コード例 #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest request,
            ILogger logger,
            ExecutionContext context)
        {
            logger.LogInformation($"{nameof(TimetableFunction)} HTTP trigger function processed a request.");

            var body = await request.ReadAsStringAsync().ConfigureAwait(false);

            if (string.IsNullOrEmpty(body))
            {
                return(new BadRequestResult());
            }

            var configuration = GetConfiguration(context);

            if (configuration == null)
            {
                logger.LogError($"{nameof(TimetableFunction)} Could not read configuration.");
                return(new BadRequestResult());
            }

            var client = new WebhookClient(configuration, logger);
            await client.Update(body).ConfigureAwait(false);

            return(new OkResult());
        }
コード例 #2
0
        public async Task DeleteAsync_WebhookIdZero_Throw()
        {
            var apiConnection = Substitute.For <IApiConnection>();
            var client        = new WebhookClient(apiConnection);

            await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(async() => await client.DeleteAsync(0));

            await apiConnection.DidNotReceive().ExecuteDeleteAsync(Arg.Any <string>());
        }
コード例 #3
0
        public async Task DeleteAsync()
        {
            var apiConnection = Substitute.For <IApiConnection>();
            var client        = new WebhookClient(apiConnection);

            await client.DeleteAsync(1);

            await apiConnection.Received().ExecuteDeleteAsync("webhooks/1");
        }
コード例 #4
0
        public async Task CreateAsync_WebhookNull_Throw()
        {
            var apiConnection = Substitute.For <IApiConnection>();
            var client        = new WebhookClient(apiConnection);

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await client.CreateAsync(null));

            await apiConnection.DidNotReceive().ExecutePostAsync <object, WebhookInfo>(Arg.Any <string>(), Arg.Any <object>());
        }
コード例 #5
0
        public async Task CreateAsync()
        {
            var apiConnection = Substitute.For <IApiConnection>();
            var client        = new WebhookClient(apiConnection);

            await client.CreateAsync(new CreateWebhook());

            await apiConnection.Received().ExecutePostAsync <object, WebhookInfo>("webhooks", Arg.Any <object>());
        }
コード例 #6
0
        public async Task GetByIdAsync()
        {
            var apiConnection = Substitute.For <IApiConnection>();
            var client        = new WebhookClient(apiConnection);

            await client.GetByIdAsync(1);

            await apiConnection.Received().ExecuteGetAsync <WebhookInfo>("webhooks/1");
        }
コード例 #7
0
 public SharedFunctions(LookupClient lookupClient, IAcmeProtocolClientFactory acmeProtocolClientFactory,
                        IDnsProvider dnsProvider, CertificateClient certificateClient,
                        WebhookClient webhookClient, IOptions <AcmebotOptions> options)
 {
     _acmeProtocolClientFactory = acmeProtocolClientFactory;
     _dnsProvider       = dnsProvider;
     _lookupClient      = lookupClient;
     _certificateClient = certificateClient;
     _webhookClient     = webhookClient;
     _options           = options.Value;
 }
コード例 #8
0
 public SharedFunctions(LookupClient lookupClient, IAcmeProtocolClientFactory acmeProtocolClientFactory,
                        IDnsProvider dnsProvider, KeyVaultClient keyVaultClient,
                        WebhookClient webhookClient, IOptions <AcmebotOptions> options)
 {
     _acmeProtocolClientFactory = acmeProtocolClientFactory;
     _dnsProvider    = dnsProvider;
     _lookupClient   = lookupClient;
     _keyVaultClient = keyVaultClient;
     _webhookClient  = webhookClient;
     _options        = options.Value;
 }
コード例 #9
0
 public SharedFunctions(IHttpClientFactory httpClientFactory, LookupClient lookupClient,
                        IAcmeProtocolClientFactory acmeProtocolClientFactory, IKuduClientFactory kuduClientFactory,
                        WebSiteManagementClient webSiteManagementClient, DnsManagementClient dnsManagementClient,
                        WebhookClient webhookClient, IOptions <AcmebotOptions> options)
 {
     _httpClientFactory         = httpClientFactory;
     _lookupClient              = lookupClient;
     _acmeProtocolClientFactory = acmeProtocolClientFactory;
     _kuduClientFactory         = kuduClientFactory;
     _webSiteManagementClient   = webSiteManagementClient;
     _dnsManagementClient       = dnsManagementClient;
     _webhookClient             = webhookClient;
     _options = options.Value;
 }
コード例 #10
0
        public void SetUp()
        {
            fixture = SparkTestFixture.Instance;
            Assert.IsNotNull(fixture);

            //spark = fixture.spark;
            spark = fixture.CreateSpark();
            Assert.IsNotNull(spark);

            webhooks = spark.Webhooks;
            Assert.IsNotNull(webhooks);

            myRoom    = fixture.CreateRoom("test room");
            myWebHook = CreateWebHook();
            Assert.IsNotNull(myWebHook);
            Assert.IsNotNull(myWebHook.Id);
        }
コード例 #11
0
        public void SetUp()
        {
            fixture = WebexTestFixture.Instance;
            Assert.IsNotNull(fixture);

            //webex = fixture.webex;
            webex = fixture.CreateWebex();
            Assert.IsNotNull(webex);

            webhooks = webex.Webhooks;
            Assert.IsNotNull(webhooks);

            mySpace   = fixture.CreateSpace("test space");
            myWebHook = CreateWebHook();
            Assert.IsNotNull(myWebHook);
            Assert.IsNotNull(myWebHook.Id);
        }
