ideal_postcodes 0.1.1 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +22 -0
  3. data/CHANGELOG.md +20 -0
  4. data/LICENSE +21 -0
  5. data/README.md +289 -43
  6. data/Rakefile +13 -6
  7. data/ideal-postcodes-ruby.gemspec +11 -11
  8. data/lib/ideal_postcodes.rb +1 -1
  9. data/lib/idealpostcodes/address.rb +31 -0
  10. data/lib/idealpostcodes/errors.rb +31 -26
  11. data/lib/idealpostcodes/key.rb +14 -0
  12. data/lib/idealpostcodes/postcode.rb +20 -32
  13. data/lib/idealpostcodes/util.rb +38 -25
  14. data/lib/idealpostcodes/version.rb +2 -2
  15. data/lib/idealpostcodes.rb +114 -81
  16. data/spec/addresses_spec.rb +68 -0
  17. data/spec/idealpostcodes_spec.rb +56 -0
  18. data/spec/keys_spec.rb +25 -0
  19. data/spec/postcodes_spec.rb +77 -0
  20. data/spec/spec_helper.rb +89 -0
  21. data/spec/vcr_cassettes/IdealPostcodes_Address_lookup_raises_an_exception_if_invalid_key.yml +42 -0
  22. data/spec/vcr_cassettes/IdealPostcodes_Address_lookup_raises_an_exception_if_limit_breached.yml +42 -0
  23. data/spec/vcr_cassettes/IdealPostcodes_Address_lookup_raises_an_exception_if_no_lookups_remaining.yml +42 -0
  24. data/spec/vcr_cassettes/IdealPostcodes_Address_lookup_returns_an_address_for_a_valid_UDPRN.yml +74 -0
  25. data/spec/vcr_cassettes/IdealPostcodes_Address_lookup_returns_nil_for_an_invalid_UDPRN.yml +42 -0
  26. data/spec/vcr_cassettes/IdealPostcodes_Address_search_is_sensitive_to_limit.yml +81 -0
  27. data/spec/vcr_cassettes/IdealPostcodes_Address_search_is_sensitive_to_page.yml +369 -0
  28. data/spec/vcr_cassettes/IdealPostcodes_Address_search_raises_an_exception_if_invalid_key.yml +42 -0
  29. data/spec/vcr_cassettes/IdealPostcodes_Address_search_raises_an_exception_if_limit_breached.yml +42 -0
  30. data/spec/vcr_cassettes/IdealPostcodes_Address_search_raises_an_exception_if_no_lookups_remaining.yml +42 -0
  31. data/spec/vcr_cassettes/IdealPostcodes_Address_search_returns_results_in_a_SearchResult_object.yml +273 -0
  32. data/spec/vcr_cassettes/IdealPostcodes_Key_lookup_details_returns_key_details.yml +62 -0
  33. data/spec/vcr_cassettes/IdealPostcodes_Key_lookup_returns_the_availability_status_of_a_key_false_key_.yml +45 -0
  34. data/spec/vcr_cassettes/IdealPostcodes_Key_lookup_returns_the_availability_status_of_a_key_true_key_.yml +45 -0
  35. data/spec/vcr_cassettes/IdealPostcodes_Postcode_find_by_location_is_sensitive_to_limit_parameter.yml +52 -0
  36. data/spec/vcr_cassettes/IdealPostcodes_Postcode_find_by_location_is_sensitive_to_radius_parament.yml +133 -0
  37. data/spec/vcr_cassettes/IdealPostcodes_Postcode_find_by_location_returns_an_array_of_postcodes_and_locations.yml +84 -0
  38. data/spec/vcr_cassettes/IdealPostcodes_Postcode_find_by_location_returns_an_empty_array_if_no_results_are_found.yml +43 -0
  39. data/spec/vcr_cassettes/IdealPostcodes_Postcode_lookup_raises_an_exception_if_invalid_key.yml +42 -0
  40. data/spec/vcr_cassettes/IdealPostcodes_Postcode_lookup_raises_an_exception_if_key_has_run_out_of_balance.yml +42 -0
  41. data/spec/vcr_cassettes/IdealPostcodes_Postcode_lookup_raises_an_exception_if_limit_has_been_reached.yml +42 -0
  42. data/spec/vcr_cassettes/IdealPostcodes_Postcode_lookup_returns_a_list_of_addresses_for_a_postcode.yml +268 -0
  43. data/spec/vcr_cassettes/IdealPostcodes_Postcode_lookup_returns_an_empty_array_if_postcode_does_not_exist.yml +42 -0
  44. data/spec/vcr_cassettes/IdealPostcodes_key_available_returns_false_if_key_is_unavailable.yml +45 -0
  45. data/spec/vcr_cassettes/IdealPostcodes_key_available_returns_true_if_key_is_available.yml +45 -0
  46. data/spec/vcr_cassettes/IdealPostcodes_key_details_raises_an_exception_if_no_secret_is_provided.yml +45 -0
  47. data/spec/vcr_cassettes/IdealPostcodes_key_details_returns_key_information.yml +62 -0
  48. data/spec/vcr_cassettes/IdealPostcodes_request_generates_a_HTTP_request.yml +268 -0
  49. data/spec/vcr_cassettes/IdealPostcodes_request_raises_authentication_error_if_invalid_key_is_provided.yml +42 -0
  50. data/spec/vcr_cassettes/IdealPostcodes_request_raises_limit_reached_error_if_a_limit_has_been_breached.yml +42 -0
  51. data/spec/vcr_cassettes/IdealPostcodes_request_raises_token_exhausted_error_if_key_balance_is_depleted.yml +42 -0
  52. metadata +117 -52
  53. data/test/test_helper.rb +0 -77
  54. data/test/test_ideal_postcodes.rb +0 -78
