Beispiel #1
0
 public void Initialize()
 {
     eventSink = new Mock <IEventSink>();
     webhooks  = new WebhooksClient
     {
         EventSink = eventSink.Object
     };
 }
            public void DeletesCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new WebhooksClient(connection);

                client.Delete(123);

                connection.Received().Delete(Arg.Is <Uri>(u => u.ToString() == "webhooks/123"));
            }
 /// <summary>Snippet for GetWebhook</summary>
 public void GetWebhookResourceNames()
 {
     // Snippet: GetWebhook(WebhookName, CallSettings)
     // Create client
     WebhooksClient webhooksClient = WebhooksClient.Create();
     // Initialize request argument(s)
     WebhookName name = WebhookName.FromProjectLocationAgentWebhook("[PROJECT]", "[LOCATION]", "[AGENT]", "[WEBHOOK]");
     // Make the request
     Webhook response = webhooksClient.GetWebhook(name);
     // End snippet
 }
 /// <summary>Snippet for GetWebhook</summary>
 public void GetWebhook()
 {
     // Snippet: GetWebhook(string, CallSettings)
     // Create client
     WebhooksClient webhooksClient = WebhooksClient.Create();
     // Initialize request argument(s)
     string name = "projects/[PROJECT]/locations/[LOCATION]/agents/[AGENT]/webhooks/[WEBHOOK]";
     // Make the request
     Webhook response = webhooksClient.GetWebhook(name);
     // End snippet
 }
 /// <summary>Snippet for CreateWebhook</summary>
 public void CreateWebhook()
 {
     // Snippet: CreateWebhook(string, Webhook, CallSettings)
     // Create client
     WebhooksClient webhooksClient = WebhooksClient.Create();
     // Initialize request argument(s)
     string  parent  = "projects/[PROJECT]/locations/[LOCATION]/agents/[AGENT]";
     Webhook webhook = new Webhook();
     // Make the request
     Webhook response = webhooksClient.CreateWebhook(parent, webhook);
     // End snippet
 }
 /// <summary>Snippet for CreateWebhook</summary>
 public void CreateWebhookResourceNames()
 {
     // Snippet: CreateWebhook(AgentName, Webhook, CallSettings)
     // Create client
     WebhooksClient webhooksClient = WebhooksClient.Create();
     // Initialize request argument(s)
     AgentName parent  = AgentName.FromProjectLocationAgent("[PROJECT]", "[LOCATION]", "[AGENT]");
     Webhook   webhook = new Webhook();
     // Make the request
     Webhook response = webhooksClient.CreateWebhook(parent, webhook);
     // End snippet
 }
 /// <summary>Snippet for UpdateWebhook</summary>
 public void UpdateWebhook()
 {
     // Snippet: UpdateWebhook(Webhook, FieldMask, CallSettings)
     // Create client
     WebhooksClient webhooksClient = WebhooksClient.Create();
     // Initialize request argument(s)
     Webhook   webhook    = new Webhook();
     FieldMask updateMask = new FieldMask();
     // Make the request
     Webhook response = webhooksClient.UpdateWebhook(webhook, updateMask);
     // End snippet
 }
