public void Create() { var responseJson = GetJsonPayload("/webhooks/subscriptionsApi/response/createSubscription.json"); var requestJson = GetJsonPayload("/webhooks/subscriptionsApi/request/createSubscription.json"); var restRequest = MockRestResponse(responseJson); var subscription = new Subscription { Enabled = true, Endpoint = "http://www.example.com/endpoint", NotificationFormat = NotificationFormat.JSON, BroadcastId = 14L, TriggerEvent = TriggerEvent.CAMPAIGN_STARTED }; var id = Client.SubscriptionsApi.Create(subscription); 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 subscription = new Subscription { TriggerEvent = TriggerEvent.CAMPAIGN_FINISHED, NotificationFormat = NotificationFormat.JSON, Endpoint = "http://your-site.com/endpoint" }; var resourceId1 = Client.SubscriptionsApi.Create(subscription); Assert.NotNull(resourceId1.Id); subscription.NotificationFormat = NotificationFormat.SOAP; var resourceId2 = Client.SubscriptionsApi.Create(subscription); var findRequest = new FindSubscriptionsRequest { Limit = 30, Format = NotificationFormat.SOAP, Fields = "items(id,notificationFormat)" }; var page = Client.SubscriptionsApi.Find(findRequest); Assert.That(page.Items, Has.Count.GreaterThan(0)); subscription = page.Items[0]; Assert.Null(subscription.Endpoint); Assert.Null(page.Items[0].TriggerEvent); Assert.NotNull(subscription.Id); Assert.AreEqual(NotificationFormat.SOAP, page.Items[0].NotificationFormat); subscription.Endpoint = subscription.Endpoint + "1"; Client.SubscriptionsApi.Update(subscription); var updated = Client.SubscriptionsApi.Get((long)subscription.Id); Assert.AreEqual(subscription.Endpoint, updated.Endpoint); Client.SubscriptionsApi.Delete((long)resourceId1.Id); Client.SubscriptionsApi.Delete((long)resourceId2.Id); Assert.Throws<ResourceNotFoundException>(() => Client.SubscriptionsApi.Get((long)resourceId1.Id)); Assert.Throws<ResourceNotFoundException>(() => Client.SubscriptionsApi.Get((long)resourceId2.Id)); }
public void Update() { var expectedJson = GetJsonPayload("/webhooks/subscriptionsApi/request/updateSubscription.json"); var restRequest = MockRestResponse(expectedJson); var subscription = new Subscription { Id = 11L, BroadcastId = 15L, TriggerEvent = TriggerEvent.CAMPAIGN_FINISHED }; Client.SubscriptionsApi.Update(subscription); 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")); }
/// <summary> /// Create a Subscription for notification in the CallFire system. Use the subscriptions 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="subscription">subscription to create</param> /// <returns>ResourceId object with id of created subscription</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(Subscription subscription) { return Client.Post<ResourceId>(SUBSCRIPTIONS_PATH, subscription); }
/// <summary> /// Update subscription /// </summary> /// <param name="subscription">subscription 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(Subscription subscription) { string path = SUBSCRIPTIONS_ITEM_PATH.ReplaceFirst(ClientConstants.PLACEHOLDER, subscription.Id.ToString()); Client.Put<object>(path, subscription); }