Beispiel #1
0
        public IActionResult GetPostcodeApiLimit()
        {
            PostcodeApiClient client = new PostcodeApiClient(Config["PostcodeAPI:Key"]);
            int?remaining            = client.RequestsRemaining;

            return(Ok(new { remaining }));
        }
        public void GetSinglePostcodeInformation()
        {
            PostcodeApiClient client = new PostcodeApiClient(ApiKey);
            PostcodeArea      result = client.GetPostcode("1097JR");

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Streets.Count);
            Assert.AreEqual("Pierre Lallementstraat", result.Streets[0]);
            Assert.AreEqual("Amsterdam", result.City.Label);
        }
        public void GetLargePostcodeSet()
        {
            PostcodeApiClient   client = new PostcodeApiClient(ApiKey);
            ApiHalResultWrapper result = client.GetPostcodes("1097");

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Links.Self);
            Assert.IsNotNull(result.Links.Next);
            Assert.IsTrue(result.Embedded.Postcodes.Count == 20);
            Assert.AreEqual("Amsterdam", result.Embedded.Postcodes[0].City.Label);
        }
        public void RequestsLimitsAreFilled()
        {
            PostcodeApiClient client = new PostcodeApiClient(_apiKey);

            Assert.IsNull(client.RequestDayLimit);
            Assert.IsNull(client.RequestsRemaining);

            client.GetAddressInfo("0268200000075156");

            Assert.IsNotNull(client.RequestDayLimit);
            Assert.IsNotNull(client.RequestsRemaining);
        }
Beispiel #5
0
        public void GetLargeAddressRange()
        {
            PostcodeApiClient   client = new PostcodeApiClient(ApiKey);
            ApiHalResultWrapper result = client.GetAddress("1097JR");

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Links.Self);
            Assert.IsNotNull(result.Links.Next);
            Assert.IsTrue(result.Embedded.Addresses.Count == 20);
            Assert.AreEqual("Pierre Lallementstraat", result.Embedded.Addresses[0].Street);
            Assert.AreEqual("Amsterdam", result.Embedded.Addresses[0].City.Label);
        }
Beispiel #6
0
        public void GetAddressRange()
        {
            PostcodeApiClient   client = new PostcodeApiClient(ApiKey);
            ApiHalResultWrapper result = client.GetAddress("1446WP");

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Links.Self);
            Assert.IsNull(result.Links.Next);
            Assert.IsTrue(result.Embedded.Addresses.Count > 1);
            Assert.AreEqual("Component", result.Embedded.Addresses[0].Street);
            Assert.AreEqual("Purmerend", result.Embedded.Addresses[0].City.Label);
        }
Beispiel #7
0
        public void GetSingleAddress()
        {
            PostcodeApiClient client  = new PostcodeApiClient(ApiKey);
            Address           address = client.GetAddressInfo("0268200000075156");

            Assert.IsNotNull(address);
            Assert.IsNotNull(address.Geo.GeographicCenter);
            Assert.IsNotNull(address.Geo.GeographicExterior);
            Assert.AreEqual(1, address.Geo.GeographicExterior.WGSCoordinates.Coordinates.Count);
            Assert.AreEqual(5, address.Geo.GeographicExterior.WGSCoordinates.Coordinates[0].Count);
            Assert.AreEqual(2, address.Geo.GeographicExterior.WGSCoordinates.Coordinates[0][1].Count);
        }
Beispiel #8
0
        public void GetSpecificAddress()
        {
            PostcodeApiClient   client = new PostcodeApiClient(ApiKey);
            ApiHalResultWrapper result = client.GetAddress("1446WP", 106);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Links.Self);
            Assert.AreEqual(1, result.Embedded.Addresses.Count);
            Assert.AreEqual("Component", result.Embedded.Addresses[0].Street);
            Assert.AreEqual("Purmerend", result.Embedded.Addresses[0].City.Label);
            Assert.AreEqual(1997, result.Embedded.Addresses[0].Year);
            Assert.AreEqual(682, result.Embedded.Addresses[0].SurfaceArea);
        }
        public void RequestLimitsAreUpdatedAfterEachRequest()
        {
            PostcodeApiClient client = new PostcodeApiClient(_apiKey);

            client.GetAddressInfo("0268200000075156");

            int?remaining = client.RequestsRemaining;
            int?limit     = client.RequestDayLimit;

            Assert.IsNotNull(remaining, "Calls remaining: {0}", remaining);
            Assert.IsNotNull(limit, "Max calls: {0}", limit);

            client.GetAddressInfo("0268200000075156");

            Assert.IsTrue(client.RequestsRemaining < remaining, "Calls remaining (after query): {0}", client.RequestsRemaining);
            Assert.AreEqual(limit, client.RequestDayLimit);
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter Postcode:");
            string   postcode          = Console.ReadLine();
            var      PostcodeApiClient = new PostcodeApiClient();
            Postcode postcodeData      = PostcodeApiClient.GetLatLong(postcode);

            var         TflApiClient = new TflApiClient();
            List <Stop> busStops     = TflApiClient.GetBusStopCodes(postcodeData);

            int[] zeroOne = new int[] { 0, 1 };
            foreach (int i in zeroOne)
            {
                var nextStop = busStops[i];
                Console.WriteLine(nextStop.commonName);
                var nearestStopCode = nextStop.naptanId;
                PrintBusTimes(TflApiClient.GetBusTimes(nearestStopCode));
            }

            Console.ReadLine();
        }
Beispiel #11
0
        public IActionResult FetchAddress([FromBody] PostcodeApiRequestModel model)
        {
            PostcodeApiClient client = new PostcodeApiClient(Config["PostcodeAPI:Key"]);

            try
            {
                ApiHalResultWrapper       result   = client.GetAddress(model.Zip, int.Parse(model.Number));
                PostcodeAPI.Model.Address address  = result.Embedded.Addresses[0];
                AddressResponse           response = new AddressResponse
                {
                    City     = address.City.ToString(),
                    Street   = address.Street,
                    Province = address.Province.ToString()
                };
                return(Ok(new { response }));
            }
            catch (ArgumentException)
            {
                return(BadRequest());
            }
        }
Beispiel #12
0
        public ActionResult BusInfo(PostcodeSelection selection)
        {
            bool        valid = true;
            List <Stop> stops = new List <Stop>();

            var      PostcodeApiClient = new PostcodeApiClient();
            Postcode postcodeData      = PostcodeApiClient.GetLatLong(selection.Postcode);

            if (postcodeData == null)
            {
                valid = false;
            }
            else
            {
                var TflApiClient = new TflApiClient();
                stops = TflApiClient.GetBusStopCodes(postcodeData);

                if (!stops.Any())
                {
                    valid = false;
                }

                foreach (Stop s in stops)
                {
                    s.buses = TflApiClient.GetBusTimes(s.naptanId);
                }
            }

            var info = new BusInfo(selection.Postcode)
            {
                PostCode = selection.Postcode,
                Stops    = stops,
                Valid    = valid
            };

            return(View(info));
        }
Beispiel #13
0
        public void SetUp()
        {
            string apiKey = ConfigurationManager.AppSettings.Get("ApiKey");

            _client = new PostcodeApiClient(apiKey);
        }
Beispiel #14
0
        public void Setup()
        {
            string apiKey = ConfigurationManager.AppSettings.Get("V3ApiKey");

            _client = new PostcodeApiClient(Environment.SANDBOX, apiKey);
        }