public static void Main()
        {
            const string postcode = "D08XY00";
            var autoaddressClient = new AutoaddressClient();
            var request = new Request(postcode: postcode, language: Language.EN, country: Country.IE, limit: 20, geographicAddress: false, vanityMode: false, addressElements: false, addressProfileName: null);

            var response1 = autoaddressClient.PostcodeLookup(request);

            Console.WriteLine("response1.Result = {0}", response1.Result);
            Console.WriteLine("response1.MatchLevel = {0}", response1.MatchLevel);
            Console.WriteLine("response1.AddressType = {0}", response1.AddressType);
            Console.WriteLine("response1.AddressId = {0}", response1.AddressId);
            Console.WriteLine("response1.Postcode = {0}", response1.Postcode);
            Console.WriteLine("response1.PostalAddress = {0}", string.Join(",", response1.PostalAddress));
            Console.WriteLine("response1.Options[0].DisplayName = {0}", response1.Options[0].DisplayName);
            Console.WriteLine("response1.Options[1].DisplayName = {0}", response1.Options[1].DisplayName);
            Console.WriteLine("response1.Options[2].DisplayName = {0}", response1.Options[2].DisplayName);

            var response2 = autoaddressClient.PostcodeLookup(response1.Options[2].Links.OfType<Model.PostcodeLookup.Link>().First());
            
            Console.WriteLine("response2.Result = {0}", response2.Result);
            Console.WriteLine("response2.MatchLevel = {0}", response2.MatchLevel);
            Console.WriteLine("response2.AddressType = {0}", response2.AddressType);
            Console.WriteLine("response2.AddressId = {0}", response2.AddressId);
            Console.WriteLine("response2.Postcode = {0}", response2.Postcode);
            Console.WriteLine("response2.PostalAddress = {0}", string.Join(",", response2.PostalAddress));
        }
        internal Response(ReturnCode result,
                          string postcode,
                          int? addressId,
                          AddressType? addressType,
                          MatchLevel matchLevel,
                          string[] postalAddress,
                          AddressElement[] postalAddressElements,
                          string[] geographicAddress,
                          AddressElement[] geographicAddressElements,
                          string[] vanityAddress,
                          AddressElement[] vanityAddressElements,
                          ReformattedAddressResult? reformattedAddressResult,
                          string[] reformattedAddress,
                          int totalOptions,
                          Option[] options,
                          Request input,
                          Model.Link[] links
            )
        {
            if (links == null) throw new ArgumentNullException("links");

            Result = result;
            Postcode = postcode;
            AddressId = addressId;
            AddressType = addressType;
            MatchLevel = matchLevel;
            PostalAddress = postalAddress;
            PostalAddressElements = postalAddressElements;
            GeographicAddress = geographicAddress;
            GeographicAddressElements = geographicAddressElements;
            VanityAddress = vanityAddress;
            VanityAddressElements = vanityAddressElements;
            ReformattedAddressResult = reformattedAddressResult;
            ReformattedAddress = reformattedAddress;
            TotalOptions = totalOptions;
            Options = options;
            Input = input;

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

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

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

                newLinks.Add(newLink);
            }

            Links = newLinks.ToArray();
        }
예제 #3
0
        /// <summary>
        /// Lookup a Postcode as an asynchronous operation. Returns all available data if found.
        /// </summary>
        /// <param name="request">PostcodeLookup request.</param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <example>
        /// The following code example creates an AutoaddressClient and calls PostcodeLookupAsync with a request.
        /// <code source="..\src\Autoaddress2.0SDK.Test\Example\AutoaddressClientPostcodeLookupAsyncRequestExample1.cs" language="cs" />
        /// </example>
        public async Task <Model.PostcodeLookup.Response> PostcodeLookupAsync(Model.PostcodeLookup.Request request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            Uri requestUri = GetRequestUri(_licenceKey, request.Txn, _autoaddressConfig.ApiBaseAddress, Version, PostcodeLookupMethod, request);
            var response   = await GetResponseAsync <Model.PostcodeLookup.Response>(request, requestUri);

            return(response);
        }
        public static void Main()
        {
            const string postcode = "A86VC04";
            var autoaddressClient = new AutoaddressClient();
            var request = new Request(postcode: postcode, language: Language.EN, country: Country.IE, limit: 20, geographicAddress: false, vanityMode: false, addressElements: false, addressProfileName: null);

            var response = autoaddressClient.PostcodeLookup(request);

            Console.WriteLine("response.Result = {0}", response.Result);
            Console.WriteLine("response.MatchLevel = {0}", response.MatchLevel);
            Console.WriteLine("response.AddressType = {0}", response.AddressType);
            Console.WriteLine("response.AddressId = {0}", response.AddressId);
            Console.WriteLine("response.Postcode = {0}", response.Postcode);
            Console.WriteLine("response.PostalAddress = {0}", string.Join(",", response.PostalAddress));
        }
예제 #5
0
        /// <summary>
        /// Lookup a Postcode. Returns all available data if found.
        /// </summary>
        /// <param name="request">PostcodeLookup request.</param>
        /// <returns>PostcodeLookup response.</returns>
        /// <example>
        /// The following code example creates an AutoaddressClient and calls PostcodeLookup with a request.
        /// <code source="..\src\Autoaddress2.0SDK.Test\Example\AutoaddressClientPostcodeLookupRequestExample1.cs" language="cs" />
        /// </example>
        public Model.PostcodeLookup.Response PostcodeLookup(Model.PostcodeLookup.Request request)
        {
            try
            {
                return(PostcodeLookupAsync(request).Result);
            }
            catch (Exception e)
            {
                if (e.InnerException != null)
                {
                    throw e.InnerException;
                }

                throw;
            }
        }