@@ -0,0 +1,42 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://localhost:1337/v1/addresses/0?api_key=foo
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ""
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 401
19
+ message: Unauthorized
20
+ headers:
21
+ Access-Control-Allow-Origin:
22
+ - "*"
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Content-Length:
26
+ - "135"
27
+ Etag:
28
+ - '"-632160061"'
29
+ Date:
30
+ - Fri, 12 Dec 2014 17:40:26 GMT
31
+ Connection:
32
+ - keep-alive
33
+ body:
34
+ encoding: UTF-8
35
+ string: |-
36
+ {
37
+ "code": 4010,
38
+ "message": "Invalid Key. For more information see http://ideal-postcodes.co.uk/documentation/response-codes#4010"
39
+ }
40
+ http_version:
41
+ recorded_at: Fri, 12 Dec 2014 17:40:26 GMT
42
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,42 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://localhost:1337/v1/addresses/-3?api_key=gandhi
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ""
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 402
19
+ message: Payment Required
20
+ headers:
21
+ Access-Control-Allow-Origin:
22
+ - "*"
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Content-Length:
26
+ - "144"
27
+ Etag:
28
+ - '"1445167850"'
29
+ Date:
30
+ - Fri, 12 Dec 2014 17:40:26 GMT
31
+ Connection:
32
+ - keep-alive
33
+ body:
34
+ encoding: UTF-8
35
+ string: |-
36
+ {
37
+ "code": 4021,
38
+ "message": "Lookup Limit Reached. For more information see http://ideal-postcodes.co.uk/documentation/response-codes#4021"
39
+ }
40
+ http_version:
41
+ recorded_at: Fri, 12 Dec 2014 17:40:26 GMT
42
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,42 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://localhost:1337/v1/addresses/-2?api_key=gandhi
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ""
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 402
19
+ message: Payment Required
20
+ headers:
21
+ Access-Control-Allow-Origin:
22
+ - "*"
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Content-Length:
26
+ - "146"
27
+ Etag:
28
+ - '"1304241290"'
29
+ Date:
30
+ - Fri, 12 Dec 2014 17:40:26 GMT
31
+ Connection:
32
+ - keep-alive
33
+ body:
34
+ encoding: UTF-8
35
+ string: |-
36
+ {
37
+ "code": 4020,
38
+ "message": "Token balance depleted. For more information see http://ideal-postcodes.co.uk/documentation/response-codes#4020"
39
+ }
40
+ http_version:
41
+ recorded_at: Fri, 12 Dec 2014 17:40:26 GMT
42
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,74 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://localhost:1337/v1/addresses/0?api_key=gandhi
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ""
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Access-Control-Allow-Origin:
22
+ - "*"
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Content-Length:
26
+ - "911"
27
+ Etag:
28
+ - '"1752222490"'
29
+ Date:
30
+ - Fri, 12 Dec 2014 17:40:26 GMT
31
+ Connection:
32
+ - keep-alive
33
+ body:
34
+ encoding: UTF-8
35
+ string: |-
36
+ {
37
+ "result": {
38
+ "postcode": "ID1 1QD",
39
+ "postcode_inward": "1QD",
40
+ "postcode_outward": "ID1",
41
+ "post_town": "LONDON",
42
+ "dependant_locality": "",
43
+ "double_dependant_locality": "",
44
+ "thoroughfare": "Barons Court Road",
45
+ "dependant_thoroughfare": "",
46
+ "building_number": "2",
47
+ "building_name": "",
48
+ "sub_building_name": "",
49
+ "po_box": "",
50
+ "department_name": "",
51
+ "organisation_name": "",
52
+ "udprn": 0,
53
+ "postcode_type": "S",
54
+ "su_organisation_indicator": "",
55
+ "delivery_point_suffix": "1G",
56
+ "line_1": "2 Barons Court Road",
57
+ "line_2": "",
58
+ "line_3": "",
59
+ "premise": "2",
60
+ "country": "England",
61
+ "county": "",
62
+ "district": "Hammersmith and Fulham",
63
+ "ward": "North End",
64
+ "longitude": -0.208644362766368,
65
+ "latitude": 51.4899488390558,
66
+ "eastings": 524466,
67
+ "northings": 178299
68
+ },
69
+ "code": 2000,
70
+ "message": "Success"
71
+ }
72
+ http_version:
73
+ recorded_at: Fri, 12 Dec 2014 17:40:26 GMT
74
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,42 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://localhost:1337/v1/addresses/-1?api_key=gandhi
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ""
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 404
19
+ message: Not Found
20
+ headers:
21
+ Access-Control-Allow-Origin:
22
+ - "*"
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Content-Length:
26
+ - "49"
27
+ Etag:
28
+ - '"-1363169990"'
29
+ Date:
30
+ - Fri, 12 Dec 2014 17:40:26 GMT
31
+ Connection:
32
+ - keep-alive
33
+ body:
34
+ encoding: UTF-8
35
+ string: |-
36
+ {
37
+ "code": 4044,
38
+ "message": "No UDPRN found"
39
+ }
40
+ http_version:
41
+ recorded_at: Fri, 12 Dec 2014 17:40:26 GMT
42
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,81 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://localhost:1337/v1/addresses?api_key=gandhi&limit=1&query=High%20Street
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ""
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Access-Control-Allow-Origin:
22
+ - "*"
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Content-Length:
26
+ - "1141"
27
+ Etag:
28
+ - '"447427024"'
29
+ Date:
30
+ - Fri, 12 Dec 2014 17:40:27 GMT
31
+ Connection:
32
+ - keep-alive
33
+ body:
34
+ encoding: UTF-8
35
+ string: |-
36
+ {
37
+ "result": {
38
+ "total": 245046,
39
+ "limit": 1,
40
+ "page": 0,
41
+ "hits": [
42
+ {
43
+ "dependant_locality": "",
44
+ "postcode_type": "S",
45
+ "po_box": "",
46
+ "post_town": "RHYL",
47
+ "delivery_point_suffix": "1N",
48
+ "double_dependant_locality": "",
49
+ "su_organisation_indicator": "Y",
50
+ "longitude": -3.48941454288796,
51
+ "department_name": "",
52
+ "district": "Denbighshire",
53
+ "building_name": "66a",
54
+ "dependant_thoroughfare": "",
55
+ "northings": 381371,
56
+ "premise": "66a",
57
+ "postcode_outward": "LL18",
58
+ "postcode_inward": "1UB",
59
+ "sub_building_name": "",
60
+ "eastings": 300883,
61
+ "postcode": "LL18 1UB",
62
+ "country": "Wales",
63
+ "udprn": 13525462,
64
+ "line_3": "",
65
+ "organisation_name": "High Street News",
66
+ "ward": "Rhyl West",
67
+ "county": "",
68
+ "line_1": "High Street News",
69
+ "building_number": " ",
70
+ "thoroughfare": "High Street",
71
+ "line_2": "66a High Street",
72
+ "latitude": 53.3199596875698
73
+ }
74
+ ]
75
+ },
76
+ "code": 2000,
77
+ "message": "Success"
78
+ }
79
+ http_version:
80
+ recorded_at: Fri, 12 Dec 2014 17:40:27 GMT
81
+ recorded_with: VCR 2.9.3