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 Find() { var expectedJson = GetJsonPayload("/webhooks/subscriptionsApi/response/findSubscriptions.json"); var restRequest = MockRestResponse(expectedJson); var request = new FindSubscriptionsRequest { Limit = 5, Offset = 0, CampaignId = 111, Format = NotificationFormat.JSON }; var webhooks = Client.SubscriptionsApi.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("campaignId") && p.Value.Equals("111"))); Assert.That(restRequest.Value.Parameters, Has.Some.Matches<Parameter>(p => p.Name.Equals("format") && p.Value.Equals("JSON"))); }
/// <summary> /// Find all subscriptions for the user. /// Search for subscriptions on campaign id, resource, event, from number, to number, or whether they are enabled. /// </summary> /// <param name="request">request object with different fields to filter</param> /// <returns>paged list with subscriptions</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<Subscription> Find(FindSubscriptionsRequest request) { return Client.Get<Page<Subscription>>(SUBSCRIPTIONS_PATH, request); }