コード例 #12
0
 public SharedFunctions(IHttpClientFactory httpClientFactory, IAzureEnvironment environment, LookupClient lookupClient,
                        IAcmeProtocolClientFactory acmeProtocolClientFactory, IKuduClientFactory kuduClientFactory,
                        WebSiteManagementClient webSiteManagementClient, DnsManagementClient dnsManagementClient,
                        ResourceManagementClient resourceManagementClient, WebhookClient webhookClient, IOptions <AcmebotOptions> options,
                        ILogger <SharedFunctions> logger)
 {
     _httpClientFactory         = httpClientFactory;
     _environment               = environment;
     _lookupClient              = lookupClient;
     _acmeProtocolClientFactory = acmeProtocolClientFactory;
     _kuduClientFactory         = kuduClientFactory;
     _webSiteManagementClient   = webSiteManagementClient;
     _dnsManagementClient       = dnsManagementClient;
     _resourceManagementClient  = resourceManagementClient;
     _webhookClient             = webhookClient;
     _options = options.Value;
     _logger  = logger;
 }
コード例 #13
0
        public async Task SendEvent(IHiarcEvent theEvent)
        {
            try
            {
                var serializedEvent = JsonSerializer.Serialize(theEvent);
                var httpContent     = new StringContent(serializedEvent);
                httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                if (!string.IsNullOrWhiteSpace(_webhookSettings.Secret))
                {
                    // TODO: https://stripe.com/docs/webhooks/signatures
                    var unixNow = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
                    var payload = $"{unixNow}.{serializedEvent}";

                    var encoding  = new UTF8Encoding();
                    var keyBytes  = encoding.GetBytes(_webhookSettings.Secret);
                    var textBytes = encoding.GetBytes(payload);

                    using HMACSHA256 hash = new HMACSHA256(keyBytes);
                    var hashBytes  = hash.ComputeHash(textBytes);
                    var hashString = BitConverter.ToString(hashBytes).Replace("-", "").ToLower();
                    var signature  = $"t={unixNow},v1={hashString}";

                    httpContent.Headers.Add(HIARC_SIGNATURE, signature);
                }

                var response = await WebhookClient.PostAsync(_webhookSettings.URL, httpContent);

                if (response.IsSuccessStatusCode)
                {
                    _logger.LogDebug($"Successfully sent event '{theEvent.Event}' to '{this.Name}'. Payload: {serializedEvent}");
                }
                else
                {
                    var body = await response.Content.ReadAsStringAsync();

                    _logger.LogError($"Failed to send event to '{this.Name}'. Response Body: {body}");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to send event to '{this.Name}'. Exception: {ex.Message}");
            }
        }
コード例 #14
0
ファイル: DevToClient.cs プロジェクト: podobaas/DevToAPI
        /// <summary>
        /// API client
        /// </summary>
        /// <remarks>
        /// See the <a href="https://docs.dev.to/api/#section/Authentication/api_key">Authentication</a> for more information
        /// </remarks>
        /// <param name="apiUrl">API connection url</param>
        /// <param name="token">API key</param>
        public DevToClient(string apiUrl, string token)
        {
            var restClient = new RestClient(apiUrl);

            restClient.AddDefaultHeader("api-key", token);
            restClient.AddDefaultHeader("User-Agent", "DevToAPI-client-dotnet");
            var apiConnection = new ApiConnection(restClient);

            AdminConfigurations = new AdminConfigurationClient(apiConnection);
            Articles            = new ArticleClient(apiConnection);
            Comments            = new CommentClient(apiConnection);
            Followers           = new FollowerClient(apiConnection);
            Follows             = new FollowClient(apiConnection);
            Listings            = new ListingClient(apiConnection);
            Organizations       = new OrganizationClient(apiConnection);
            PodcastEpisodes     = new PodcastEpisodeClient(apiConnection);
            ReadingLists        = new ReadingListClient(apiConnection);
            Tags          = new TagClient(apiConnection);
            Users         = new UserClient(apiConnection);
            Videos        = new VideoClient(apiConnection);
            Webhooks      = new WebhookClient(apiConnection);
            ProfileImages = new ProfileImageClient(apiConnection);
        }
コード例 #15
0
        static void Main(string[] args)
        {
            WebhookClient _client = new WebhookClient("Inset WebHook url");

            var jObject = JObject.Parse(File.ReadAllText("Json.json"));

            try
            {
                var em = new EmbedBuilder()
                {
                    Title       = "Did you know...",
                    ImageUrl    = "https://img.buzzfeed.com/buzzfeed-static/static/2014-03/enhanced/webdr02/26/18/original-5460-1395871268-26.jpg?downsize=715:*&output-format=auto&output-quality=auto",
                    Description = "There are cats who have survived falls from over 32 stories (320 meters) onto concrete.\nQuite interesting indeed don't you agree?",
                    Color       = new Color(242, 186, 225),
                };

                _client.PostMessageAsync("Hello World.");
            }
            catch (Exception exc)
            {
                Console.WriteLine($"{exc.Message}\n\n{exc.StackTrace}");
            }
            Console.ReadLine();
        }