public void Create() { var responseJson = GetJsonPayload("/webhooks/webhooksApi/response/createWebhook.json"); var requestJson = GetJsonPayload("/webhooks/webhooksApi/request/createWebhook.json"); var restRequest = MockRestResponse(responseJson); var webhook = new Webhook { Name = "API hook", Resource = ResourceType.TEXT_BROADCAST, Events = new HashSet<ResourceEvent> { ResourceEvent.STARTED, ResourceEvent.STOPPED }, Callback = "http://yoursite.com/webhook" }; var id = Client.WebhooksApi.Create(webhook); Assert.That(Serializer.Serialize(id), Is.EqualTo(responseJson)); Assert.AreEqual(Method.POST, restRequest.Value.Method); var requestBodyParam = restRequest.Value.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody); Assert.That(requestBodyParam.Value, Is.EqualTo(requestJson)); }
public void CrudOperations() { var api = Client.WebhooksApi; var webhook = new Webhook { Name = "test_name1", Callback = "test_callback", Resource = ResourceType.TEXT_BROADCAST, Events = new HashSet<ResourceEvent> { ResourceEvent.STARTED } }; var resourceId1 = api.Create(webhook); Assert.NotNull(resourceId1.Id); webhook.Name = "test_name2"; var resourceId2 = api.Create(webhook); var findRequest = new FindWebhooksRequest { Limit = 30L, Name = "test_name1", Fields = "items(id,callback,name,resource,events)" }; var page = api.Find(findRequest); Assert.That(page.Items.Count > 1); Assert.AreEqual("test_name1", page.Items[0].Name); Assert.AreEqual("test_callback", page.Items[0].Callback); Assert.AreEqual(ResourceType.TEXT_BROADCAST, page.Items[0].Resource); Assert.AreEqual(1, page.Items[0].Events.Count); Assert.NotNull(page.Items[0].Id); webhook = page.Items[0]; webhook.Name = "test_name2"; api.Update(webhook); Webhook updated = api.Get((long)webhook.Id); Assert.AreEqual(webhook.Resource, updated.Resource); api.Delete((long)resourceId1.Id); api.Delete((long)resourceId2.Id); Assert.Throws<ResourceNotFoundException>(() => api.Get((long)resourceId1.Id)); Assert.Throws<ResourceNotFoundException>(() => api.Get((long)resourceId2.Id)); }
/// <summary> /// Create a Webhook for notification in the CallFire system. Use the webhooks API to receive /// notifications of important CallFire events. Select the resource to listen to, and then choose /// the events for that resource to receive notifications on. When an event triggers, /// a POST will be made to the callback URL with a payload of notification information. /// </summary> /// <param name="webhook">webhook to create</param> /// <returns>ResourceId object with id of created webhook</returns> /// <exception cref="BadRequestException"> in case HTTP response code is 400 - Bad request, the request was formatted improperly.</exception> /// <exception cref="UnauthorizedException"> in case HTTP response code is 401 - Unauthorized, API Key missing or invalid.</exception> /// <exception cref="AccessForbiddenException"> in case HTTP response code is 403 - Forbidden, insufficient permissions.</exception> /// <exception cref="ResourceNotFoundException"> in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist.</exception> /// <exception cref="InternalServerErrorException"> in case HTTP response code is 500 - Internal Server Error.</exception> /// <exception cref="CallfireApiException"> in case HTTP response code is something different from codes listed above.</exception> /// <exception cref="CallfireClientException"> in case error has occurred in client.</exception> public ResourceId Create(Webhook webhook) { return Client.Post<ResourceId>(WEBHOOKS_PATH, webhook); }
/// <summary> /// Update webhook /// </summary> /// <param name="webhook">webhook to update</param> /// <exception cref="BadRequestException"> in case HTTP response code is 400 - Bad request, the request was formatted improperly.</exception> /// <exception cref="UnauthorizedException"> in case HTTP response code is 401 - Unauthorized, API Key missing or invalid.</exception> /// <exception cref="AccessForbiddenException"> in case HTTP response code is 403 - Forbidden, insufficient permissions.</exception> /// <exception cref="ResourceNotFoundException"> in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist.</exception> /// <exception cref="InternalServerErrorException"> in case HTTP response code is 500 - Internal Server Error.</exception> /// <exception cref="CallfireApiException"> in case HTTP response code is something different from codes listed above.</exception> /// <exception cref="CallfireClientException"> in case error has occurred in client.</exception> public void Update(Webhook webhook) { string path = WEBHOOKS_ITEM_PATH.ReplaceFirst(ClientConstants.PLACEHOLDER, webhook.Id.ToString()); Client.Put<object>(path, webhook); }
public void ValidateWebhook() { var webhook = new Webhook { Resource = ResourceType.CALL_BROADCAST, Events = new HashSet<ResourceEvent> { ResourceEvent.FINISHED, ResourceEvent.STARTED, ResourceEvent.UNKNOWN } }; var ex = Assert.Throws<ModelValidationException>(() => Client.WebhooksApi.Update(webhook)); Assert.That(ex.Message, Is.StringContaining("Event [unknown] is unsupported for CallBroadcast resource")); }
public void Update() { var expectedJson = GetJsonPayload("/webhooks/webhooksApi/request/updateWebhook.json"); var restRequest = MockRestResponse(expectedJson); var webhook = new Webhook { Id = 11, Name = "API hook", Resource = ResourceType.TEXT_BROADCAST, Events = new HashSet<ResourceEvent> { ResourceEvent.STOPPED }, Callback = "http://yoursite.com/webhook" }; Client.WebhooksApi.Update(webhook); Assert.AreEqual(Method.PUT, restRequest.Value.Method); var requestBodyParam = restRequest.Value.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody); Assert.AreEqual(requestBodyParam.Value, expectedJson); Assert.That(restRequest.Value.Resource, Is.StringEnding("/11")); }