loqate 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99e0ea7429e262e3ea0d27b5b97e47069414bc0c7f04306df780884e4827f333
4
- data.tar.gz: c6e29931639924647a9a23eb753258c2baf1c7edf650413ebe28ab054d0dc1f2
3
+ metadata.gz: 18b2de06a287567be0f1ccce8dc27723ed9ff5a786ffa4d2dbfa365be936bb60
4
+ data.tar.gz: cc2ca8285a696744a06967f66809afc2bf045a88a4d47b507f0b5ab70bb2eb30
5
5
  SHA512:
6
- metadata.gz: 1804077569ad841285a33eeba7edd9ab2a323069220d2782996f65d1f270acf35088a25c96ed29381609919190e230e54bded7fa3464c103fc39666832e8d250
7
- data.tar.gz: 332955af60f1623ca8f4249b9cefda5a35a63c4a84aa4488aa674a7ca2776e7259fe1e8d378988c0382a56854f79b087335bcf2d367116a7e4b82346a2767da9
6
+ metadata.gz: 8de9e9a790722ce940c8859ea30176f09685daf9904c49ecd432fa3aad0b9e94a1f7120f0fb55886c7c1b18510ee15f8ed156d100bdf51b0fd3c6afb0c7c5d5b
7
+ data.tar.gz: 7c36a6013d07df700d6cc42a16746d8207a4a95ded5aae5dff3a33bf3275bfbd5a594fd9f3d50451afc381d1867baa24a5bc928733e47562f31a4e2638eaf970
@@ -81,6 +81,16 @@ rules:
81
81
  - Loqate::Bank::CardValidation#card_type
82
82
  - Loqate::Bank::Gateway#build_branch_from
83
83
  - Loqate::Bank::Gateway#initialize
84
+ - Loqate::Geocoding::Country#country_name
85
+ - Loqate::Geocoding::Country#country_iso2
86
+ - Loqate::Geocoding::Country#country_iso3
87
+ - Loqate::Geocoding::Country#country_iso_number
88
+ - Loqate::Geocoding::Gateway#position_to_country!
89
+ - Loqate::Geocoding::Gateway#directions!
90
+ - Loqate::Geocoding::Gateway#geocode!
91
+ - Loqate::Geocoding::Location#name
92
+ - Loqate::Geocoding::Location#latitude
93
+ - Loqate::Geocoding::Location#longitude
84
94
  - Loqate::Bank::InternationalAccountValidation#correct?
85
95
  - Loqate::Bank::InternationalAccountValidation#is_correct
86
96
  - Loqate::Email::BatchEmailValidation#account
@@ -124,6 +134,7 @@ rules:
124
134
  - Loqate::Gateway#geocoding
125
135
  - Loqate::Gateway#initialize
126
136
  - Loqate::Gateway#phone
137
+ - Loqate::Geocoding::Gateway#directions
127
138
  - Loqate::Geocoding::Gateway#initialize
128
139
  - Loqate::Geocoding::Direction#segment_number
129
140
  - Loqate::Geocoding::Direction#step_number
@@ -190,6 +201,8 @@ rules:
190
201
  - Loqate::Email::Gateway#mapper
191
202
  - Loqate::Error#attributes
192
203
  - Loqate::Gateway#client
204
+ - Loqate::Geocoding::Gateway#build_country_from
205
+ - Loqate::Geocoding::Gateway#build_location_from
193
206
  - Loqate::Geocoding::Gateway#error_mapper
194
207
  - Loqate::Geocoding::Gateway#client
195
208
  - Loqate::Geocoding::Gateway#mapper
@@ -244,11 +257,13 @@ rules:
244
257
  - Loqate::Email::Gateway#mapper
245
258
  - Loqate::Error#attributes
246
259
  - Loqate::Gateway#client
260
+ - Loqate::Geocoding::Gateway#build_country_from
247
261
  - Loqate::Geocoding::Gateway#error_mapper
248
262
  - Loqate::Geocoding::Gateway#client
249
263
  - Loqate::Geocoding::Gateway#mapper
250
264
  - Loqate::Geocoding::Gateway#build_error_from
251
265
  - Loqate::Geocoding::Gateway#build_directions_from
266
+ - Loqate::Geocoding::Gateway#build_location_from
252
267
  - Loqate::Phone::Gateway#build_error_from
253
268
  - Loqate::Phone::Gateway#build_phone_validation_from
254
269
  - Loqate::Phone::Gateway#client
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.9.0] - 2018-12-11
8
+ ### Added
9
+ - Geocoding service of the Geocoding API
10
+ - A service to calculate the country a given location is within
11
+
7
12
  ## [0.8.0] - 2018-12-10
8
13
  ### Added
9
14
  - Distance service of the Geocoding API
@@ -61,6 +66,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
61
66
  - Initial core functionality
62
67
  - Codebase maintenance tools
63
68
 
