public async static Task <ListPrivateAddressResponse> List(GetAddesssApi api, ListPrivateAddressRequest request, string path, AdminKey adminKey)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }


            var fullPath = path + request.Postcode;

            api.SetAuthorizationKey(adminKey);

            var response = await api.Get(fullPath);

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

            if (response.IsSuccessStatusCode)
            {
                var addresses = GetPrivateAddresses(body);

                return(new ListPrivateAddressResponse.Success((int)response.StatusCode, response.ReasonPhrase, body, addresses));
            }

            return(new ListPrivateAddressResponse.Failed((int)response.StatusCode, response.ReasonPhrase, body));
        }
Beispiel #2
0
        private async static Task <GetInvoiceResponse> GetInternal(GetAddesssApi api, string path, AdminKey adminKey, string number)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (adminKey == null)
            {
                throw new ArgumentNullException(nameof(adminKey));
            }


            api.SetAuthorizationKey(adminKey);

            var response = await api.Get(path);

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

            if (response.IsSuccessStatusCode)
            {
                var invoice = GetInvoice(body, number);

                return(new GetInvoiceResponse.Success((int)response.StatusCode, response.ReasonPhrase, body, invoice));
            }

            return(new GetInvoiceResponse.Failed((int)response.StatusCode, response.ReasonPhrase, body));
        }
Beispiel #3
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));
        }
        public async static Task <RemoveIpAddressWhitelistResponse> Remove(GetAddesssApi api, RemoveIpAddressWhitelistRequest request, string path, AdminKey adminKey)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }


            var fullPath = path + request.Id;

            api.SetAuthorizationKey(adminKey);

            var response = await api.Delete(fullPath);

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

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

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

            return(new RemoveIpAddressWhitelistResponse.Failed((int)response.StatusCode, response.ReasonPhrase, body));
        }
Beispiel #5
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 <RemovePrivateAddressResponse> Remove(GetAddesssApi api, RemovePrivateAddressRequest request, string path, AdminKey adminKey)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }


            var fullPath = $"{path}{request.Postcode}/{request.Id}";

            api.SetAuthorizationKey(adminKey);

            var response = await api.Delete(fullPath);

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

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

            return(new RemovePrivateAddressResponse.Failed((int)response.StatusCode, response.ReasonPhrase, body));
        }
Beispiel #7
0
        public async static Task <GetUsageResponse> Get(GetAddesssApi api, string path, AdminKey adminKey)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (adminKey == null)
            {
                throw new ArgumentNullException(nameof(adminKey));
            }


            api.SetAuthorizationKey(adminKey);

            var response = await api.Get(path);

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

            if (response.IsSuccessStatusCode)
            {
                var usage = GetUsage(body);

                return(new GetUsageResponse.Success((int)response.StatusCode, response.ReasonPhrase, body, usage.Count,
                                                    usage.Limit1, usage.Limit2));
            }

            return(new GetUsageResponse.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));
        }
Beispiel #9
0
        private async static Task <GetExpiredCCResponse> GetCCInternal(GetAddesssApi api, string path, AdminKey adminKey, long id)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (adminKey == null)
            {
                throw new ArgumentNullException(nameof(adminKey));
            }

            api.SetAuthorizationKey(adminKey);

            var response = await api.Get(path);

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

            if (response.IsSuccessStatusCode)
            {
                var cC = ExpiredCC.Deserialize(body);

                return(new GetExpiredCCResponse.Success((int)response.StatusCode, response.ReasonPhrase, body, cC));
            }

            return(new GetExpiredCCResponse.Failed((int)response.StatusCode, response.ReasonPhrase, body));
        }
        public async static Task <DistanceResponse> Get(GetAddesssApi api, string path, ApiKey apiKey, DistanceRequest request)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (apiKey == null)
            {
                throw new ArgumentNullException(nameof(apiKey));
            }


            api.SetAuthorizationKey(apiKey);

            var fullPath = $"{path}{request.PostcodeFrom}/{request.PostcodeTo}";

            var response = await api.Get(fullPath);

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

            if (response.IsSuccessStatusCode)
            {
                var distance = Distance.FromJson(body);

                return(new DistanceResponse.Success((int)response.StatusCode, response.ReasonPhrase, body, distance));
            }

            return(new DistanceResponse.Failed((int)response.StatusCode, response.ReasonPhrase, body));
        }
