ideal_postcodes 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +3 -16
  3. data/LICENSE +1 -21
  4. data/README.md +13 -332
  5. data/lib/ideal_postcodes/base_client.rb +88 -0
  6. data/lib/ideal_postcodes/client.rb +42 -0
  7. data/lib/ideal_postcodes/errors.rb +59 -0
  8. data/lib/ideal_postcodes/generated.rb +83 -0
  9. data/lib/ideal_postcodes/model.rb +73 -0
  10. data/lib/ideal_postcodes/operations.rb +866 -0
  11. data/lib/ideal_postcodes/responses/address_response.rb +19 -0
  12. data/lib/ideal_postcodes/responses/api_key_details_response.rb +21 -0
  13. data/lib/ideal_postcodes/responses/api_key_response.rb +21 -0
  14. data/lib/ideal_postcodes/responses/api_key_usage_response.rb +21 -0
  15. data/lib/ideal_postcodes/responses/autocomplete_response.rb +19 -0
  16. data/lib/ideal_postcodes/responses/cleanse_response.rb +31 -0
  17. data/lib/ideal_postcodes/responses/config_response.rb +21 -0
  18. data/lib/ideal_postcodes/responses/configs_response.rb +21 -0
  19. data/lib/ideal_postcodes/responses/delete_config_response.rb +19 -0
  20. data/lib/ideal_postcodes/responses/delete_licensee_response.rb +19 -0
  21. data/lib/ideal_postcodes/responses/email_response.rb +31 -0
  22. data/lib/ideal_postcodes/responses/gbr_resolve_address_response.rb +21 -0
  23. data/lib/ideal_postcodes/responses/licensee_response.rb +21 -0
  24. data/lib/ideal_postcodes/responses/licensees_response.rb +21 -0
  25. data/lib/ideal_postcodes/responses/phone_number_response.rb +31 -0
  26. data/lib/ideal_postcodes/responses/place_response.rb +19 -0
  27. data/lib/ideal_postcodes/responses/postcode_response.rb +30 -0
  28. data/lib/ideal_postcodes/responses/resolve_place_response.rb +24 -0
  29. data/lib/ideal_postcodes/transport.rb +61 -0
  30. data/lib/ideal_postcodes/types/ab_address.rb +283 -0
  31. data/lib/ideal_postcodes/types/abp_address.rb +674 -0
  32. data/lib/ideal_postcodes/types/address.rb +290 -0
  33. data/lib/ideal_postcodes/types/address_list_item.rb +592 -0
  34. data/lib/ideal_postcodes/types/address_result.rb +24 -0
  35. data/lib/ideal_postcodes/types/address_suggestion.rb +27 -0
  36. data/lib/ideal_postcodes/types/api_key.rb +27 -0
  37. data/lib/ideal_postcodes/types/api_key_automated_topup.rb +17 -0
  38. data/lib/ideal_postcodes/types/api_key_current_purchase.rb +27 -0
  39. data/lib/ideal_postcodes/types/api_key_daily_limit.rb +21 -0
  40. data/lib/ideal_postcodes/types/api_key_datasets.rb +202 -0
  41. data/lib/ideal_postcodes/types/api_key_details.rb +90 -0
  42. data/lib/ideal_postcodes/types/api_key_individual_limit.rb +16 -0
  43. data/lib/ideal_postcodes/types/api_key_monthly_limit.rb +21 -0
  44. data/lib/ideal_postcodes/types/api_key_notifications.rb +35 -0
  45. data/lib/ideal_postcodes/types/autocomplete_result.rb +25 -0
  46. data/lib/ideal_postcodes/types/available_context.rb +35 -0
  47. data/lib/ideal_postcodes/types/ban_address.rb +179 -0
  48. data/lib/ideal_postcodes/types/bev_address.rb +288 -0
  49. data/lib/ideal_postcodes/types/cannar_address.rb +297 -0
  50. data/lib/ideal_postcodes/types/carrier.rb +31 -0
  51. data/lib/ideal_postcodes/types/config.rb +34 -0
  52. data/lib/ideal_postcodes/types/configs_result.rb +15 -0
  53. data/lib/ideal_postcodes/types/deleted_config.rb +13 -0
  54. data/lib/ideal_postcodes/types/deleted_licensee.rb +13 -0
  55. data/lib/ideal_postcodes/types/ecad_address.rb +393 -0
  56. data/lib/ideal_postcodes/types/ecaf_address.rb +204 -0
  57. data/lib/ideal_postcodes/types/email.rb +45 -0
  58. data/lib/ideal_postcodes/types/fodbosa_address.rb +201 -0
  59. data/lib/ideal_postcodes/types/gbr_cleanse_match.rb +70 -0
  60. data/lib/ideal_postcodes/types/gbr_cleanse_no_match.rb +47 -0
  61. data/lib/ideal_postcodes/types/geonames_place.rb +153 -0
  62. data/lib/ideal_postcodes/types/gnaf_address.rb +463 -0
  63. data/lib/ideal_postcodes/types/here_address.rb +174 -0
  64. data/lib/ideal_postcodes/types/invalid_phone_number.rb +50 -0
  65. data/lib/ideal_postcodes/types/kadaster_address.rb +480 -0
  66. data/lib/ideal_postcodes/types/kartverket_address.rb +342 -0
  67. data/lib/ideal_postcodes/types/key_usage_day.rb +16 -0
  68. data/lib/ideal_postcodes/types/key_usage_result.rb +36 -0
  69. data/lib/ideal_postcodes/types/licensee.rb +50 -0
  70. data/lib/ideal_postcodes/types/licensee_daily_usage.rb +29 -0
  71. data/lib/ideal_postcodes/types/licensees_result.rb +23 -0
  72. data/lib/ideal_postcodes/types/mois_address.rb +440 -0
  73. data/lib/ideal_postcodes/types/mr_address.rb +99 -0
  74. data/lib/ideal_postcodes/types/native_record.rb +368 -0
  75. data/lib/ideal_postcodes/types/nyb_address.rb +99 -0
  76. data/lib/ideal_postcodes/types/paf_address.rb +96 -0
  77. data/lib/ideal_postcodes/types/pafa_address.rb +104 -0
  78. data/lib/ideal_postcodes/types/pafw_address.rb +99 -0
  79. data/lib/ideal_postcodes/types/phone_number.rb +50 -0
  80. data/lib/ideal_postcodes/types/place.rb +79 -0
  81. data/lib/ideal_postcodes/types/place_result.rb +21 -0
  82. data/lib/ideal_postcodes/types/place_suggestion.rb +32 -0
  83. data/lib/ideal_postcodes/types/sdfi_address.rb +520 -0
  84. data/lib/ideal_postcodes/types/swt_address.rb +247 -0
  85. data/lib/ideal_postcodes/types/uk_address_suggestion.rb +45 -0
  86. data/lib/ideal_postcodes/types/uk_address_suggestion_urls.rb +21 -0
  87. data/lib/ideal_postcodes/types/unknown_email.rb +43 -0
  88. data/lib/ideal_postcodes/types/upujp_address.rb +763 -0
  89. data/lib/ideal_postcodes/types/usps_address.rb +294 -0
  90. data/lib/ideal_postcodes/version.rb +5 -0
  91. data/lib/ideal_postcodes.rb +14 -2
  92. data/sig/ideal_postcodes/base_client.rbs +40 -0
  93. data/sig/ideal_postcodes/client.rbs +35 -0
  94. data/sig/ideal_postcodes/errors.rbs +27 -0
  95. data/sig/ideal_postcodes/model.rbs +37 -0
  96. data/sig/ideal_postcodes/operations.rbs +207 -0
  97. data/sig/ideal_postcodes/responses/address_response.rbs +13 -0
  98. data/sig/ideal_postcodes/responses/api_key_details_response.rbs +13 -0
  99. data/sig/ideal_postcodes/responses/api_key_response.rbs +13 -0
  100. data/sig/ideal_postcodes/responses/api_key_usage_response.rbs +13 -0
  101. data/sig/ideal_postcodes/responses/autocomplete_response.rbs +13 -0
  102. data/sig/ideal_postcodes/responses/cleanse_response.rbs +19 -0
  103. data/sig/ideal_postcodes/responses/config_response.rbs +13 -0
  104. data/sig/ideal_postcodes/responses/configs_response.rbs +13 -0
  105. data/sig/ideal_postcodes/responses/delete_config_response.rbs +13 -0
  106. data/sig/ideal_postcodes/responses/delete_licensee_response.rbs +13 -0
  107. data/sig/ideal_postcodes/responses/email_response.rbs +19 -0
  108. data/sig/ideal_postcodes/responses/gbr_resolve_address_response.rbs +13 -0
  109. data/sig/ideal_postcodes/responses/licensee_response.rbs +13 -0
  110. data/sig/ideal_postcodes/responses/licensees_response.rbs +13 -0
  111. data/sig/ideal_postcodes/responses/phone_number_response.rbs +19 -0
  112. data/sig/ideal_postcodes/responses/place_response.rbs +13 -0
  113. data/sig/ideal_postcodes/responses/postcode_response.rbs +16 -0
  114. data/sig/ideal_postcodes/responses/resolve_place_response.rbs +13 -0
  115. data/sig/ideal_postcodes/transport.rbs +39 -0
  116. data/sig/ideal_postcodes/types/ab_address.rbs +57 -0
  117. data/sig/ideal_postcodes/types/abp_address.rbs +126 -0
  118. data/sig/ideal_postcodes/types/address.rbs +136 -0
  119. data/sig/ideal_postcodes/types/address_list_item.rbs +160 -0
  120. data/sig/ideal_postcodes/types/address_result.rbs +12 -0
  121. data/sig/ideal_postcodes/types/address_suggestion.rbs +11 -0
  122. data/sig/ideal_postcodes/types/api_key.rbs +11 -0
  123. data/sig/ideal_postcodes/types/api_key_automated_topup.rbs +9 -0
  124. data/sig/ideal_postcodes/types/api_key_current_purchase.rbs +11 -0
  125. data/sig/ideal_postcodes/types/api_key_daily_limit.rbs +10 -0
  126. data/sig/ideal_postcodes/types/api_key_datasets.rbs +46 -0
  127. data/sig/ideal_postcodes/types/api_key_details.rbs +22 -0
  128. data/sig/ideal_postcodes/types/api_key_individual_limit.rbs +9 -0
  129. data/sig/ideal_postcodes/types/api_key_monthly_limit.rbs +10 -0
  130. data/sig/ideal_postcodes/types/api_key_notifications.rbs +13 -0
  131. data/sig/ideal_postcodes/types/autocomplete_result.rbs +15 -0
  132. data/sig/ideal_postcodes/types/available_context.rbs +13 -0
  133. data/sig/ideal_postcodes/types/ban_address.rbs +46 -0
  134. data/sig/ideal_postcodes/types/bev_address.rbs +67 -0
  135. data/sig/ideal_postcodes/types/cannar_address.rbs +62 -0
  136. data/sig/ideal_postcodes/types/carrier.rbs +14 -0
  137. data/sig/ideal_postcodes/types/config.rbs +14 -0
  138. data/sig/ideal_postcodes/types/configs_result.rbs +9 -0
  139. data/sig/ideal_postcodes/types/deleted_config.rbs +9 -0
  140. data/sig/ideal_postcodes/types/deleted_licensee.rbs +9 -0
  141. data/sig/ideal_postcodes/types/ecad_address.rbs +84 -0
  142. data/sig/ideal_postcodes/types/ecaf_address.rbs +45 -0
  143. data/sig/ideal_postcodes/types/email.rbs +16 -0
  144. data/sig/ideal_postcodes/types/fodbosa_address.rbs +43 -0
  145. data/sig/ideal_postcodes/types/gbr_cleanse_match.rbs +25 -0
  146. data/sig/ideal_postcodes/types/gbr_cleanse_no_match.rbs +28 -0
  147. data/sig/ideal_postcodes/types/geonames_place.rbs +42 -0
  148. data/sig/ideal_postcodes/types/gnaf_address.rbs +104 -0
  149. data/sig/ideal_postcodes/types/here_address.rbs +37 -0
  150. data/sig/ideal_postcodes/types/invalid_phone_number.rbs +17 -0
  151. data/sig/ideal_postcodes/types/kadaster_address.rbs +98 -0
  152. data/sig/ideal_postcodes/types/kartverket_address.rbs +78 -0
  153. data/sig/ideal_postcodes/types/key_usage_day.rbs +10 -0
  154. data/sig/ideal_postcodes/types/key_usage_result.rbs +13 -0
  155. data/sig/ideal_postcodes/types/licensee.rbs +17 -0
  156. data/sig/ideal_postcodes/types/licensee_daily_usage.rbs +12 -0
  157. data/sig/ideal_postcodes/types/licensees_result.rbs +11 -0
  158. data/sig/ideal_postcodes/types/mois_address.rbs +97 -0
  159. data/sig/ideal_postcodes/types/mr_address.rbs +27 -0
  160. data/sig/ideal_postcodes/types/native_record.rbs +34 -0
  161. data/sig/ideal_postcodes/types/nyb_address.rbs +27 -0
  162. data/sig/ideal_postcodes/types/paf_address.rbs +27 -0
  163. data/sig/ideal_postcodes/types/pafa_address.rbs +27 -0
  164. data/sig/ideal_postcodes/types/pafw_address.rbs +27 -0
  165. data/sig/ideal_postcodes/types/phone_number.rbs +17 -0
  166. data/sig/ideal_postcodes/types/place.rbs +29 -0
  167. data/sig/ideal_postcodes/types/place_result.rbs +15 -0
  168. data/sig/ideal_postcodes/types/place_suggestion.rbs +12 -0
  169. data/sig/ideal_postcodes/types/sdfi_address.rbs +108 -0
  170. data/sig/ideal_postcodes/types/swt_address.rbs +57 -0
  171. data/sig/ideal_postcodes/types/uk_address_suggestion.rbs +13 -0
  172. data/sig/ideal_postcodes/types/uk_address_suggestion_urls.rbs +10 -0
  173. data/sig/ideal_postcodes/types/unknown_email.rbs +16 -0
  174. data/sig/ideal_postcodes/types/upujp_address.rbs +156 -0
  175. data/sig/ideal_postcodes/types/usps_address.rbs +63 -0
  176. metadata +186 -175
  177. data/.travis.yml +0 -9
  178. data/Gemfile +0 -2
  179. data/Rakefile +0 -15
  180. data/ideal-postcodes-ruby.gemspec +0 -25
  181. data/lib/idealpostcodes/address.rb +0 -31
  182. data/lib/idealpostcodes/errors.rb +0 -33
  183. data/lib/idealpostcodes/key.rb +0 -13
  184. data/lib/idealpostcodes/postcode.rb +0 -22
  185. data/lib/idealpostcodes/util.rb +0 -29
  186. data/lib/idealpostcodes/version.rb +0 -3
  187. data/lib/idealpostcodes.rb +0 -112
  188. data/spec/addresses_spec.rb +0 -68
  189. data/spec/idealpostcodes_spec.rb +0 -56
  190. data/spec/keys_spec.rb +0 -25
  191. data/spec/postcodes_spec.rb +0 -66
  192. data/spec/spec_helper.rb +0 -68
  193. data/spec/vcr_cassettes/IdealPostcodes_Address_lookup_raises_an_exception_if_invalid_key.yml +0 -42
  194. data/spec/vcr_cassettes/IdealPostcodes_Address_lookup_raises_an_exception_if_limit_breached.yml +0 -42
  195. data/spec/vcr_cassettes/IdealPostcodes_Address_lookup_raises_an_exception_if_no_lookups_remaining.yml +0 -42
  196. data/spec/vcr_cassettes/IdealPostcodes_Address_lookup_returns_an_address_for_a_valid_UDPRN.yml +0 -74
  197. data/spec/vcr_cassettes/IdealPostcodes_Address_lookup_returns_nil_for_an_invalid_UDPRN.yml +0 -42
  198. data/spec/vcr_cassettes/IdealPostcodes_Address_search_is_sensitive_to_limit.yml +0 -81
  199. data/spec/vcr_cassettes/IdealPostcodes_Address_search_is_sensitive_to_page.yml +0 -369
  200. data/spec/vcr_cassettes/IdealPostcodes_Address_search_raises_an_exception_if_invalid_key.yml +0 -42
  201. data/spec/vcr_cassettes/IdealPostcodes_Address_search_raises_an_exception_if_limit_breached.yml +0 -42
  202. data/spec/vcr_cassettes/IdealPostcodes_Address_search_raises_an_exception_if_no_lookups_remaining.yml +0 -42
  203. data/spec/vcr_cassettes/IdealPostcodes_Address_search_returns_results_in_a_SearchResult_object.yml +0 -273
  204. data/spec/vcr_cassettes/IdealPostcodes_Key_lookup_details_returns_key_details.yml +0 -62
  205. data/spec/vcr_cassettes/IdealPostcodes_Key_lookup_returns_the_availability_status_of_a_key_false_key_.yml +0 -45
  206. data/spec/vcr_cassettes/IdealPostcodes_Key_lookup_returns_the_availability_status_of_a_key_true_key_.yml +0 -45
  207. data/spec/vcr_cassettes/IdealPostcodes_Postcode_find_by_location_is_sensitive_to_limit_parameter.yml +0 -52
  208. data/spec/vcr_cassettes/IdealPostcodes_Postcode_find_by_location_is_sensitive_to_radius_parament.yml +0 -133
  209. data/spec/vcr_cassettes/IdealPostcodes_Postcode_find_by_location_returns_an_array_of_postcodes_and_locations.yml +0 -84
  210. data/spec/vcr_cassettes/IdealPostcodes_Postcode_find_by_location_returns_an_empty_array_if_no_results_are_found.yml +0 -43
  211. data/spec/vcr_cassettes/IdealPostcodes_Postcode_lookup_raises_an_exception_if_invalid_key.yml +0 -42
  212. data/spec/vcr_cassettes/IdealPostcodes_Postcode_lookup_raises_an_exception_if_key_has_run_out_of_balance.yml +0 -42
  213. data/spec/vcr_cassettes/IdealPostcodes_Postcode_lookup_raises_an_exception_if_limit_has_been_reached.yml +0 -42
  214. data/spec/vcr_cassettes/IdealPostcodes_Postcode_lookup_returns_a_list_of_addresses_for_a_postcode.yml +0 -268
  215. data/spec/vcr_cassettes/IdealPostcodes_Postcode_lookup_returns_an_empty_array_if_postcode_does_not_exist.yml +0 -42
  216. data/spec/vcr_cassettes/IdealPostcodes_key_available_returns_false_if_key_is_unavailable.yml +0 -45
  217. data/spec/vcr_cassettes/IdealPostcodes_key_available_returns_true_if_key_is_available.yml +0 -45
  218. data/spec/vcr_cassettes/IdealPostcodes_key_details_raises_an_exception_if_no_secret_is_provided.yml +0 -45
  219. data/spec/vcr_cassettes/IdealPostcodes_key_details_returns_key_information.yml +0 -62
  220. data/spec/vcr_cassettes/IdealPostcodes_request_generates_a_HTTP_request.yml +0 -268
  221. data/spec/vcr_cassettes/IdealPostcodes_request_raises_authentication_error_if_invalid_key_is_provided.yml +0 -42
  222. data/spec/vcr_cassettes/IdealPostcodes_request_raises_limit_reached_error_if_a_limit_has_been_breached.yml +0 -42
  223. data/spec/vcr_cassettes/IdealPostcodes_request_raises_token_exhausted_error_if_key_balance_is_depleted.yml +0 -42
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ced7ca1b0bfedf6e6e3de16898062cc335927ed5
4
- data.tar.gz: a59fe3d7b1cc4797842872997a7128ee1e2399e3
2
+ SHA256:
3
+ metadata.gz: 35942296eddb610d4177a5e29b634595be1ae8ac189531d16c73038880b198f4
4
+ data.tar.gz: e9134bf40e399cf0c86194ac113af3ed1d31665a374a403995553032af8470c3
5
5
  SHA512:
