ideal_postcodes 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -0
  3. data/README.md +295 -42
  4. data/Rakefile +13 -6
  5. data/ideal-postcodes-ruby.gemspec +9 -10
  6. data/lib/idealpostcodes.rb +30 -9
  7. data/lib/idealpostcodes/address.rb +31 -0
  8. data/lib/idealpostcodes/key.rb +13 -0
  9. data/lib/idealpostcodes/postcode.rb +11 -24
  10. data/lib/idealpostcodes/util.rb +2 -2
  11. data/lib/idealpostcodes/version.rb +1 -1
  12. data/spec/addresses_spec.rb +68 -0
  13. data/spec/idealpostcodes_spec.rb +56 -0
  14. data/spec/keys_spec.rb +25 -0
  15. data/spec/postcodes_spec.rb +66 -0
  16. data/spec/spec_helper.rb +65 -0
  17. data/spec/vcr_cassettes/IdealPostcodes_Address_lookup_raises_an_exception_if_invalid_key.yml +42 -0
  18. data/spec/vcr_cassettes/IdealPostcodes_Address_lookup_raises_an_exception_if_limit_breached.yml +42 -0
  19. data/spec/vcr_cassettes/IdealPostcodes_Address_lookup_raises_an_exception_if_no_lookups_remaining.yml +42 -0
  20. data/spec/vcr_cassettes/IdealPostcodes_Address_lookup_returns_an_address_for_a_valid_UDPRN.yml +74 -0
  21. data/spec/vcr_cassettes/IdealPostcodes_Address_lookup_returns_nil_for_an_invalid_UDPRN.yml +42 -0
  22. data/spec/vcr_cassettes/IdealPostcodes_Address_search_is_sensitive_to_limit.yml +81 -0
  23. data/spec/vcr_cassettes/IdealPostcodes_Address_search_is_sensitive_to_page.yml +369 -0
  24. data/spec/vcr_cassettes/IdealPostcodes_Address_search_raises_an_exception_if_invalid_key.yml +42 -0
  25. data/spec/vcr_cassettes/IdealPostcodes_Address_search_raises_an_exception_if_limit_breached.yml +42 -0
  26. data/spec/vcr_cassettes/IdealPostcodes_Address_search_raises_an_exception_if_no_lookups_remaining.yml +42 -0
  27. data/spec/vcr_cassettes/IdealPostcodes_Address_search_returns_results_in_a_SearchResult_object.yml +273 -0
  28. data/spec/vcr_cassettes/IdealPostcodes_Key_lookup_details_returns_key_details.yml +62 -0
  29. data/spec/vcr_cassettes/IdealPostcodes_Key_lookup_returns_the_availability_status_of_a_key_false_key_.yml +45 -0
  30. data/spec/vcr_cassettes/IdealPostcodes_Key_lookup_returns_the_availability_status_of_a_key_true_key_.yml +45 -0
  31. data/spec/vcr_cassettes/IdealPostcodes_Postcode_find_by_location_is_sensitive_to_limit_parameter.yml +52 -0
  32. data/spec/vcr_cassettes/IdealPostcodes_Postcode_find_by_location_is_sensitive_to_radius_parament.yml +133 -0
  33. data/spec/vcr_cassettes/IdealPostcodes_Postcode_find_by_location_returns_an_array_of_postcodes_and_locations.yml +84 -0
  34. data/spec/vcr_cassettes/IdealPostcodes_Postcode_find_by_location_returns_an_empty_array_if_no_results_are_found.yml +43 -0
  35. data/spec/vcr_cassettes/IdealPostcodes_Postcode_lookup_raises_an_exception_if_invalid_key.yml +42 -0
  36. data/spec/vcr_cassettes/IdealPostcodes_Postcode_lookup_raises_an_exception_if_key_has_run_out_of_balance.yml +42 -0
  37. data/spec/vcr_cassettes/IdealPostcodes_Postcode_lookup_raises_an_exception_if_limit_has_been_reached.yml +42 -0
  38. data/spec/vcr_cassettes/IdealPostcodes_Postcode_lookup_returns_a_list_of_addresses_for_a_postcode.yml +268 -0
  39. data/spec/vcr_cassettes/IdealPostcodes_Postcode_lookup_returns_an_empty_array_if_postcode_does_not_exist.yml +42 -0
  40. data/spec/vcr_cassettes/IdealPostcodes_key_available_returns_false_if_key_is_unavailable.yml +45 -0
  41. data/spec/vcr_cassettes/IdealPostcodes_key_available_returns_true_if_key_is_available.yml +45 -0
  42. data/spec/vcr_cassettes/IdealPostcodes_key_details_raises_an_exception_if_no_secret_is_provided.yml +45 -0
  43. data/spec/vcr_cassettes/IdealPostcodes_key_details_returns_key_information.yml +62 -0
  44. data/spec/vcr_cassettes/IdealPostcodes_request_generates_a_HTTP_request.yml +268 -0
  45. data/spec/vcr_cassettes/IdealPostcodes_request_raises_authentication_error_if_invalid_key_is_provided.yml +42 -0
  46. data/spec/vcr_cassettes/IdealPostcodes_request_raises_limit_reached_error_if_a_limit_has_been_breached.yml +42 -0
  47. data/spec/vcr_cassettes/IdealPostcodes_request_raises_token_exhausted_error_if_key_balance_is_depleted.yml +42 -0
  48. metadata +96 -39
  49. data/test/test_helper.rb +0 -77
  50. data/test/test_ideal_postcodes.rb +0 -78
