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); }
public void Create(CreateWebhook command) { Guard.Valid(command, nameof(command), () => "Cannot create webhook"); VerifyNotCreated(); RaiseEvent(SimpleMapper.Map(command, new WebhookCreated())); }
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)); }
/// <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)); }
/// <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<IResponse<System.Boolean>>.</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)); }
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)); }
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 }) ); }
/// <summary> /// Create room webhook /// </summary> /// <param name="room">The room.</param> /// <param name="hook">The hook.</param> /// <returns>Task<IResponse<System.Boolean>>.</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); }
protected async Task On(CreateWebhook command, CommandContext context) { await ValidateAsync(command, () => "Failed to create webhook"); await handler.CreateAsync <WebhookDomainObject>(context, c => c.Create(command)); }