コード例 #1
0
        public Webhook CreateWebhook(CreateWebhook createWebhook)
        {
            var validateResult = createWebhook.Validate();

            if (validateResult.Count > 0)
            {
                throw new Exception($"CreateWebhook request does not pass validation. {string.Join(" :: ", validateResult)}");
            }

            var request = BuildRequestAuthorization(POST_CREATE_WEBHOOK, Method.POST);

            request.AddJsonBody(createWebhook);

            var response = WebClient.Execute <Webhook>(request);

            if (response.ResponseStatus == ResponseStatus.Completed && response.StatusCode == System.Net.HttpStatusCode.Created)
            {
                return(response.Data);
            }

            if (!string.IsNullOrWhiteSpace(response.ErrorMessage))
            {
                throw new Exception(response.ErrorMessage);
            }

            if (!string.IsNullOrWhiteSpace(response.StatusDescription) && !string.IsNullOrWhiteSpace(response.Content))
            {
                throw new Exception($"{response.StatusDescription} || {response.Content}");
            }

            return(null);
        }
コード例 #2
0
        public void Create(CreateWebhook command)
        {
            Guard.Valid(command, nameof(command), () => "Cannot create webhook");

            VerifyNotCreated();

            RaiseEvent(SimpleMapper.Map(command, new WebhookCreated()));
        }
コード例 #3
0
ファイル: WebhookClient.cs プロジェクト: podobaas/DevToAPI
        public async Task <WebhookInfo> CreateAsync(CreateWebhook webhook)
        {
            ThrowHelper.ThrowIfNull(webhook, nameof(webhook));

            var request = new { webhook_endpoint = webhook };

            return(await ApiConnection.ExecutePostAsync <object, WebhookInfo>(Route, request).ConfigureAwait(false));
        }
コード例 #4
0
ファイル: Webhooks.cs プロジェクト: sastrakhan/EmmaSharp
        /// <summary>
        /// Create an new webhook.
        /// </summary>
        /// <param name="webhook">The webhook to be created.</param>
        /// <returns>The ID of the newly created webhook.</returns>@Html.Raw(breadcrumb.Item3)
        public int CreateWebhook(CreateWebhook webhook)
        {
            var request = new RestRequest(Method.POST);

            request.Resource = "/{accountId}/webhooks";

            request.RequestFormat  = DataFormat.Json;
            request.JsonSerializer = new EmmaJsonSerializer();
            request.AddBody(webhook);

            return(Execute <int>(request));
        }
コード例 #5
0
ファイル: RoomsClient.cs プロジェクト: tailored/hipchat.net
        /// <summary>
        /// Create room webhook
        /// </summary>
        /// <param name="room">The room.</param>
        /// <param name="url">The URL.</param>
        /// <param name="webhookEvent">The webhook event.</param>
        /// <param name="name">The name.</param>
        /// <param name="pattern">The pattern.</param>
        /// <returns>Task&lt;IResponse&lt;System.Boolean&gt;&gt;.</returns>
        public async Task <IResponse <bool> > CreateWebhookAsync(string room, Uri url, WebhookEvent webhookEvent, string name = null, string pattern = null)
        {
            var hook = new CreateWebhook
            {
                Url   = url.AbsoluteUri,
                Event = webhookEvent,
                Name  = string.Format("HipChatDotNet_{0}", name ?? "Default")
            };

            if (pattern != null && (webhookEvent == WebhookEvent.RoomMessage || webhookEvent == WebhookEvent.RoomNotification))
            {
                hook.Pattern = pattern;
            }

            return(await CreateWebhookAsync(room, hook));
        }
コード例 #6
0
        public async Task <IActionResult> PostWebhook(string app, [FromBody] CreateWebhookDto request)
        {
            var schemas = request.Schemas.Select(s => SimpleMapper.Map(s, new WebhookSchema())).ToList();

            var command = new CreateWebhook {
                Url = request.Url, Schemas = schemas
            };

            var context = await CommandBus.PublishAsync(command);

            var result   = context.Result <EntityCreatedResult <Guid> >();
            var response = new WebhookCreatedDto {
                Id = result.IdOrValue, SharedSecret = command.SharedSecret, Version = result.Version
            };

            return(CreatedAtAction(nameof(GetWebhooks), new { app }, response));
        }
コード例 #7
0
        public void Create_should_create_events()
        {
            var command = new CreateWebhook {
                Url = url
            };

            sut.Create(CreateWebhookCommand(command));

            sut.GetUncomittedEvents()
            .ShouldHaveSameEvents(
                CreateWebhookEvent(new WebhookCreated
            {
                Url          = url,
                Schemas      = command.Schemas,
                SharedSecret = command.SharedSecret,
                WebhookId    = command.WebhookId
            })
                );
        }
コード例 #8
0
ファイル: RoomsClient.cs プロジェクト: tailored/hipchat.net
        /// <summary>
        /// Create room webhook
        /// </summary>
        /// <param name="room">The room.</param>
        /// <param name="hook">The hook.</param>
        /// <returns>Task&lt;IResponse&lt;System.Boolean&gt;&gt;.</returns>
        public async Task <IResponse <bool> > CreateWebhookAsync(string room, CreateWebhook hook)
        {
            Validate.Length(room, 100, "Room Id/Name");
            Validate.NotEmpty(hook.Url, "Webhook URL");

            var json    = JsonConvert.SerializeObject(hook, Formatting.None, _jsonSettings);
            var payload = new StringContent(json, Encoding.UTF8, "application/json");

            var result = await ApiConnection.Client.PostAsync(string.Format("room/{0}/webhook", room), payload);

            var content = await result.Content.ReadAsStringAsync();

            var response = new Response <bool>(true)
            {
                Code        = result.StatusCode,
                Body        = content,
                ContentType = result.Content.Headers.ContentType.MediaType
            };

            return(response);
        }
コード例 #9
0
        protected async Task On(CreateWebhook command, CommandContext context)
        {
            await ValidateAsync(command, () => "Failed to create webhook");

            await handler.CreateAsync <WebhookDomainObject>(context, c => c.Create(command));
        }