6
- metadata.gz: 79892c818f0d4319a12ec35ef81aca5aee11d5478742989bfe0f87fc4f77e1567c4efbd08d254663984a5aee15ba4ee15a79fffe91c3e4d34f413951ec42ba04
7
- data.tar.gz: 471e2ac36ad0eb8c662a641e11d5d7d23b5e77c0952901b18611ee01ae54d26717c86b198d63635d48451a5deca67e34a61379d31643f303404bfba84079795f
6
+ metadata.gz: 8391bb41c0e558947fcc063a73533de7f05d0da74fc27e7572f32ce26947577a79d46052a77bcf129b87d9b9130eff77690e6e799486f22d893005e1d986470c
7
+ data.tar.gz: 33fe23e1e4d5923bc1893f7ad9f5ac5d4389f855d42cd05dcdda66127d211b9e2fcd24019dce7f9b32b2c4ad3baa280d5650b2d2b2b787d17d082e9a6b29d9e4
data/CHANGELOG.md CHANGED
@@ -1,20 +1,7 @@
1
1
  # Changelog
2
2
 
3
- Any changes, including backwards incompatible changes will be listed here
3
+ ## 3.0.0 (2026-11-26)
4
4
 
5
- ## 2.0.0 (11/10/2017)
5
+ ### Features
6
6
 
