Пример #1
0
        public async static Task <UnsubscribeResponse> Unsubscribe(GetAddesssApi api, string path, AdminKey adminKey, string code = null)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }

            api.SetAuthorizationKey(adminKey);

            var fullPath = path + "unsubscribe";

            if (!string.IsNullOrWhiteSpace(code))
            {
                fullPath += $"?code={code}";
            }

            var response = await api.Put(fullPath);

            var body = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                return(new UnsubscribeResponse.Success((int)response.StatusCode, response.ReasonPhrase, body));
            }

            return(new UnsubscribeResponse.Failed((int)response.StatusCode, response.ReasonPhrase, body));
        }
Пример #2
0
        public async static Task <UpdatePermissionResponse> Update(GetAddesssApi api, UpdatePermissionRequest request, string path, AdminKey adminKey)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            api.SetAuthorizationKey(adminKey);

            var response = await api.Put(path, request);

            var body = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                var message = MessageResponse.GetMessageResponse(body);

                return(new UpdatePermissionResponse.Success((int)response.StatusCode, response.ReasonPhrase, body, message.Message));
            }

            return(new UpdatePermissionResponse.Failed((int)response.StatusCode, response.ReasonPhrase, body));
        }
        public async static Task <EmailAddressResponse> Update(GetAddesssApi api, string path, AdminKey adminKey, UpdateEmailAddressRequest request)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }

            api.SetAuthorizationKey(adminKey);

            var response = await api.Put(path, request);

            var body = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                return(new EmailAddressResponse.Success((int)response.StatusCode, response.ReasonPhrase, body, request.NewEmailAddress));
            }

            if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
            {
                var message = GetMessage(body);
                return(new EmailAddressResponse.FailedInvalidEmailAddress((int)response.StatusCode, response.ReasonPhrase, body, message));
            }

            return(new EmailAddressResponse.Failed((int)response.StatusCode, response.ReasonPhrase, body));
        }
Пример #4
0
        public async static Task <BillingAddressResponse> Update(GetAddesssApi api, BillingAddressRequest request, string path, AdminKey adminKey)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            api.SetAuthorizationKey(adminKey);

            var response = await api.Put(path, request);

            var body = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                var address = GetBillingAddress(body);

                return(new BillingAddressResponse.Success((int)response.StatusCode, response.ReasonPhrase, body,
                                                          address.Line1, address.Line2, address.Line3, address.TownOrCity, address.County, address.Postcode));
            }

            return(new BillingAddressResponse.Failed((int)response.StatusCode, response.ReasonPhrase, body));
        }
Пример #5
0
        public async static Task <ApiKeyResponse> Update(GetAddesssApi api, string path, AdminKey adminKey)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }

            api.SetAuthorizationKey(adminKey);

            var response = await api.Put(path);

            var body = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                var model = GetApiKey(body);

                return(new ApiKeyResponse.Success((int)response.StatusCode, response.ReasonPhrase, body, model.ApiKey));
            }

            return(new ApiKeyResponse.Failed((int)response.StatusCode, response.ReasonPhrase, body));
        }