internal Option(string displayName, int? addressId, AddressType? addressType, string postcode, OptionType optionType, Model.Link[] links)
        {
            if (string.IsNullOrWhiteSpace(displayName)) throw new ArgumentNullException("displayName");
            if (links == null) throw new ArgumentNullException("links");

            DisplayName = displayName;
            AddressId = addressId;
            AddressType = addressType;
            Postcode = postcode;
            OptionType = optionType;

            var newLinks = new List<Model.Link>();

            foreach (Model.Link link in links)
            {
                Model.Link newLink;

                switch (link.Rel)
                {
                    case "next":
                        newLink = new Link(link.Rel, link.Href);
                        break;
                    default:
                        newLink = link;
                        break;
                }

                newLinks.Add(newLink);
            }

            Links = newLinks.ToArray();
        }
示例#2
0
        /// <summary>
        /// Lookup a Postcode or Address as an asynchronous operation. Returns all available data if found.
        /// </summary>
        /// <param name="link">A link returned in a FindAddress response.</param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <example>
        /// The following code example creates an AutoaddressClient and calls FindAddressAsync then calls FindAddressAsync again with an option link.
        /// <code source="..\src\Autoaddress2.0SDK.Test\Example\AutoaddressClientFindAddressAsyncLinkExample1.cs" language="cs" />
        /// </example>
        public async Task <Model.FindAddress.Response> FindAddressAsync(Model.FindAddress.Link link)
        {
            if (link == null)
            {
                throw new ArgumentNullException(nameof(link));
            }

            Uri requestUri = link.Href;
            var response   = await GetResponseAsync <Model.FindAddress.Response>(link, requestUri);

            return(response);
        }
示例#3
0
        /// <summary>
        /// Lookup a Postcode or Address. Returns all available data if found.
        /// </summary>
        /// <param name="link">A link returned in a FindAddress response.</param>
        /// <returns>FindAddress response.</returns>
        /// <example>
        /// The following code example creates an AutoaddressClient and calls FindAddress then calls FindAddress again with an option link.
        /// <code source="..\src\Autoaddress2.0SDK.Test\Example\AutoaddressClientFindAddressLinkExample1.cs" language="cs" />
        /// </example>
        public Model.FindAddress.Response FindAddress(Model.FindAddress.Link link)
        {
            try
            {
                return(FindAddressAsync(link).Result);
            }
            catch (Exception e)
            {
                if (e.InnerException != null)
                {
                    throw e.InnerException;
                }

                throw;
            }
        }