Beispiel #11
0
        public async static Task <ListInvoicesResponse> List(GetAddesssApi api, string path, AdminKey adminKey)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            api.SetAuthorizationKey(adminKey);

            var response = await api.Get(path);

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

            if (response.IsSuccessStatusCode)
            {
                var list = GetInvoiceList(body);

                return(new ListInvoicesResponse.Success((int)response.StatusCode, response.ReasonPhrase, body, list));
            }

            return(new ListInvoicesResponse.Failed((int)response.StatusCode, response.ReasonPhrase, body));
        }
        public async static Task <AddIpAddressWhitelistResponse> Add(GetAddesssApi api, AddIpAddressWhitelistRequest 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.Post(path, request);

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


            if (response.IsSuccessStatusCode)
            {
                var messageAndId = GetMessageAndId(body);

                return(new AddIpAddressWhitelistResponse.Success((int)response.StatusCode, response.ReasonPhrase, body, messageAndId.Message, messageAndId.Id));
            }

            return(new AddIpAddressWhitelistResponse.Failed((int)response.StatusCode, response.ReasonPhrase, body));
        }
Beispiel #13
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));
        }
Beispiel #14
0
        public async static Task <PlaceDetailsResponse> PlaceDetails(GetAddesssApi api, string path, ApiKey apiKey, PlaceDetailsRequest request)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (apiKey == null)
            {
                throw new ArgumentNullException(nameof(apiKey));
            }
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var fullPath = $"{path}{request.PlaceId.Value}/?google-api-key={request.GoogleApiKey.Value}";

            api.SetAuthorizationKey(apiKey);

            var response = await api.Get(fullPath);

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

            if (response.IsSuccessStatusCode)
            {
                var addressBody = GetSingleExpandedAddressFromBody(json);

                double latitude  = addressBody.Item1;
                double longitude = addressBody.Item2;
                var    address   = addressBody.Item4;
                var    postcode  = addressBody.Item3;

                return(new PlaceDetailsResponse.Success((int)response.StatusCode, response.ReasonPhrase, json, latitude, longitude, postcode, address));
            }

            return(new PlaceDetailsResponse.Failed((int)response.StatusCode, response.ReasonPhrase, json));
        }
Beispiel #15
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));
        }
Beispiel #16
0
        public async static Task <GetExpandedAddressResponse> GetExpanded(GetAddesssApi api, string path, ApiKey apiKey, GetAddressRequest request)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (apiKey == null)
            {
                throw new ArgumentNullException(nameof(apiKey));
            }
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var fullPath = $"{path}{request.Postcode}/{request.House}/?sort={request.Sort}&expand={true}&fuzzy={request.Fuzzy}";

            api.SetAuthorizationKey(apiKey);

            var response = await api.Get(fullPath);

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

            if (response.IsSuccessStatusCode)
            {
                var    addressesBody = GetExpandedAddressFromBody(body);
                double latitude      = addressesBody.Item1;
                double longitude     = addressesBody.Item2;
                var    addresses     = addressesBody.Item4;
                var    postcode      = addressesBody.Item3;
                return(new GetExpandedAddressResponse.Success((int)response.StatusCode, response.ReasonPhrase, body, latitude, longitude, postcode, addresses));
            }

            return(new GetExpandedAddressResponse.Failed((int)response.StatusCode, response.ReasonPhrase, body));
        }
        private async static Task <AutocompleteResponse> GetResponse(GetAddesssApi api, string path, ApiKey apiKey, AutocompleteRequest request)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (apiKey == null)
            {
                throw new ArgumentNullException(nameof(apiKey));
            }
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var fullPath = $"{path}places/{request.Input}?google-api-key={request.GoogleApiKey.Value}";

            fullPath = AddSessionToken(fullPath, request);
            fullPath = AddIpAddress(fullPath, request);

            api.SetAuthorizationKey(apiKey);

            var response = await api.Get(fullPath);

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

            if (response.IsSuccessStatusCode)
            {
                var predictions = GetPredictions(json);

                return(new AutocompleteResponse.Success((int)response.StatusCode, response.ReasonPhrase, json, predictions));
            }

            return(new AutocompleteResponse.Failed((int)response.StatusCode, response.ReasonPhrase, json));
        }
