public async Task <CreateTemplateResponse> Create(Template template) { var request = new Request { Url = $"api/{client.Version}/templates", Method = "POST", Data = dataMapper.ToDictionary(template) }; var response = await requestSender.Send(request); if (response.StatusCode != HttpStatusCode.OK) { throw new ResponseException(response); } var createTemplateResponse = new CreateTemplateResponse() { ReasonPhrase = response.ReasonPhrase, StatusCode = response.StatusCode, Content = response.Content }; try { var results = JsonConvert.DeserializeObject <dynamic>(response.Content).results; createTemplateResponse.Id = results.Id; } catch { // ignored. } return(createTemplateResponse); }
public async Task <ListSuppressionResponse> List(object query = null) { if (query == null) { query = new {} } ; var request = new Request { Url = $"/api/{client.Version}/suppression-list", Method = "GET", Data = query }; var response = await requestSender.Send(request); if (response.StatusCode != HttpStatusCode.OK) { throw new ResponseException(response); } var results = Jsonification.DeserializeObject <dynamic>(response.Content).results; return(new ListSuppressionResponse { ReasonPhrase = response.ReasonPhrase, StatusCode = response.StatusCode, Content = response.Content, Suppressions = ConvertResultsToAListOfSuppressions(results) }); }
public async Task <SendTransmissionResponse> Send(Transmission transmission) { var request = new Request { Url = $"api/{client.Version}/transmissions", Method = "POST", Data = dataMapper.ToDictionary(transmission) }; var response = await requestSender.Send(request); if (response.StatusCode != HttpStatusCode.OK) { throw new ResponseException(response); } var results = Jsonification.DeserializeObject <JsonSendResponse>(response.Content).Results; return(new SendTransmissionResponse() { Id = results.Id, ReasonPhrase = response.ReasonPhrase, StatusCode = response.StatusCode, Content = response.Content, TotalAcceptedRecipients = results.TotalAcceptedRecipients, TotalRejectedRecipients = results.TotalRejectedRecipients, }); }
public async Task <ListSuppressionResponse> List(string url, SuppressionsQuery supppressionsQuery) { var request = new Request { Url = url, Method = "GET", Data = (object)supppressionsQuery ?? new { } }; var response = await requestSender.Send(request); if (response.StatusCode != HttpStatusCode.OK) { throw new ResponseException(response); } var content = Jsonification.DeserializeObject <dynamic>(response.Content); return(new ListSuppressionResponse { ReasonPhrase = response.ReasonPhrase, StatusCode = response.StatusCode, Content = response.Content, Suppressions = ConvertResultsToAListOfSuppressions(content.results), TotalCount = content.total_count, Links = ConvertToLinks(content.links) }); }
public async Task <RetrieveRecipientListsResponse> Retrieve(string recipientListsId) { var request = new Request { Url = $"api/{client.Version}/recipient-lists/" + recipientListsId + "?show_recipients=true", Method = "GET", }; var response = await requestSender.Send(request); if (new[] { HttpStatusCode.OK, HttpStatusCode.NotFound }.Contains(response.StatusCode) == false) { throw new ResponseException(response); } var recipientListsResponse = new RetrieveRecipientListsResponse() { ReasonPhrase = response.ReasonPhrase, StatusCode = response.StatusCode, Content = response.Content, }; var results = JsonConvert.DeserializeObject <dynamic>(response.Content).results; if (results.recipients == null) { return(recipientListsResponse); } recipientListsResponse.Id = results.id; recipientListsResponse.Name = results.name; recipientListsResponse.Description = results.description; recipientListsResponse.Attributes = results.attributes != null ? new Attributes { InternalId = results.attributes.internal_id , ListGroupId = results.attributes.list_group_id } : null; recipientListsResponse.TotalAcceptedRecipients = results.total_accepted_recipients; recipientListsResponse.RecipientLists = RetrieveRecipientListsResponse.CreateFromResponse(response); recipientListsResponse.RecipientList = new RecipientList { Id = recipientListsResponse.Id, Recipients = recipientListsResponse.RecipientLists, Attributes = recipientListsResponse.Attributes, Description = recipientListsResponse.Description, Name = recipientListsResponse.Name }; return(recipientListsResponse); }
public async Task <TResponse> Get <TResponse>(string uri) { using (var request = new HttpRequestMessage(HttpMethod.Get, uri)) { var response = await requestSender.Send(request).ConfigureAwait(false); var deserialized = await responseDeserializer.Deserialize <TResponse>(response).ConfigureAwait(false); return(deserialized); } }
public void the_payload_is_deserialized() { //Arrange A.CallTo(() => _fakeRequestSender.Send(A <RequestApplicationToChangeRegisterV1_0Type> .Ignored, A <string> .Ignored, A <string> .Ignored)) .Returns(A <Lrap1Response> .Ignored); //Act _sut.Submit(_lrap1Request); //Assert A.CallTo(() => _fakeObjectSerializer.XmlDeserializeFromString <RequestApplicationToChangeRegisterV1_0Type>(_lrap1Request.Payload)) .MustHaveHappened(Repeated.Exactly.Once); }
public virtual Task <Response> Send(Request request) { Response response = null; Task.Run(async() => { response = await requestSender.Send(request); }).Wait(); return(Task.FromResult(response)); }
public async Task <ListSubaccountResponse> List() { var request = new Request { Url = $"/api/{client.Version}/subaccounts", Method = "GET" }; var response = await requestSender.Send(request); if (response.StatusCode != HttpStatusCode.OK) { throw new ResponseException(response); } return(ListSubaccountResponse.CreateFromResponse(response)); }
public void the_payload_is_deserialized() { //Arrange A.CallTo(() => _fakeRequestSender.Send(A <newAttachmentRequest> .Ignored, A <string> .Ignored, A <string> .Ignored)) .Returns(A <Lrap1Response> .Ignored); A.CallTo( () => _fakeObjectSerializer.XmlDeserializeFromString <newAttachmentRequest>(_lrap1AttachmentRequest.Payload)) .Returns(new newAttachmentRequest(new AttachmentV1_0Type())); //Act _sut.Submit(_lrap1AttachmentRequest); //Assert A.CallTo(() => _fakeObjectSerializer.XmlDeserializeFromString <newAttachmentRequest>(_lrap1AttachmentRequest.Payload)) .MustHaveHappened(Repeated.Exactly.Once); }
public async Task <ListWebhookResponse> List(object query = null) { if (query == null) { query = new {} } ; var request = new Request { Url = $"/api/{client.Version}/webhooks", Method = "GET", Data = query }; var response = await requestSender.Send(request); if (response.StatusCode != HttpStatusCode.OK) { throw new ResponseException(response); } return(ListWebhookResponse.CreateFromResponse(response)); }
public async Task <ListMessageEventsResponse> List(object messageEventsQuery) { if (messageEventsQuery == null) { messageEventsQuery = new { } } ; var request = new Request { Url = $"/api/{client.Version}/message-events", Method = "GET", Data = messageEventsQuery }; var response = await requestSender.Send(request); if (response.StatusCode != HttpStatusCode.OK) { throw new ResponseException(response); } dynamic content = Jsonification.DeserializeObject <dynamic>(response.Content); var listMessageEventsResponse = new ListMessageEventsResponse { ReasonPhrase = response.ReasonPhrase, StatusCode = response.StatusCode, Content = response.Content, MessageEvents = ConvertResultsToAListOfMessageEvents(content.results), TotalCount = content.total_count, Links = ConvertToLinks(content.links) }; return(listMessageEventsResponse); }
private async Task <Response> GetApiResponse(string relUrl, object query) { if (query == null) { query = new { } } ; var request = new Request { Url = $"/api/{client.Version}/metrics/{relUrl}", Method = "GET", Data = query }; var response = await requestSender.Send(request); if (response.StatusCode != HttpStatusCode.OK) { throw new ResponseException(response); } return(response); }
public void DoLogin(UserCredentialsModel model, Action <LoginResultModel> cb) { requestSender.Send("/sessions", model, (json) => cb(JsonUtility.FromJson <LoginResultModel>(json))); }