internal Response(ReturnCode result,
                          string postcode,
                          SpatialInfo spatialInfo,
                          Request input,
                          Model.Link[] links)
        {
            if (links == null) throw new ArgumentNullException("links");

            Result = result;
            Postcode = postcode;
            SpatialInfo = spatialInfo;
            Input = input;
            
            var newLinks = new List<Model.Link>();

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

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

                newLinks.Add(newLink);
            }

            Links = newLinks.ToArray();
        }
Beispiel #2
0
        /// <summary>
        /// Return data for the supplied UK postcode as an asynchronous operation.
        /// </summary>
        /// <param name="link">A link returned in a GetGbPostcodeData response.</param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public async Task <Model.GetGbPostcodeData.Response> GetGbPostcodeDataAsync(Model.GetGbPostcodeData.Link link)
        {
            if (link == null)
            {
                throw new ArgumentNullException(nameof(link));
            }

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

            return(response);
        }
Beispiel #3
0
        /// <summary>
        /// Return data for the supplied UK postcode.
        /// </summary>
        /// <param name="link">A link returned in a GetGbPostcodeData response.</param>
        /// <returns>GetGbPostcodeData response.</returns>
        public Model.GetGbPostcodeData.Response GetGbPostcodeData(Model.GetGbPostcodeData.Link link)
        {
            try
            {
                return(GetGbPostcodeDataAsync(link).Result);
            }
            catch (Exception e)
            {
                if (e.InnerException != null)
                {
                    throw e.InnerException;
                }

                throw;
            }
        }