Beispiel #8
0
            public async Task DeserializeCreateInformations()
            {
                var stream = Helper.LoadFixture("webhook_organization_create.json");

                using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
                {
                    var fixture = await reader.ReadToEndAsync();

                    var webhookClient = new WebhooksClient();
                    var result        = webhookClient.ParseWebhookOrganizationResponse(fixture);
                }
            }
            public async Task RequestsCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new WebhooksClient(connection);

                await client.GetAll();

                Received.InOrder(async() =>
                {
                    await connection.GetAll <Webhook>(Arg.Is <Uri>(u => u.ToString() == "webhooks"));
                });
            }
 /// <summary>Snippet for GetWebhook</summary>
 public void GetWebhookRequestObject()
 {
     // Snippet: GetWebhook(GetWebhookRequest, CallSettings)
     // Create client
     WebhooksClient webhooksClient = WebhooksClient.Create();
     // Initialize request argument(s)
     GetWebhookRequest request = new GetWebhookRequest
     {
         WebhookName = WebhookName.FromProjectLocationAgentWebhook("[PROJECT]", "[LOCATION]", "[AGENT]", "[WEBHOOK]"),
     };
     // Make the request
     Webhook response = webhooksClient.GetWebhook(request);
     // End snippet
 }
        /// <summary>Snippet for DeleteWebhookAsync</summary>
        public async Task DeleteWebhookAsync()
        {
            // Snippet: DeleteWebhookAsync(string, CallSettings)
            // Additional: DeleteWebhookAsync(string, CancellationToken)
            // Create client
            WebhooksClient webhooksClient = await WebhooksClient.CreateAsync();

            // Initialize request argument(s)
            string name = "projects/[PROJECT]/locations/[LOCATION]/agents/[AGENT]/webhooks/[WEBHOOK]";
            // Make the request
            await webhooksClient.DeleteWebhookAsync(name);

            // End snippet
        }
            public void PostsToTheCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new WebhooksClient(connection);

                var newWebhook = new NewWebhook("https://test.com", "*", "*");

                client.Create(newWebhook);

                connection.Received().Post <Webhook>(Arg.Is <Uri>(u => u.ToString() == "webhooks"),
                                                     Arg.Is <NewWebhook>(df => df.EventAction == "*" &&
                                                                         df.EventObject == "*" &&
                                                                         df.SubscriptionUrl == "https://test.com"));
            }
        /// <summary>Snippet for DeleteWebhookAsync</summary>
        public async Task DeleteWebhookResourceNamesAsync()
        {
            // Snippet: DeleteWebhookAsync(WebhookName, CallSettings)
            // Additional: DeleteWebhookAsync(WebhookName, CancellationToken)
            // Create client
            WebhooksClient webhooksClient = await WebhooksClient.CreateAsync();

            // Initialize request argument(s)
            WebhookName name = WebhookName.FromProjectLocationAgentWebhook("[PROJECT]", "[LOCATION]", "[AGENT]", "[WEBHOOK]");
            // Make the request
            await webhooksClient.DeleteWebhookAsync(name);

            // End snippet
        }
 /// <summary>Snippet for CreateWebhook</summary>
 public void CreateWebhookRequestObject()
 {
     // Snippet: CreateWebhook(CreateWebhookRequest, CallSettings)
     // Create client
     WebhooksClient webhooksClient = WebhooksClient.Create();
     // Initialize request argument(s)
     CreateWebhookRequest request = new CreateWebhookRequest
     {
         ParentAsAgentName = AgentName.FromProjectLocationAgent("[PROJECT]", "[LOCATION]", "[AGENT]"),
         Webhook           = new Webhook(),
     };
     // Make the request
     Webhook response = webhooksClient.CreateWebhook(request);
     // End snippet
 }
        /// <summary>Snippet for CreateWebhookAsync</summary>
        public async Task CreateWebhookAsync()
        {
            // Snippet: CreateWebhookAsync(string, Webhook, CallSettings)
            // Additional: CreateWebhookAsync(string, Webhook, CancellationToken)
            // Create client
            WebhooksClient webhooksClient = await WebhooksClient.CreateAsync();

            // Initialize request argument(s)
            string  parent  = "projects/[PROJECT]/locations/[LOCATION]/agents/[AGENT]";
            Webhook webhook = new Webhook();
            // Make the request
            Webhook response = await webhooksClient.CreateWebhookAsync(parent, webhook);

            // End snippet
        }