7
- - Adds Ruby 2.4.0 support
8
- - Drops 1.9 support
9
-
10
- ## 1.1.0 (22/6/2017)
11
-
12
- - Updated rest-client dependency
13
-
14
- ## 1.0.0
15
- - Major rewrite to make way for more resources
16
- - Breaking change applied to postcode lookup functionality
17
- - Implemented [addresses resource](https://ideal-postcodes.co.uk/documentation/addresses)
18
- - Implemented [keys resource](https://ideal-postcodes.co.uk/documentation/keys)
19
- - Implemented [postcodes resource](https://ideal-postcodes.co.uk/documentation/postcodes). Added location-based postcode searches
20
- - Swapped out test suite with rspec and vcr
7
+ * Add the Ruby SDK
data/LICENSE CHANGED
@@ -1,21 +1 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2016 Ideal Postcodes
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ Copyright (C) IDDQD Limited - All Rights Reserved
data/README.md CHANGED
@@ -1,350 +1,31 @@
1
- # Ideal Postcodes Ruby Library [![Build Status](https://travis-ci.org/ideal-postcodes/ideal-postcodes-ruby.png)](https://travis-ci.org/ideal-postcodes/ideal-postcodes-ruby)
1
+ # Ideal Postcodes Ruby SDK
2
2
 
3
- Ideal Postcodes is a simple JSON API to query UK postcodes and addresses. Find out more at [Ideal-Postcodes.co.uk](https://ideal-postcodes.co.uk/)
4
-
5
- Our API uses Royal Mail's Postcode Address File and is updated daily. Each method incurs a small charge (typically 2p) - free methods are labelled as such and are based on open data sources.
6
-
7
- ## Getting Started
8
-
9
- **Install**
3
+ Calls to the Ideal Postcodes API from Ruby 3.3 or later, with no runtime dependencies.
10
4
 
11
5
  ```bash
12
6
  gem install ideal_postcodes
13
7
  ```
14
8
 
15
- Alternatively, include this in your gemfile and bundle install
16
-
17
9
  ```ruby
18
- gem 'ideal_postcodes'
19
- ```
10
+ require "ideal_postcodes"
20
11
 
21
- **Create a Key**
12
+ client = IdealPostcodes::Client.new(api_key: "ak_test")
22
13
 
23
- Sign up at [Ideal-Postcodes.co.uk](https://ideal-postcodes.co.uk) and create a key.
24
-
25
- **Configure**
26
-
27
- Drop in your key when using the library.
28
-
29
- ```ruby
30
- IdealPostcodes.api_key = "your_key_goes_here"
31
- ```
32
-
33
- ## Error Handling
34
-
35
- It's important that you lookout for common exceptions when interacting with the API. The most common exceptions can be caught as shown below.
36
-
37
- ```ruby
38
- begin
39
- IdealPostcodes::Postcode.lookup "ID1 1QD"
40
- rescue IdealPostcodes::AuthenticationError => e
41
- # Invalid API Key
42
- rescue IdealPostcodes::TokenExhaustedError => e
43
- # Token has run out of lookups
44
- rescue IdealPostcodes::LimitReachedError => e
45
- # One of your predefinied limits has been reached
46
- rescue IdealPostcodes::IdealPostcodesError => e
47
- # API Error
48
- rescue => e
49
- # An unexpected error
14
+ lookup = client.lookup("BR8 7RE")
15
+ lookup.addresses.each do |address|
16
+ puts "#{address.line_1}, #{address.post_town}, #{address.postcode}"
50
17
  end
51
- ```
52
-
53
- Possible errors to look out for are listed in the [documentation](https://ideal-postcodes.co.uk/documentation/response-codes).
54
-
55
- ## Methods
56
-
57
- The client provides a number of methods to allow you to get specific jobs done quickly and easily. These methods are listed below.
58
-
59
-
60
-
61
-
62
- ## Get all addresses for a postcode [(docs)](https://ideal-postcodes.co.uk/documentation/postcodes#postcode)
63
-
64
- ```
65
- IdealPostcodes::Postcode.lookup postcode
66
- ```
67
-
68
- Returns an array of addresses representing all addresses at the specified postcode.
69
-
70
- **Arguments**
71
-
72
- - `postcode` (string). The postcode you want to lookup, case and space insensitive.
73
-
74
- **Returns**
75
-
76
- An array of hashes which represent each address at the postcode. Returns an empty array for an invalid postcode.
77
-
78
- **Example**
79
-
80
- ```ruby
81
- addresses = IdealPostcodes::Postcode.lookup "ID1 1QD"
82
-
83
- if addresses.empty?
84
- puts "Your postcode doesn't have a match"
85
- else
86
- puts addresses
87
- end
88
-
89
- # addresses =>
90
- #[
91
- # {
92
- # :postcode => "ID1 1QD",
93
- # :post_town => "LONDON",
94
- # :line_1 => "Kingsley Hall",
95
- # :line_2 => "Powis Road",
96
- # :line_3 => "",
97
- # :organisation_name => "",
98
- # :building_name => "Kingsley Hall",
99
- # :udprn => 12345678
100
- # ... and so on
101
- ```
102
-
103
- **Notes**
104
-
105
- **Data Source:** Royal Mail Postcode Address File. Ordnance Survey.
106
-
107
- Use the postcode "ID1 1QD" to test this method for free. The complete list of test postcodes is available in the [documentation](https://ideal-postcodes/documentation/postcodes).
108
-
109
-
110
-
111
-
112
- ## Search for an address [(docs)](https://ideal-postcodes.co.uk/documentation/addresses#query)
113
-
114
- Perform a search for addresses which match your search term.
115
-
116
- ```ruby
117
- IdealPostcodes::Address.search search_term, limit: 20, page: 0
118
- ```
119
-
120
- **Arguments**
121
-
122
- - `search_term` (string). The address you wish to search for
123
- - `options` (hash, optional). Customise your search.
124
- - `limit` (number). The maximum number of returned results per page
125
- - `page` (number). Page of results to return (starts at page 0)
126
-
127
- **Returns**
128
-
129
- Returns a search result object with the following attributes.
130
-
131
- - `addresses` (Array). An array of hashes which represent each address at the postcode. The array is ordered by how close the search term and address match.
132
- - `limit` (Number). The maximum number of returned results per page.
133
- - `page` (Number). The returned page of results.
134
-
135
-
136
- **Example**
137
-
138
- ```ruby
139
- IdealPostcodes::Address.search "10 Downing Street London"
140
-
141
- r.limit # => 10
142
- r.page # => 0
143
- r.addresses
144
-
145
- #[
146
- # {
147
- # :line_1=>"Prime Minister & First Lord Of The Treasury",
148
- # :line_2=>"10 Downing Street",
149
- # :line_3=>"",
150
- # :post_town=>"LONDON",
151
- # :postcode=>"SW1A 2AA",
152
- # :organisation_name=>"Prime Minister & First Lord Of The Treasury",
153
- # :premise=>"10",
154
- # :latitude=>51.5035398826274
155
- # :longitude=>-0.127695242183412,
156
- # :thoroughfare=>"Downing Street",
157
- # :district=>"Westminster",
158
- # :ward=>"St James's",
159
- # :building_number=>"10",
160
- # :udprn=>23747771,
161
- # ... and so on
162
- ```
163
-
164
- **Notes**
165
-
166
- Data source: Royal Mail Postcode Address File, Ordnance Survey.
167
-
168
- Use the address "ID1 1QD" to test integration for free. The complete list of test methods is available in the [documentation](https://ideal-postcodes/documentation/addresses).
169
-
170
-
171
-
172
-
173
- ## Get nearby postcode for a given geolocation [(docs)](https://ideal-postcodes.co.uk/documentation/postcodes#lonlat)
174
18
 
175
- Retrieve the nearest postcodes for a given geolocation. Free to use.
176
-
177
- ```ruby
178
- IdealPostcodes::Postcode.find_by_location longitude: lon, latitude: lat
179
- ```
180
-
181
- **Arguments**
182
-
183
- - `location` (Hash)
184
- - `longitude` (number, required)
185
- - `latitude` (number, required)
186
- - `limit` (number, optional) Maximum number of results to return
187
- - `radius` (number, optional) search radius (in metres)
188
-
189
- **Returns**
190
-
191
- An array of hashes which represent the nearest postcodes to the specified location. Ordered by distance from location.
192
-
193
- **Example**
194
-
195
- ```ruby
196
- postcodes = IdealPostcodes::Postcode.find_by_location longitude: 0.629834, latitude: 51.79232
197
-
198
- # postcodes =>
199
- #[
200
- # {
201
- # :postcode=>"CM8 1EF",
202
- # :northings=>213679,
203
- # :eastings=>581461,
204
- # :longitude=>0.629834723775309,
205
- # :latitude=>51.7923246977375,
206
- # :distance=>0.52506633},
207
- # {
208
- # :postcode=>"CM8 1EU",
209
- # :northings=>213650,
210
- # :eastings=>581507,
211
- # :longitude=>0.630485817275861,
212
- # :latitude=>51.7920493205979,
213
- # :distance=>54.12525282
214
- # },
215
- ```
216
-
217
- **Notes**
218
-
219
- Data source: Ordnance Survey. Free to use.
220
-
221
-
222
-
223
- ## Retrieve an address using UDPRN [(docs)](https://ideal-postcodes.co.uk/documentation/addresses#address)
224
-
225
- Retrieve the specific address for a specific UDPRN.
226
-
227
- ```ruby
228
- IdealPostcodes::Address.lookup udprn
19
+ response = client.find_address(query: "9 Malyons Road")
20
+ response.result.hits.each { |hit| puts hit.suggestion }
229
21
  ```
230
22
 
231
- **Arguments**
232
-
233
- - `udprn` (string | number). A number which uniquely identifies the address.
234
-
235
- **Returns**
236
-
237
- Returns a hash representing the matching address. Returns `nil` if no matching address is found.
238
-
239
- **Example**
240
-
241
- ```ruby
242
- IdealPostcodes::Address.lookup 23747771
243
-
244
- #{
245
- # :line_1=>"Prime Minister & First Lord Of The Treasury",
246
- # :line_2=>"10 Downing Street",
247
- # :line_3=>"",
248
- # :post_town=>"LONDON",
249
- # :postcode=>"SW1A 2AA",
250
- # :organisation_name=>"Prime Minister & First Lord Of The Treasury",
251
- # :premise=>"10",
252
- # :latitude=>51.5035398826274
253
- # :longitude=>-0.127695242183412,
254
- # :thoroughfare=>"Downing Street",
255
- # :district=>"Westminster",
256
- # :ward=>"St James's",
257
- # :building_number=>"10",
258
- # :udprn=>23747771,
259
- # ... and so on
260
- ```
261
-
262
- **Notes**
263
-
264
- Data source: Royal Mail Postcode Address File, Ordnance Survey.
265
-
266
- Use the address `0` to test integration for free. The complete list of test methods is available in the [documentation](https://ideal-postcodes/documentation/addresses).
267
-
268
- ## Utility Methods
269
-
270
- Listed below are free utility methods, e.g. finding the status of your key.
271
-
272
- ### Find out if your key is in a usable state [(docs)](https://ideal-postcodes.co.uk/documentation/keys#key)
23
+ Each API operation is one method on the client, named from its operation ID, such as `postcodes`, `address_cleanse` or `key_usage`. Path parameters are positional and everything else is a keyword argument. Every response is an object with one reader per field under the API's own name, `[]` for any key and `to_h` for the decoded body, unknown fields included. An HTTP error raises `IdealPostcodes::ApiError`, with the HTTP status in `status` and the API error code in `code`.
273
24
 
274
- Find out if your key is in a usable state. E.g. it has a positive balance, it is currently under your defined usage limits, etc.
25
+ Key, licensee and configuration operations need your Management Key: pass `management_key:` to `Client.new`. Keep it on your server.
275
26
 
276
- ```
277
- IdealPostcodes.key_available
278
- ```
279
-
280
- **Arguments**
281
-
282
- None.
283
-
284
- **Returns**
285
-
286
- - availability (Boolean). Returns true if key can be used. False if something is preventing the key from making lookups e.g. insufficient balance, reached limits, etc.
287
-
288
- **Example**
289
-
290
- ```ruby
291
- IdealPostcodes.key_available # => true, you're clear to make lookups
292
- ```
293
-
294
- ### Retrieve private key information [(docs)](https://ideal-postcodes.co.uk/documentation/keys#details)
295
-
296
- This method reveals private information about your key such as the lookup balance, whitelisted URLs, etc. Note: a secret key is required to invoke this method.
297
-
298
- ```
299
- IdealPostcodes.key_details
300
- ```
301
-
302
- **Arguments**
303
-
304
- None.
305
-
306
- **Returns**
307
-
308
- Returns a hash containing pertinent private information about your key.
309
-
310
- **Example**
311
-
312
- ```ruby
313
- IdealPostcodes.key_details
314
-
315
- # {
316
- # :lookups_remaining=>9678,
317
- # :daily_limit=>{
318
- # :limit=>100,
319
- # :consumed=>1
320
- # },
321
- # :individual_limit=>{
322
- # :limit=>15
323
- # },
324
- # :allowed_urls=>["foo.com"],
325
- # :notifications=>{
326
- # :emails=>["bar@baz.com"],
327
- # :enabled=>true},
328
- # :automated_topups=>{
329
- # :enabled=>true
330
- # }
331
- # }
332
- ```
333
-
334
- If you intend to use this method, you must pass your secret key (which can be found on your [account page](https://ideal-postcodes.co.uk/account)) along with your API key when instantiating the client. E.g.
335
-
336
- ```ruby
337
- IdealPostcodes.apply_secret "your secret key"
338
- ```
339
-
340
- Do not share your secret key and avoid commiting this key to your codebase.
341
-
342
- ## Testing
343
-
344
- ```
345
- bundle exec rake
346
- ```
27
+ [Documentation](https://docs.ideal-postcodes.co.uk/docs/sdks/ruby) covers setup, postcode and UPRN lookup, autocomplete, address cleanse, email and phone validation, keys, licensees, responses, errors and a reference page for every operation. Coding agents can install the `ideal-postcodes-ruby-sdk` skill with `npx skills add ideal-postcodes/skills`.
347
28
 
348
29
  ## License
349
30
 
350
- MIT
31
+ SEE LICENSE IN LICENSE
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IdealPostcodes
4
+ # Construction, credentials and the request every generated operation makes. Client
5
+ # subclasses it and includes Operations.
6
+ class BaseClient
7
+ DEFAULT_BASE_URL = "https://api.ideal-postcodes.co.uk/v1"
8
+
9
+ # @param api_key [String] the API Key, for lookups
10
+ # @param management_key [String, nil] the Management Key, for key and licensee administration
11
+ # @param base_url [String]
12
+ # @param timeout [Numeric] seconds allowed to connect, and again for each read and write
13
+ # @param user_agent [String, nil] your application's identifier, sent before the SDK's own
14
+ # @param transport [#call, nil] replaces Net::HTTP: takes a Request, returns a Response
15
+ def initialize(api_key:, management_key: nil, base_url: DEFAULT_BASE_URL, timeout: 30,
16
+ user_agent: nil, transport: nil)
17
+ @api_key = api_key
18
+ @management_key = management_key
19
+ @base_url = base_url.delete_suffix("/")
20
+ @user_agent = [user_agent&.strip, "ideal-postcodes-ruby-sdk/#{VERSION} ruby/#{RUBY_VERSION}"]
21
+ .reject { |part| part.nil? || part.empty? }.join(" ")
22
+ @transport = transport || HttpTransport.new(timeout: timeout)
23
+ end
24
+
25
+ def inspect
26
+ "#<#{self.class.name} #{@base_url}>"
27
+ end
28
+
29
+ private
30
+
31
+ # A JSON operation returns response.from_hash of the body; a CSV one the text.
32
+ def request(method, template, auth, path: {}, query: {}, body: nil, response: nil)
33
+ headers = request_headers(auth, response)
34
+ payload = nil
35
+ unless body.nil?
36
+ headers["Content-Type"] = "application/json"
37
+ payload = JSON.generate(body.compact)
38
+ end
39
+ result = @transport.call(Request.new(http_method: method, url: url(template, path, query),
40
+ headers: headers, body: payload))
41
+ raise ApiError.from_response(result) if result.status >= 400
42
+
43
+ response ? response.from_hash(decode(result)) : result.body
44
+ end
45
+
46
+ def request_headers(auth, response)
47
+ headers = {
48
+ "Accept" => response ? "application/json" : "text/csv",
49
+ "User-Agent" => @user_agent
50
+ }
51
+ token = credential(auth)
52
+ headers["Authorization"] = "Bearer #{token}" if token
53
+ headers
54
+ end
55
+
56
+ def credential(auth)
57
+ case auth
58
+ when :api_key then @api_key
59
+ when :management_key then @management_key || raise(MissingManagementKeyError)
60
+ end
61
+ end
62
+
63
+ def url(template, path, query)
64
+ url = @base_url + template.gsub(/\{([^}]+)\}/) { escape(path.fetch(Regexp.last_match(1))) }
65
+ pairs = query.filter_map { |name, value| [name, query_value(value)] unless value.nil? }
66
+ pairs.empty? ? url : "#{url}?#{URI.encode_www_form(pairs)}"
67
+ end
68
+
69
+ # An array is sent comma-joined, the form the API reads.
70
+ def query_value(value)
71
+ value.is_a?(Array) ? value.join(",") : value.to_s
72
+ end
73
+
74
+ # Percent-encodes everything but RFC 3986 unreserved characters.
75
+ def escape(value)
76
+ value.to_s.b.gsub(/[^A-Za-z0-9\-._~]/) { |c| format("%%%02X", c.ord) }
77
+ end
78
+
79
+ def decode(result)
80
+ decoded = JSON.parse(result.body, freeze: true)
81
+ raise UnserializableResponseError, result unless decoded.is_a?(Hash)
82
+
83
+ decoded
84
+ rescue JSON::ParserError
85
+ raise UnserializableResponseError, result
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IdealPostcodes
4
+ # The Ideal Postcodes API client: one method per operation (Operations), plus lookup.
5
+ #
6
+ # @example
7
+ # client = IdealPostcodes::Client.new(api_key: "ak_test")
8
+ # client.postcodes("BR8 7RE").result.first.line_1
9
+ class Client < BaseClient
10
+ include Operations
11
+
12
+ # The result of #lookup. found is false for an unknown postcode, with the API's
13
+ # closest matching postcodes in suggestions.
14
+ PostcodeLookup = Data.define(:found, :addresses, :suggestions, :total) do
15
+ alias_method :found?, :found
16
+ end
17
+
18
+ # The addresses at a postcode. An unknown postcode returns no addresses and the
19
+ # API's suggestions instead of raising; other errors still raise.
20
+ #
21
+ # @param postcode [String]
22
+ # @param ** keyword arguments for #postcodes, such as filter: or page:
23
+ # @return [PostcodeLookup]
24
+ # @see https://docs.ideal-postcodes.co.uk/docs/sdks/ruby/postcode-lookup
25
+ def lookup(postcode, **)
26
+ response = postcodes(postcode, **)
27
+ PostcodeLookup.new(found: true, addresses: response.result, suggestions: [],
28
+ total: response.total)
29
+ rescue ApiError => e
30
+ raise unless e.code == 4040
31
+
32
+ PostcodeLookup.new(found: false, addresses: [], suggestions: suggestions(e.body), total: 0)
33
+ end
34
+
35
+ private
36
+
37
+ def suggestions(body)
38
+ list = body.is_a?(Hash) ? body["suggestions"] : nil
39
+ list.is_a?(Array) ? list.grep(String) : []
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IdealPostcodes
4
+ # The base of every error the SDK raises.
5
+ class Error < StandardError; end
6
+
7
+ # The API answered with an error status. code and message come from the
8
+ # response body when it has them.
9
+ class ApiError < Error
10
+ # @return [Integer] the HTTP status
11
+ attr_reader :status
12
+ # @return [Integer, nil] the API's own error code, such as 4040
13
+ attr_reader :code
14
+ # @return [Hash{String => Object}, String] the decoded body, or the raw text when it is not JSON
15
+ attr_reader :body
16
+
17
+ # @param response [Response]
18
+ # @return [ApiError]
19
+ def self.from_response(response)
20
+ body = begin
21
+ decoded = JSON.parse(response.body)
22
+ decoded.is_a?(Hash) ? decoded : response.body
23
+ rescue JSON::ParserError
24
+ response.body
25
+ end
26
+ new(response.status, body)
27
+ end
28
+
29
+ def initialize(status, body)
30
+ @status = status
31
+ @body = body
32
+ fields = body.is_a?(Hash) ? body : {}
33
+ @code = fields["code"].is_a?(Integer) ? fields["code"] : nil
34
+ message = fields["message"]
35
+ super(message.is_a?(String) && !message.empty? ? message : "HTTP #{status}")
36
+ end
37
+ end
38
+
39
+ # The request never got an answer: DNS, connection, TLS or timeout. #cause holds the original.
40
+ class TransportError < Error; end
41
+
42
+ # A successful response whose body is not a JSON object.
43
+ class UnserializableResponseError < Error
44
+ # @return [Response]
45
+ attr_reader :response
46
+
47
+ def initialize(response)
48
+ @response = response
49
+ super("Expected a JSON object from the API (HTTP #{response.status})")
50
+ end
51
+ end
52
+
53
+ # A Management Key operation was called on a client built without management_key:.
54
+ class MissingManagementKeyError < Error
55
+ def initialize(message = "This operation needs a Management Key: pass management_key: to the client")
56
+ super
57
+ end
58
+ end
59
+ end