69
+ [0.9.0]: https://github.com/wilsonsilva/loqate/compare/v0.8.0...v0.9.0
64
70
  [0.8.0]: https://github.com/wilsonsilva/loqate/compare/v0.7.0...v0.8.0
65
71
  [0.7.0]: https://github.com/wilsonsilva/loqate/compare/v0.6.0...v0.7.0
66
72
  [0.6.0]: https://github.com/wilsonsilva/loqate/compare/v0.5.0...v0.6.0
data/README.md CHANGED
@@ -21,6 +21,8 @@ Client to address verification, postcode lookup, & data quality services from Lo
21
21
  - [Retrieving the details of an address](#retrieving-the-details-of-an-address)
22
22
  - [Geocoding API](#geocoding-api)
23
23
  - [Finding directions](#finding-directions)
24
+ - [Geocoding a location](#geocoding-a-location)
25
+ - [Finding a country based on coordinates](#finding-a-country-based-on-coordinates)
24
26
  - [Phone API](#phone-api)
25
27
  - [Validating a phone number](#validating-a-phone-number)
26
28
  - [Email API](#phone-api)
@@ -142,6 +144,18 @@ directions = gateway.geocoding.directions!(
142
144
  directions.first.description # => 'Leave from Strand/A4'
143
145
  ```
144
146
 
147
+ #### Geocoding a location
148
+ ```ruby
149
+ location = gateway.geocoding.geocode!(country: 'US', location: '90210')
150
+ location.name # => 'Beverly Hills, CA 90210'
151
+ ```
152
+
153
+ #### Finding a country based on coordinates
154
+ ```ruby
155
+ country = gateway.geocoding.position_to_country!(latitude: 52.1321, longitude: -2.1001)
156
+ country.country_name # => 'United Kingdom'
157
+ ```
158
+
145
159
  ### Phone API
146
160
 
147
161
  The Phone API consists of a single API request:
data/ROADMAP.md CHANGED
@@ -9,9 +9,12 @@
9
9
  - [x] Domain error handling
10
10
  - [x] Configuration
11
11
  - [x] Unwrap request results
12
- - [ ] Validate request parameters
13
12
  - [ ] API/Service versioning
14
- - [ ] Integration with RSpec
13
+
14
+ ## Extended
15
+ - [ ] Validate request parameters before submitting a request
16
+ - [ ] Integration with RSpec (Mocks and Matchers)
17
+ - [ ] Implement Google Open Location Code in the Geocoding API (https://github.com/google/open-location-code)
15
18
 
16
19
  ## APIs
17
20
 
@@ -0,0 +1,30 @@
1
+ module Loqate
2
+ module Geocoding
3
+ # A result from the position to country API call.
4
+ class Country < Dry::Struct::Value
5
+ # The name of the country where the position belongs to.
6
+ #
7
+ # @return [String]
8
+ #
9
+ attribute :country_name, Types::Strict::String
10
+
11
+ # The ISO2 of the country.
12
+ #
13
+ # @return [String]
14
+ #
15
+ attribute :country_iso2, Types::Strict::String
16
+
17
+ # The ISO3 of the country.
18
+ #
19
+ # @return [String]
20
+ #
21
+ attribute :country_iso3, Types::Strict::String
22
+
23
+ # The ISO number of the country.
24
+ #
25
+ # @return [Integer]
26
+ #
27
+ attribute :country_iso_number, Types::Strict::Integer
28
+ end
29
+ end
30
+ end
@@ -1,14 +1,18 @@
1
1
  require 'loqate/client'
2
2
  require 'loqate/result'
3
+ require 'loqate/geocoding/country'
3
4
  require 'loqate/geocoding/direction'
5
+ require 'loqate/geocoding/location'
4
6
  require 'loqate/mappers/error_mapper'
5
7
  require 'loqate/mappers/generic_mapper'
6
8
 
7
9
  module Loqate
8
10
  module Geocoding
9
- # Retrieves
11
+ # Performs API requests to the geocoding services.
10
12
  class Gateway
11
13
  DIRECTIONS_ENDPOINT = '/DistancesAndDirections/Interactive/Directions/v2.00/json3.ws'.freeze
14
+ GEOCODE_ENDPOINT = '/Geocoding/International/Geocode/v1.10/json3.ws'.freeze
15
+ POSITION_TO_COUNTRY_ENDPOINT = '/Geocoding/International/PositionToCountry/v1.00/json3.ws'.freeze
12
16
 
13
17
  include Result::Mixin
14
18
 
@@ -85,6 +89,81 @@ module Loqate
85
89
  response.errors? && build_error_from(response.items.first) || build_directions_from(response.items)
86
90
  end
87
91
 
92
+ # Returns the directions between two or more points.
93
+ #
94
+ # @raise [Error] If the result is not a success
95
+ #
96
+ # @see Loqage::Geocoding::Geocoding#directions
97
+ #
98
+ # @return [Array<Direction>] A list of directions.
99
+ #
100
+ def directions!(options)
101
+ unwrap_result_or_raise { directions(options) }
102
+ end
103
+
104
+ # Returns the WGS84 latitude and longitude for the given location. Supports most international locations.
105
+ #
106
+ # @param [Hash] options The options to geocode.
107
+ # @option options [String] :country The name or ISO 2 or 3 character code for the country to search in.
108
+ # Most country names will be recognised but the use of the ISO country code is recommended for clarity.
109
+ # @option options [String] :location The location to geocode. This can be a postal code or place name.
110
+ #
111
+ # @example
112
+ # result = geocoding_gateway.geocode(country: 'US', location: '90210')
113
+ #
114
+ # @return [Result] A result wrapping a location.
115
+ #
116
+ def geocode(options)
117
+ response = client.get(GEOCODE_ENDPOINT, options)
118
+
119
+ response.errors? && build_error_from(response.items.first) || build_location_from(response.items.first)
120
+ end
121
+
122
+ # Returns the WGS84 latitude and longitude for the given location. Supports most international locations.
123
+ #
124
+ # @raise [Error] If the result is not a success
125
+ #
126
+ # @see Loqate::Geocoding::Geocoding#geocode
127
+ #
128
+ # @return [Location] A location.
129
+ #
130
+ def geocode!(options)
131
+ unwrap_result_or_raise { geocode(options) }
132
+ end
133
+
134
+ # Returns the country based on the WGS84 latitude and longitude supplied. No result is returned if
135
+ # the coordinates are in international waters.
136
+ #
137
+ # @param [Hash] options The coordinates of the position to search against.
138
+ # @option options [Float] :latitude The latitude of the position to search against.
139
+ # @option options [Float] :longitude The longitude of the position to search against.
140
+ #
141
+ # @example
142
+ # result = geocoding_gateway.position_to_country(latitude: 52.1321, longitude: -2.1001)
143
+ #
144
+ # @return [Result|nil] A result wrapping a country.
145
+ #
146
+ def position_to_country(options)
147
+ response = client.get(POSITION_TO_COUNTRY_ENDPOINT, options)
148
+
149
+ return Success(nil) if response.items.empty?
150
+
151
+ response.errors? && build_error_from(response.items.first) || build_country_from(response.items.first)
152
+ end
153
+
154
+ # Returns the country based on the WGS84 latitude and longitude supplied. No result is returned if
155
+ # the coordinates are in international waters.
156
+ #
157
+ # @raise [Error] If the result is not a success
158
+ #
159
+ # @see Loqate::Geocoding::Geocoding#position_to_country
160
+ #
161
+ # @return [Country] A country.
162
+ #
163
+ def position_to_country!(options)
164
+ unwrap_result_or_raise { position_to_country(options) }
165
+ end
166
+
88
167
  private
89
168
 
90
169
  # @api private
@@ -97,10 +176,22 @@ module Loqate
97
176
  end
98
177
 
99
178
  # @api private
100
- def build_directions_from(item)
101
- direction = mapper.map(item, Direction)
179
+ def build_directions_from(items)
180
+ direction = mapper.map(items, Direction)
102
181
  Success(direction)
103
182
  end
183
+
184
+ # @api private
185
+ def build_location_from(item)
186
+ location = mapper.map_one(item, Location)
187
+ Success(location)
188
+ end
189
+
190
+ # @api private
191
+ def build_country_from(item)
192
+ country = mapper.map_one(item, Country)
193
+ Success(country)
194
+ end
104
195
  end
105
196
  end
106
197
  end
@@ -0,0 +1,24 @@
1
+ module Loqate
2
+ module Geocoding
3
+ # A result from the geocode API call.
4
+ class Location < Dry::Struct::Value
5
+ # The name of the location found.
6
+ #
7
+ # @return [String]
8
+ #
9
+ attribute :name, Types::Strict::String
10
+
11
+ # The WGS84 latitude of the found location.
12
+ #
13
+ # @return [Float]
14
+ #
15
+ attribute :latitude, Types::Strict::Float
16
+
17
+ # The WGS84 longitude of the found location.
18
+ #
19
+ # @return [Float]
20
+ #
21
+ attribute :longitude, Types::Strict::Float
22
+ end
23
+ end
24
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Loqate
4
- VERSION = '0.8.0'
4
+ VERSION = '0.9.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loqate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wilson Silva
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-10 00:00:00.000000000 Z
11
+ date: 2018-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-struct
@@ -361,8 +361,10 @@ files:
361
361
  - lib/loqate/email/gateway.rb
362
362
  - lib/loqate/error.rb
363
363
  - lib/loqate/gateway.rb
364
+ - lib/loqate/geocoding/country.rb
364
365
  - lib/loqate/geocoding/direction.rb
365
366
  - lib/loqate/geocoding/gateway.rb
367
+ - lib/loqate/geocoding/location.rb
366
368
  - lib/loqate/mappers/error_mapper.rb
367
369
  - lib/loqate/mappers/generic_mapper.rb
368
370
  - lib/loqate/phone/gateway.rb