@@ -0,0 +1,45 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://localhost:1337/v1/keys/gandhi?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
+ - '83'
27
+ Etag:
28
+ - '"2124296415"'
29
+ Date:
30
+ - Fri, 12 Dec 2014 17:48:13 GMT
31
+ Connection:
32
+ - keep-alive
33
+ body:
34
+ encoding: UTF-8
35
+ string: |-
36
+ {
37
+ "result": {
38
+ "available": true
39
+ },
40
+ "code": 2000,
41
+ "message": "Success"
42
+ }
43
+ http_version:
44
+ recorded_at: Fri, 12 Dec 2014 17:48:13 GMT
45
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,62 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://localhost:1337/v1/keys/gandhi?api_key=gandhi&user_token=uk_hxp6ouk0rmyXoobVJnehrsQcdvTfb
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
+ - '405'
27
+ Etag:
28
+ - '"-476306859"'
29
+ Date:
30
+ - Fri, 12 Dec 2014 17:50:14 GMT
31
+ Connection:
32
+ - keep-alive
33
+ body:
34
+ encoding: UTF-8
35
+ string: |-
36
+ {
37
+ "result": {
38
+ "lookups_remaining": 20894,
39
+ "daily_limit": {
40
+ "limit": null,
41
+ "consumed": 0
42
+ },
43
+ "individual_limit": {
44
+ "limit": null
45
+ },
46
+ "allowed_urls": [],
47
+ "notifications": {
48
+ "emails": [
49
+ "cablanchard2@gmail.com"
50
+ ],
51
+ "enabled": true
52
+ },
53
+ "automated_topups": {
54
+ "enabled": true
55
+ }
56
+ },
57
+ "code": 2000,
58
+ "message": "Success"
59
+ }
60
+ http_version:
61
+ recorded_at: Fri, 12 Dec 2014 17:50:14 GMT
62
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,268 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://localhost:1337/v1/postcodes/ID1%201QD?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
+ - '6683'
27
+ Etag:
28
+ - '"1136868456"'
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
+ {
39
+ "postcode": "ID1 1QD",
40
+ "postcode_inward": "1QD",
41
+ "postcode_outward": "ID1",
42
+ "post_town": "LONDON",
43
+ "dependant_locality": "",
44
+ "double_dependant_locality": "",
45
+ "thoroughfare": "Barons Court Road",
46
+ "dependant_thoroughfare": "",
47
+ "building_number": "2",
48
+ "building_name": "",
49
+ "sub_building_name": "",
50
+ "po_box": "",
51
+ "department_name": "",
52
+ "organisation_name": "",
53
+ "udprn": 25962203,
54
+ "postcode_type": "S",
55
+ "su_organisation_indicator": "",
56
+ "delivery_point_suffix": "1G",
57
+ "line_1": "2 Barons Court Road",
58
+ "line_2": "",
59
+ "line_3": "",
60
+ "premise": "2",
61
+ "country": "England",
62
+ "county": "",
63
+ "district": "Hammersmith and Fulham",
64
+ "ward": "North End",
65
+ "longitude": -0.208644362766368,
66
+ "latitude": 51.4899488390558,
67
+ "eastings": 524466,
68
+ "northings": 178299
69
+ },
70
+ {
71
+ "postcode": "ID1 1QD",
72
+ "postcode_inward": "1QD",
73
+ "postcode_outward": "ID1",
74
+ "post_town": "LONDON",
75
+ "dependant_locality": "",
76
+ "double_dependant_locality": "",
77
+ "thoroughfare": "Barons Court Road",
78
+ "dependant_thoroughfare": "",
79
+ "building_number": "2",
80
+ "building_name": "Basement Flat",
81
+ "sub_building_name": "",
82
+ "po_box": "",
83
+ "department_name": "",
84
+ "organisation_name": "",
85
+ "udprn": 52618355,
86
+ "postcode_type": "S",
87
+ "su_organisation_indicator": "",
88
+ "delivery_point_suffix": "3A",
89
+ "line_1": "Basement Flat",
90
+ "line_2": "2 Barons Court Road",
91
+ "line_3": "",
92
+ "premise": "Basement Flat, 2",
93
+ "country": "England",
94
+ "county": "",
95
+ "district": "Hammersmith and Fulham",
96
+ "ward": "North End",
97
+ "longitude": -0.208644362766368,
98
+ "latitude": 51.4899488390558,
99
+ "eastings": 524466,
100
+ "northings": 178299
101
+ },
102
+ {
103
+ "postcode": "ID1 1QD",
104
+ "postcode_inward": "1QD",
105
+ "postcode_outward": "ID1",
106
+ "post_town": "LONDON",
107
+ "dependant_locality": "",
108
+ "double_dependant_locality": "",
109
+ "thoroughfare": "Barons Court Road",
110
+ "dependant_thoroughfare": "",
111
+ "building_number": "4",
112
+ "building_name": "",
113
+ "sub_building_name": "",
114
+ "po_box": "",
115
+ "department_name": "",
116
+ "organisation_name": "",
117
+ "udprn": 25962215,
118
+ "postcode_type": "S",
119
+ "su_organisation_indicator": "",
120
+ "delivery_point_suffix": "1W",
121
+ "line_1": "4 Barons Court Road",
122
+ "line_2": "",
123
+ "line_3": "",
124
+ "premise": "4",
125
+ "country": "England",
126
+ "county": "",
127
+ "district": "Hammersmith and Fulham",
128
+ "ward": "North End",
129
+ "longitude": -0.208644362766368,
130
+ "latitude": 51.4899488390558,
131
+ "eastings": 524466,
132
+ "northings": 178299
133
+ },
134
+ {
135
+ "postcode": "ID1 1QD",
136
+ "postcode_inward": "1QD",
137
+ "postcode_outward": "ID1",
138
+ "post_town": "LONDON",
139
+ "dependant_locality": "",
140
+ "double_dependant_locality": "",
141
+ "thoroughfare": "Barons Court Road",
142
+ "dependant_thoroughfare": "",
143
+ "building_number": "4",
144
+ "building_name": "",
145
+ "sub_building_name": "Basement",
146
+ "po_box": "",
147
+ "department_name": "",
148
+ "organisation_name": "",
149
+ "udprn": 25962189,
150
+ "postcode_type": "S",
151
+ "su_organisation_indicator": "",
152
+ "delivery_point_suffix": "2P",
153
+ "line_1": "Basement",
154
+ "line_2": "4 Barons Court Road",
155
+ "line_3": "",
156
+ "premise": "Basement, 4",
157
+ "country": "England",
158
+ "county": "",
159
+ "district": "Hammersmith and Fulham",
160
+ "ward": "North End",
161
+ "longitude": -0.208644362766368,
162
+ "latitude": 51.4899488390558,
163
+ "eastings": 524466,
164
+ "northings": 178299
165
+ },
166
+ {
167
+ "postcode": "ID1 1QD",
168
+ "postcode_inward": "1QD",
169
+ "postcode_outward": "ID1",
170
+ "post_town": "LONDON",
171
+ "dependant_locality": "",
172
+ "double_dependant_locality": "",
173
+ "thoroughfare": "Barons Court Road",
174
+ "dependant_thoroughfare": "",
175
+ "building_number": "6",
176
+ "building_name": "",
177
+ "sub_building_name": "",
178
+ "po_box": "",
179
+ "department_name": "",
180
+ "organisation_name": "",
181
+ "udprn": 25962218,
182
+ "postcode_type": "S",
183
+ "su_organisation_indicator": "",
184
+ "delivery_point_suffix": "1Y",
185
+ "line_1": "6 Barons Court Road",
186
+ "line_2": "",
187
+ "line_3": "",
188
+ "premise": "6",
189
+ "country": "England",
190
+ "county": "",
191
+ "district": "Hammersmith and Fulham",
192
+ "ward": "North End",
193
+ "longitude": -0.208644362766368,
194
+ "latitude": 51.4899488390558,
195
+ "eastings": 524466,
196
+ "northings": 178299
197
+ },
198
+ {
199
+ "postcode": "ID1 1QD",
200
+ "postcode_inward": "1QD",
201
+ "postcode_outward": "ID1",
202
+ "post_town": "LONDON",
203
+ "dependant_locality": "",
204
+ "double_dependant_locality": "",
205
+ "thoroughfare": "Barons Court Road",
206
+ "dependant_thoroughfare": "",
207
+ "building_number": "8",
208
+ "building_name": "",
209
+ "sub_building_name": "",
210
+ "po_box": "",
211
+ "department_name": "",
212
+ "organisation_name": "",
213
+ "udprn": 25962219,
214
+ "postcode_type": "S",
215
+ "su_organisation_indicator": "",
216
+ "delivery_point_suffix": "1Z",
217
+ "line_1": "8 Barons Court Road",
218
+ "line_2": "",
219
+ "line_3": "",
220
+ "premise": "8",
221
+ "country": "England",
222
+ "county": "",
223
+ "district": "Hammersmith and Fulham",
224
+ "ward": "North End",
225
+ "longitude": -0.208644362766368,
226
+ "latitude": 51.4899488390558,
227
+ "eastings": 524466,
228
+ "northings": 178299
229
+ },
230
+ {
231
+ "postcode": "ID1 1QD",
232
+ "postcode_inward": "1QD",
233
+ "postcode_outward": "ID1",
234
+ "post_town": "LONDON",
235
+ "dependant_locality": "",
236
+ "double_dependant_locality": "",
237
+ "thoroughfare": "Barons Court Road",
238
+ "dependant_thoroughfare": "",
239
+ "building_number": "59",
240
+ "building_name": "",
241
+ "sub_building_name": "",
242
+ "po_box": "",
243
+ "department_name": "",
244
+ "organisation_name": "ID Consulting Limited",
245
+ "udprn": 25946509,
246
+ "postcode_type": "S",
247
+ "su_organisation_indicator": "Y",
248
+ "delivery_point_suffix": "1N",
249
+ "line_1": "ID Consulting Limited",
250
+ "line_2": "59 Barons Court Road",
251
+ "line_3": "",
252
+ "premise": "59",
253
+ "country": "England",
254
+ "county": "",
255
+ "district": "Hammersmith and Fulham",
256
+ "ward": "North End",
257
+ "longitude": -0.208644362766368,
258
+ "latitude": 51.4899488390558,
259
+ "eastings": 524466,
260
+ "northings": 178299
261
+ }
262
+ ],
263
+ "code": 2000,
264
+ "message": "Success"
265
+ }
266
+ http_version:
267
+ recorded_at: Fri, 12 Dec 2014 17:40:27 GMT
268
+ 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/postcodes/ID1%201QD?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:27 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:27 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/postcodes/ID1%20CHOP?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:27 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:27 GMT
42
+ recorded_with: VCR 2.9.3