Beispiel #16
0
            public async Task DeserializeUpdateInformations(string fileName)
            {
                var stream = Helper.LoadFixture(fileName);

                using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
                {
                    var fixture = await reader.ReadToEndAsync();

                    var webhookClient = new WebhooksClient();
                    var result        = webhookClient.ParseWebhookPersonResponse(fixture);

                    Assert.NotEmpty(result.Meta.Action);
                    Assert.NotEqual(0, result.Current.Id);
                }
            }
        /// <summary>Snippet for UpdateWebhookAsync</summary>
        public async Task UpdateWebhookAsync()
        {
            // Snippet: UpdateWebhookAsync(Webhook, FieldMask, CallSettings)
            // Additional: UpdateWebhookAsync(Webhook, FieldMask, CancellationToken)
            // Create client
            WebhooksClient webhooksClient = await WebhooksClient.CreateAsync();

            // Initialize request argument(s)
            Webhook   webhook    = new Webhook();
            FieldMask updateMask = new FieldMask();
            // Make the request
            Webhook response = await webhooksClient.UpdateWebhookAsync(webhook, updateMask);

            // End snippet
        }
 /// <summary>Snippet for UpdateWebhook</summary>
 public void UpdateWebhookRequestObject()
 {
     // Snippet: UpdateWebhook(UpdateWebhookRequest, CallSettings)
     // Create client
     WebhooksClient webhooksClient = WebhooksClient.Create();
     // Initialize request argument(s)
     UpdateWebhookRequest request = new UpdateWebhookRequest
     {
         Webhook    = new Webhook(),
         UpdateMask = new FieldMask(),
     };
     // Make the request
     Webhook response = webhooksClient.UpdateWebhook(request);
     // End snippet
 }
        /// <summary>Snippet for CreateWebhookAsync</summary>
        public async Task CreateWebhookResourceNamesAsync()
        {
            // Snippet: CreateWebhookAsync(AgentName, Webhook, CallSettings)
            // Additional: CreateWebhookAsync(AgentName, Webhook, CancellationToken)
            // Create client
            WebhooksClient webhooksClient = await WebhooksClient.CreateAsync();

            // Initialize request argument(s)
            AgentName parent  = AgentName.FromProjectLocationAgent("[PROJECT]", "[LOCATION]", "[AGENT]");
            Webhook   webhook = new Webhook();
            // Make the request
            Webhook response = await webhooksClient.CreateWebhookAsync(parent, webhook);

            // End snippet
        }
        /// <summary>Snippet for ListWebhooks</summary>
        public async Task ListWebhooksRequestObjectAsync()
        {
            // Snippet: ListWebhooksAsync(ListWebhooksRequest, CallSettings)
            // Create client
            WebhooksClient webhooksClient = await WebhooksClient.CreateAsync();

            // Initialize request argument(s)
            ListWebhooksRequest request = new ListWebhooksRequest
            {
                ParentAsAgentName = AgentName.FromProjectLocationAgent("[PROJECT]", "[LOCATION]", "[AGENT]"),
            };
            // Make the request
            PagedAsyncEnumerable <ListWebhooksResponse, Webhook> response = webhooksClient.ListWebhooksAsync(request);

            // Iterate over all response items, lazily performing RPCs as required
            await response.ForEachAsync((Webhook item) =>
            {
                // Do something with each item
                Console.WriteLine(item);
            });

            // Or iterate over pages (of server-defined size), performing one RPC per page
            await response.AsRawResponses().ForEachAsync((ListWebhooksResponse page) =>
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (Webhook item in page)
                {
                    // Do something with each item
                    Console.WriteLine(item);
                }
            });

            // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
            int            pageSize   = 10;
            Page <Webhook> singlePage = await response.ReadPageAsync(pageSize);

            // Do something with the page of items
            Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
            foreach (Webhook item in singlePage)
            {
                // Do something with each item
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
            // End snippet
        }
        /// <summary>Snippet for DeleteWebhook</summary>
        public void DeleteWebhookRequestObject()
        {
            // Snippet: DeleteWebhook(DeleteWebhookRequest, CallSettings)
            // Create client
            WebhooksClient webhooksClient = WebhooksClient.Create();
            // Initialize request argument(s)
            DeleteWebhookRequest request = new DeleteWebhookRequest
            {
                WebhookName = WebhookName.FromProjectLocationAgentWebhook("[PROJECT]", "[LOCATION]", "[AGENT]", "[WEBHOOK]"),
                Force       = false,
            };

            // Make the request
            webhooksClient.DeleteWebhook(request);
            // End snippet
        }