Beispiel #18
0
        internal async static Task <TestWebhookResponse> Test(GetAddesssApi api, string path, AdminKey adminKey)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }

            api.SetAuthorizationKey(adminKey);

            var response = await api.Post(path);

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

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

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

            return(new TestWebhookResponse.Failed((int)response.StatusCode, response.ReasonPhrase, body));
        }
Beispiel #19
0
        public async static Task <PermissionResponse> Get(GetPermissionRequest request, GetAddesssApi api, string path, AdminKey adminKey)
        {
            if (request is null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (adminKey == null)
            {
                throw new ArgumentNullException(nameof(adminKey));
            }

            api.SetAuthorizationKey(adminKey);

            var fullPath = path + $"{request.EmailAddress}/";

            var response = await api.Get(fullPath);

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

            if (response.IsSuccessStatusCode)
            {
                var permission = GetPermission(body);

                return(new PermissionResponse.Success((int)response.StatusCode, response.ReasonPhrase, body, permission));
            }

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


            var fullPath = path + request.Id;

            api.SetAuthorizationKey(adminKey);

            var response = await api.Get(fullPath);

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

            if (response.IsSuccessStatusCode)
            {
                var webhook = GetFirstLimitWebhook(body);

                return(new GetFirstLimitReachedWebhookResponse.Success((int)response.StatusCode, response.ReasonPhrase, body, webhook.Id, webhook.Url));
            }

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

            var fullPath = $"{path}{request.Postcode}/{request.Id}";

            api.SetAuthorizationKey(adminKey);

            var response = await api.Get(fullPath);

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

            if (response.IsSuccessStatusCode)
            {
                var addressAndId = GetPrivateAddress(body);
                return(new GetPrivateAddressResponse.Success((int)response.StatusCode, response.ReasonPhrase, body, addressAndId.Id,
                                                             addressAndId.Line1, addressAndId.Line2, addressAndId.Line3, addressAndId.Line4, addressAndId.Locality, addressAndId.TownOrCity, addressAndId.County));
            }

            return(new GetPrivateAddressResponse.Failed((int)response.StatusCode, response.ReasonPhrase, body));
        }
Beispiel #22
0
        public async static Task <SubscriptionResponse> Get(GetAddesssApi api, string path, AdminKey adminKey)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }

            api.SetAuthorizationKey(adminKey);

            var fullPath = path;

            var response = await api.Get(fullPath);

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

            if (response.IsSuccessStatusCode)
            {
                var subscription = GetSubscription(body);

                return(new SubscriptionResponse.Success((int)response.StatusCode, response.ReasonPhrase, body, subscription));
            }

            return(new SubscriptionResponse.Failed((int)response.StatusCode, response.ReasonPhrase, body));
        }
        public async static Task <GetIpAddressWhitelistResponse> Get(GetAddesssApi api, string path, AdminKey adminKey, string id)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (adminKey == null)
            {
                throw new ArgumentNullException(nameof(adminKey));
            }
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            var fullPath = path + id;

            api.SetAuthorizationKey(adminKey);

            var response = await api.Get(fullPath);

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

            if (response.IsSuccessStatusCode)
            {
                var valueAndId = GetIpAddressWhitelist(body);

                return(new GetIpAddressWhitelistResponse.Success((int)response.StatusCode, response.ReasonPhrase, body, valueAndId.Id, valueAndId.Value));
            }

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