예제 #1
0
        public async Task <SendRecipientListsResponse> Create(RecipientList recipientList)
        {
            var request = new Request
            {
                Url    = $"api/{client.Version}/recipient-lists?num_rcpt_errors=3",
                Method = "POST",
                Data   = dataMapper.ToDictionary(recipientList)
            };

            var response = await requestSender.Send(request);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new ResponseException(response);
            }

            var results = JsonConvert.DeserializeObject <dynamic>(response.Content).results;

            return(new SendRecipientListsResponse()
            {
                Id = results.id,
                TotalAcceptedRecipients = results.total_accepted_recipients,
                TotalRejectedRecipients = results.total_rejected_recipients,
                Name = results.name,
                Content = response.Content,
                StatusCode = response.StatusCode,
                ReasonPhrase = response.ReasonPhrase
            });
        }
예제 #2
0
        public IDictionary <string, object> ToDictionary(RecipientList recipientList)
        {
            var data = new Dictionary <string, object>
            {
                ["recipients"] = recipientList.Recipients.Select(ToDictionary),
                ["attributes"] = recipientList.Attributes != null
                ? (object)new Dictionary <string, object> {
                    ["internal_id"]     = recipientList.Attributes.InternalId
                    , ["list_group_id"] = recipientList.Attributes.ListGroupId
                } : null
            };
            var result = WithCommonConventions(recipientList, data);

            return(result);
        }
        public async Task <UpdateRecipientListResponse> Update(RecipientList recipientList)
        {
            var request = new Request
            {
                Url    = $"api/{client.Version}/recipient-lists/{recipientList.Id}",
                Method = "PUT",
                Data   = dataMapper.ToDictionary(recipientList)
            };

            var response = await requestSender.Send(request);

            if (new[] { HttpStatusCode.OK, HttpStatusCode.NotFound }.Contains(response.StatusCode) == false)
            {
                throw new ResponseException(response);
            }

            return(new UpdateRecipientListResponse()
            {
                ReasonPhrase = response.ReasonPhrase,
                StatusCode = response.StatusCode,
                Content = response.Content,
            });
        }