Beispiel #22
0
        public ViagogoClient(
            ProductHeaderValue product,
            IGogoKitConfiguration configuration,
            IOAuth2TokenStore tokenStore,
            IJsonSerializer serializer,
            IHttpConnection oauthConnection,
            IHttpConnection apiConnection)
        {
            Requires.ArgumentNotNull(product, nameof(product));
            Requires.ArgumentNotNull(configuration, nameof(configuration));
            Requires.ArgumentNotNull(tokenStore, nameof(tokenStore));
            Requires.ArgumentNotNull(serializer, nameof(serializer));
            Requires.ArgumentNotNull(oauthConnection, nameof(oauthConnection));
            Requires.ArgumentNotNull(apiConnection, nameof(apiConnection));

            var halKitConfiguration = new HalKitConfiguration(configuration.ViagogoApiRootEndpoint)
            {
                CaptureSynchronizationContext = configuration.CaptureSynchronizationContext
            };

            Configuration = configuration;
            TokenStore    = tokenStore;
            Hypermedia    = new HalClient(halKitConfiguration, apiConnection);
            var linkFactory = new LinkFactory(configuration);

            OAuth2         = new OAuth2Client(oauthConnection, configuration);
            User           = new UserClient(Hypermedia);
            Search         = new SearchClient(Hypermedia);
            Addresses      = new AddressesClient(User, Hypermedia, linkFactory);
            Purchases      = new PurchasesClient(User, Hypermedia, linkFactory);
            Sales          = new SalesClient(Hypermedia, linkFactory);
            Shipments      = new ShipmentsClient(Hypermedia, linkFactory);
            PaymentMethods = new PaymentMethodsClient(User, Hypermedia, linkFactory);
            Countries      = new CountriesClient(Hypermedia, linkFactory);
            Currencies     = new CurrenciesClient(Hypermedia, linkFactory);
            Categories     = new CategoriesClient(Hypermedia, linkFactory);
            Events         = new EventsClient(Hypermedia);
            Listings       = new ListingsClient(Hypermedia);
            Venues         = new VenuesClient(Hypermedia);
            SellerListings = new SellerListingsClient(Hypermedia, linkFactory);
            Webhooks       = new WebhooksClient(Hypermedia, linkFactory);

            BatchClient = new BatchClient(apiConnection,
                                          new ApiResponseFactory(serializer, halKitConfiguration),
                                          serializer,
                                          new LinkResolver());
        }
        /// <summary>Snippet for GetWebhookAsync</summary>
        public async Task GetWebhookRequestObjectAsync()
        {
            // Snippet: GetWebhookAsync(GetWebhookRequest, CallSettings)
            // Additional: GetWebhookAsync(GetWebhookRequest, CancellationToken)
            // Create client
            WebhooksClient webhooksClient = await WebhooksClient.CreateAsync();

            // Initialize request argument(s)
            GetWebhookRequest request = new GetWebhookRequest
            {
                WebhookName = WebhookName.FromProjectLocationAgentWebhook("[PROJECT]", "[LOCATION]", "[AGENT]", "[WEBHOOK]"),
            };
            // Make the request
            Webhook response = await webhooksClient.GetWebhookAsync(request);

            // End snippet
        }
        /// <summary>Snippet for CreateWebhookAsync</summary>
        public async Task CreateWebhookRequestObjectAsync()
        {
            // Snippet: CreateWebhookAsync(CreateWebhookRequest, CallSettings)
            // Additional: CreateWebhookAsync(CreateWebhookRequest, CancellationToken)
            // Create client
            WebhooksClient webhooksClient = await WebhooksClient.CreateAsync();

            // Initialize request argument(s)
            CreateWebhookRequest request = new CreateWebhookRequest
            {
                ParentAsAgentName = AgentName.FromProjectLocationAgent("[PROJECT]", "[LOCATION]", "[AGENT]"),
                Webhook           = new Webhook(),
            };
            // Make the request
            Webhook response = await webhooksClient.CreateWebhookAsync(request);

            // End snippet
        }
        /// <summary>Snippet for UpdateWebhookAsync</summary>
        public async Task UpdateWebhookRequestObjectAsync()
        {
            // Snippet: UpdateWebhookAsync(UpdateWebhookRequest, CallSettings)
            // Additional: UpdateWebhookAsync(UpdateWebhookRequest, CancellationToken)
            // Create client
            WebhooksClient webhooksClient = await WebhooksClient.CreateAsync();

            // Initialize request argument(s)
            UpdateWebhookRequest request = new UpdateWebhookRequest
            {
                Webhook    = new Webhook(),
                UpdateMask = new FieldMask(),
            };
            // Make the request
            Webhook response = await webhooksClient.UpdateWebhookAsync(request);

            // End snippet
        }
        /// <summary>Snippet for ListWebhooks</summary>
        public void ListWebhooksResourceNames()
        {
            // Snippet: ListWebhooks(AgentName, string, int?, CallSettings)
            // Create client
            WebhooksClient webhooksClient = WebhooksClient.Create();
            // Initialize request argument(s)
            AgentName parent = AgentName.FromProjectLocationAgent("[PROJECT]", "[LOCATION]", "[AGENT]");
            // Make the request
            PagedEnumerable <ListWebhooksResponse, Webhook> response = webhooksClient.ListWebhooks(parent);

            // Iterate over all response items, lazily performing RPCs as required
            foreach (Webhook item in response)
            {
                // Do something with each item
                Console.WriteLine(item);
            }

            // Or iterate over pages (of server-defined size), performing one RPC per page
            foreach (ListWebhooksResponse page in response.AsRawResponses())
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (Webhook item in page)
                {
                    // Do something with each item
                    Console.WriteLine(item);
                }
            }

            // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
            int            pageSize   = 10;
            Page <Webhook> singlePage = response.ReadPage(pageSize);

            // Do something with the page of items
            Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
            foreach (Webhook item in singlePage)
            {
                // Do something with each item
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
            // End snippet
        }
            public async Task EnsuresNonNullArguments()
            {
                var client = new WebhooksClient(Substitute.For <IApiConnection>());

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.Create(null));
            }