public void Find() { var expectedJson = GetJsonPayload("/webhooks/webhooksApi/response/findWebhooks.json"); var restRequest = MockRestResponse(expectedJson); var request = new FindWebhooksRequest { Limit = 5, Offset = 0, Enabled = false, Resource = ResourceType.TEXT_BROADCAST }; var webhooks = Client.WebhooksApi.Find(request); Assert.That(Serializer.Serialize(webhooks), Is.EqualTo(expectedJson)); Assert.AreEqual(Method.GET, restRequest.Value.Method); var requestBodyParam = restRequest.Value.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody); Assert.IsNull(requestBodyParam); Assert.That(restRequest.Value.Parameters, Has.Some.Matches <Parameter>(p => p.Name.Equals("limit") && p.Value.Equals("5"))); Assert.That(restRequest.Value.Parameters, Has.Some.Matches <Parameter>(p => p.Name.Equals("offset") && p.Value.Equals("0"))); Assert.That(restRequest.Value.Parameters, Has.Some.Matches <Parameter>(p => p.Name.Equals("resource") && p.Value.Equals(ResourceType.TEXT_BROADCAST.ToString()))); Assert.That(restRequest.Value.Parameters, Has.Some.Matches <Parameter>(p => p.Name.Equals("enabled") && p.Value.Equals("False"))); }
public void CrudOperations() { var api = Client.WebhooksApi; var webhook = new Webhook { Name = "test_name1", Callback = "https://test_callback", Resource = ResourceType.TEXT_BROADCAST, Events = new HashSet <ResourceEvent> { ResourceEvent.STARTED }, SingleUse = true }; var resourceId1 = api.Create(webhook); Assert.NotNull(resourceId1.Id); webhook.Name = "test_name2"; var resourceId2 = api.Create(webhook); webhook.Resource = ResourceType.CONTACT_LIST; webhook.Events = new HashSet <ResourceEvent> { ResourceEvent.VALIDATION_FINISHED }; var resourceId3 = api.Create(webhook); var findRequest = new FindWebhooksRequest { Limit = 30L, Name = "test_name1", Callback = "https://test_callback", Fields = "items(id,callback,name,resource,events,singleUse)" }; var page = api.Find(findRequest); Assert.That(page.Items.Count > 0); Assert.AreEqual("test_name1", page.Items[0].Name); Assert.AreEqual("https://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); Assert.True(page.Items[0].SingleUse.GetValueOrDefault()); webhook = page.Items[0]; webhook.Name = "test_name2"; webhook.SingleUse = false; api.Update(webhook); Webhook updated = api.Get((long)webhook.Id); Assert.AreEqual(webhook.Resource, updated.Resource); Assert.False(page.Items[0].SingleUse.GetValueOrDefault()); api.Delete((long)resourceId1.Id); api.Delete((long)resourceId2.Id); api.Delete((long)resourceId3.Id); Assert.Throws <ResourceNotFoundException>(() => api.Get((long)resourceId1.Id)); Assert.Throws <ResourceNotFoundException>(() => api.Get((long)resourceId2.Id)); }
public static void Main(string[] args) { var client = new CallfireClient("api_login", "api_password"); var request = new FindWebhooksRequest { Name = "my webhook", Resource = ResourceType.TEXT_BROADCAST, Event = ResourceEvent.STARTED, Callback = "https://myservice/callback", Enabled = true, Offset = 0, Limit = 10, Fields = "items(id,name,callback)" }; Page <Webhook> webhooks = client.WebhooksApi.Find(request); }
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)); }
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)); }
public void Find() { var expectedJson = GetJsonPayload("/webhooks/webhooksApi/response/findWebhooks.json"); var restRequest = MockRestResponse(expectedJson); var request = new FindWebhooksRequest { Limit = 5, Offset = 0, Enabled = false, Resource = "resource" }; var webhooks = Client.WebhooksApi.Find(request); Assert.That(Serializer.Serialize(webhooks), Is.EqualTo(expectedJson)); Assert.AreEqual(Method.GET, restRequest.Value.Method); var requestBodyParam = restRequest.Value.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody); Assert.IsNull(requestBodyParam); Assert.That(restRequest.Value.Parameters, Has.Some.Matches<Parameter>(p => p.Name.Equals("limit") && p.Value.Equals("5"))); Assert.That(restRequest.Value.Parameters, Has.Some.Matches<Parameter>(p => p.Name.Equals("offset") && p.Value.Equals("0"))); Assert.That(restRequest.Value.Parameters, Has.Some.Matches<Parameter>(p => p.Name.Equals("resource") && p.Value.Equals("resource"))); Assert.That(restRequest.Value.Parameters, Has.Some.Matches<Parameter>(p => p.Name.Equals("enabled") && p.Value.Equals("False"))); }
/// <summary> /// Find all webhooks for the user. /// Search for webhooks on name, resource, event, callback URL, or whether they are enabled. /// </summary> /// <param name="request">request object with different fields to filter</param> /// <returns>paged list with webhooks</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 Page<Webhook> Find(FindWebhooksRequest request) { return Client.Get<Page<Webhook>>(WEBHOOKS_PATH, request); }
/// <summary> /// Find all webhooks for the user. /// Search for webhooks on name, resource, event, callback URL, or whether they are enabled. /// </summary> /// <param name="request">request object with different fields to filter</param> /// <returns>paged list with webhooks</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 Page <Webhook> Find(FindWebhooksRequest request) { return(Client.Get <Page <Webhook> >(WEBHOOKS_PATH, request)); }