loqate 0.7.0 → 0.8.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5fb61fc51df7e0d68f444bbdc456f8dc3908f4615a34ba36aa0a16265518ea86
4
- data.tar.gz: 53aa2a20fde0da8a1cc284f56b18dde9edbd8def3c0f3265757ec5c30f388d23
3
+ metadata.gz: 99e0ea7429e262e3ea0d27b5b97e47069414bc0c7f04306df780884e4827f333
4
+ data.tar.gz: c6e29931639924647a9a23eb753258c2baf1c7edf650413ebe28ab054d0dc1f2
5
5
  SHA512:
6
- metadata.gz: be0b4b5a521533eb1f023c60c1cbd5b203fb586333dfc3a3b52bda07fe8b35a57b9d42d94a0eaf4f1a531e3f3ac2ef56917e75b1ca514dbf078c06192dc8c106
7
- data.tar.gz: 27f8a174a784a974f755d303ff2df0f8ec370e23781b25b7dc6ad86d2bd096bd959634e4c82506971d8e14b924ad4d8fd5acb5c8c69b7ed8b6b466c94a36d295
6
+ metadata.gz: 1804077569ad841285a33eeba7edd9ab2a323069220d2782996f65d1f270acf35088a25c96ed29381609919190e230e54bded7fa3464c103fc39666832e8d250
7
+ data.tar.gz: 332955af60f1623ca8f4249b9cefda5a35a63c4a84aa4488aa674a7ca2776e7259fe1e8d378988c0382a56854f79b087335bcf2d367116a7e4b82346a2767da9
data/.rubocop.yml CHANGED
@@ -1,3 +1,5 @@
1
+ require: rubocop-rspec
2
+
1
3
  AllCops:
2
4
  DisplayCopNames: true
3
5
 
@@ -15,6 +17,11 @@ Naming/MethodName:
15
17
  Exclude:
16
18
  - lib/loqate/result.rb
17
19
 
20
+ # ----------------------- RSpec -----------------------
21
+
22
+ RSpec/ExampleLength:
23
+ Enabled: false
24
+
18
25
  # ----------------------- Style -----------------------
19
26
 
20
27
  Style/FrozenStringLiteralComment:
data/.yardstick.yml CHANGED
@@ -121,8 +121,19 @@ rules:
121
121
  - Loqate::Gateway#bank
122
122
  - Loqate::Gateway#config
123
123
  - Loqate::Gateway#email
124
+ - Loqate::Gateway#geocoding
124
125
  - Loqate::Gateway#initialize
125
126
  - Loqate::Gateway#phone
127
+ - Loqate::Geocoding::Gateway#initialize
128
+ - Loqate::Geocoding::Direction#segment_number
129
+ - Loqate::Geocoding::Direction#step_number
130
+ - Loqate::Geocoding::Direction#action
131
+ - Loqate::Geocoding::Direction#description
132
+ - Loqate::Geocoding::Direction#road
133
+ - Loqate::Geocoding::Direction#step_time
134
+ - Loqate::Geocoding::Direction#step_distance
135
+ - Loqate::Geocoding::Direction#total_time
136
+ - Loqate::Geocoding::Direction#total_distance
126
137
  - Loqate::Phone::Gateway#initialize
127
138
  - Loqate::Phone::PhoneNumberValidation#country_prefix
128
139
  - Loqate::Phone::PhoneNumberValidation#is_valid
@@ -179,6 +190,11 @@ rules:
179
190
  - Loqate::Email::Gateway#mapper
180
191
  - Loqate::Error#attributes
181
192
  - Loqate::Gateway#client
193
+ - Loqate::Geocoding::Gateway#error_mapper
194
+ - Loqate::Geocoding::Gateway#client
195
+ - Loqate::Geocoding::Gateway#mapper
196
+ - Loqate::Geocoding::Gateway#build_error_from
197
+ - Loqate::Geocoding::Gateway#build_directions_from
182
198
  - Loqate::Phone::Gateway#build_error_from
183
199
  - Loqate::Phone::Gateway#build_phone_validation_from
184
200
  - Loqate::Phone::Gateway#client
@@ -228,6 +244,11 @@ rules:
228
244
  - Loqate::Email::Gateway#mapper
229
245
  - Loqate::Error#attributes
230
246
  - Loqate::Gateway#client
247
+ - Loqate::Geocoding::Gateway#error_mapper
248
+ - Loqate::Geocoding::Gateway#client
249
+ - Loqate::Geocoding::Gateway#mapper
250
+ - Loqate::Geocoding::Gateway#build_error_from
251
+ - Loqate::Geocoding::Gateway#build_directions_from
231
252
  - Loqate::Phone::Gateway#build_error_from
232
253
  - Loqate::Phone::Gateway#build_phone_validation_from
233
254
  - Loqate::Phone::Gateway#client
data/CHANGELOG.md CHANGED
@@ -4,6 +4,10 @@ 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.8.0] - 2018-12-10
8
+ ### Added
9
+ - Distance service of the Geocoding API
10
+
7
11
  ## [0.7.0] - 2018-12-03
8
12
  ### Changed
9
13
  - Moved the `Address`, `Email` and `Phone` APIs into their own namespaces
@@ -57,6 +61,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
57
61
  - Initial core functionality
58
62
  - Codebase maintenance tools
59
63
 
64
+ [0.8.0]: https://github.com/wilsonsilva/loqate/compare/v0.7.0...v0.8.0
60
65
  [0.7.0]: https://github.com/wilsonsilva/loqate/compare/v0.6.0...v0.7.0
61
66
  [0.6.0]: https://github.com/wilsonsilva/loqate/compare/v0.5.0...v0.6.0
62
67
  [0.5.0]: https://github.com/wilsonsilva/loqate/compare/v0.4.0...v0.5.0
data/README.md CHANGED
@@ -19,6 +19,8 @@ Client to address verification, postcode lookup, & data quality services from Lo
19
19
  - [Address API](#address-api)
20
20
  - [Finding addresses](#finding-addresses)
21
21
  - [Retrieving the details of an address](#retrieving-the-details-of-an-address)
22
+ - [Geocoding API](#geocoding-api)
23
+ - [Finding directions](#finding-directions)
22
24
  - [Phone API](#phone-api)
23
25
  - [Validating a phone number](#validating-a-phone-number)
24
26
  - [Email API](#phone-api)
@@ -127,6 +129,19 @@ address.line1 # '148 Warner Road'
127
129
  address.postal_code # 'E17 7EA'
128
130
  ```
129
131
 
132
+ ### Geocoding API
133
+
134
+ The Geocoding API exposes endpoints to perform geocoding operations.
135
+
136
+ #### Finding directions
137
+ ```ruby
138
+ directions = gateway.geocoding.directions!(
139
+ start: [51.5079532, -0.1266053],
140
+ finish: [51.5078677, -0.1266825]
141
+ )
142
+ directions.first.description # => 'Leave from Strand/A4'
143
+ ```
144
+
130
145
  ### Phone API
131
146
 
132
147
  The Phone API consists of a single API request:
data/ROADMAP.md CHANGED
@@ -5,6 +5,7 @@
5
5
  - [x] HTTP Client
6
6
  - [x] Core Client
7
7
  - [ ] Logging
8
+ - [ ] Instrumentation
8
9
  - [x] Domain error handling
9
10
  - [x] Configuration
10
11
  - [x] Unwrap request results
@@ -1,6 +1,7 @@
1
1
  require 'loqate/address/gateway'
2
2
  require 'loqate/bank/gateway'
3
3
  require 'loqate/email/gateway'
4
+ require 'loqate/geocoding/gateway'
4
5
  require 'loqate/phone/gateway'
5
6
 
6
7
  module Loqate
@@ -34,6 +35,14 @@ module Loqate
34
35
  @address ||= Address::Gateway.new(client)
35
36
  end
36
37
 
38
+ # Gateway to the Geocoding APIs.
39
+ #
40
+ # @return [Geocoding::Gateway] An instance of a geocoding gateway.
41
+ #
42
+ def geocoding
43
+ @geocoding ||= Geocoding::Gateway.new(client)
44
+ end
45
+
37
46
  # Gateway to the Phone number API.
38
47
  #
39
48
  # @return [Phone::Gateway] An instance of a phone gateway.
@@ -0,0 +1,60 @@
1
+ module Loqate
2
+ module Geocoding
3
+ # A result from the directions API call.
4
+ class Direction < Dry::Struct::Value
5
+ # A zero based counter indicating the row number.
6
+ #
7
+ # @return [Integer]
8
+ #
9
+ attribute :segment_number, Types::Strict::Integer
10
+
11
+ # A zero based counter indicating the row number.
12
+ #
13
+ # @return [Integer]
14
+ #
15
+ attribute :step_number, Types::Strict::Integer
16
+
17
+ # The type of routing instruction.
18
+ #
19
+ # @return [String]
20
+ #
21
+ attribute :action, Types::Strict::String
22
+
23
+ # Textual description of the routing instruction.
24
+ #
25
+ # @return [String]
26
+ #
27
+ attribute :description, Types::Strict::String
28
+
29
+ # The name of the road to turn onto.
30
+ #
31
+ # @return [String]
32
+ #
33
+ attribute :road, Types::Strict::String
34
+
35
+ # The time in seconds for this part of the route.
36
+ #
37
+ # @return [Integer]
38
+ #
39
+ attribute :step_time, Types::Strict::Integer
40
+
41
+ # The distance in metres for this part of the route.
42
+ #
43
+ # @return [Integer]
44
+ #
45
+ attribute :step_distance, Types::Strict::Integer
46
+
47
+ # The total time in seconds for the route.
48
+ #
49
+ # @return [Integer]
50
+ #
51
+ attribute :total_time, Types::Strict::Integer
52
+
53
+ # The total distance in metres for the route.
54
+ #
55
+ # @return [Integer]
56
+ #
57
+ attribute :total_distance, Types::Strict::Integer
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,106 @@
1
+ require 'loqate/client'
2
+ require 'loqate/result'
3
+ require 'loqate/geocoding/direction'
4
+ require 'loqate/mappers/error_mapper'
5
+ require 'loqate/mappers/generic_mapper'
6
+
7
+ module Loqate
8
+ module Geocoding
9
+ # Retrieves
10
+ class Gateway
11
+ DIRECTIONS_ENDPOINT = '/DistancesAndDirections/Interactive/Directions/v2.00/json3.ws'.freeze
12
+
13
+ include Result::Mixin
14
+
15
+ # Creates a geocoding gateway.
16
+ #
17
+ # @param [Client] client The client responsible for the HTTP interactions
18
+ #
19
+ def initialize(client)
20
+ @client = client
21
+ @mapper = Mappers::GenericMapper.new
22
+ @error_mapper = Mappers::ErrorMapper.new
23
+ end
24
+
25
+ # Returns the directions between two or more points.
26
+ #
27
+ # @param [Hash] options The options to find directions.
28
+ # @option options [String|Array<String>] :start The coordinates (latitude, longitude or easting, northing) of
29
+ # the start of the route. A postcode is also valid.
30
+ # @option options [String|Array<String>] :finish The coordinates (latitude, longitude or easting, northing) of
31
+ # the finish of the route. A postcode is also valid.
32
+ # @option options [String|Array<String>] :way_points The coordinates (latitude, longitude or easting, northing)
33
+ # of any waypoints. Postcodes are also valid.
34
+ # @option options [String] :distance_type Specifies how the distances between the stores are calculated. It can
35
+ # either be 'Fastest' or 'Shortest'.
36
+ # @option options [String] :start_day The day of the week the route is to start on. Provide this parameter
37
+ # only if you wish to utilise superior 'Speed Profiles' historic traffic speed data over time for avoiding
38
+ # rush hours and such.
39
+ # @option options [String] :start_time The time of day the route is to start on, measured in whole minutes
40
+ # from midnight. (E.g. 8:30am is entered as 510.) Provide this parameter only if you wish to utilise
41
+ # superior 'Speed Profiles' historic traffic speed data over time for avoiding rush hours and such.
42
+ #
43
+ # @example Finding directions using latitude and longitude coordinates
44
+ # directions = geocoding_gateway.directions(
45
+ # start: ['51.5211057', '-0.0989496'],
46
+ # finish: ['51.5213087', '-0.0981853']
47
+ # )
48
+ #
49
+ # @example Finding directions using easting and northing coordinates
50
+ # directions = geocoding_gateway.directions(
51
+ # start: [381600, 259400],
52
+ # finish: [380600, 258400],
53
+ # )
54
+ #
55
+ # @example Finding directions using postcodes
56
+ # directions = geocoding_gateway.directions(
57
+ # start: 'EC1A 4JA',
58
+ # finish: 'EC1A 4ER'
59
+ # )
60
+ #
61
+ # @example Finding directions using waypoints
62
+ # directions = geocoding_gateway.directions(
63
+ # start: 'EC1A 4JA',
64
+ # finish: 'EC1A 4ER',
65
+ # way_points: ['EC1A 4JQ']
66
+ # )
67
+ #
68
+ # @example Finding directions in a given time
69
+ # directions = geocoding_gateway.directions(
70
+ # start: ['51.5211057', '-0.0989496'],
71
+ # finish: ['51.5213087', '-0.0981853']
72
+ # start_day: 'Monday',
73
+ # start_time: 510
74
+ # )
75
+ #
76
+ # @return [Result] A result wrapping a list of directions.
77
+ #
78
+ def directions(options)
79
+ %i[start finish way_points].each do |key|
80
+ options[key] = options[key].join(',') if options[key].respond_to?(:join)
81
+ end
82
+
83
+ response = client.get(DIRECTIONS_ENDPOINT, options)
84
+
85
+ response.errors? && build_error_from(response.items.first) || build_directions_from(response.items)
86
+ end
87
+
88
+ private
89
+
90
+ # @api private
91
+ attr_reader :client, :mapper, :error_mapper
92
+
93
+ # @api private
94
+ def build_error_from(item)
95
+ error = error_mapper.map_one(item)
96
+ Failure(error)
97
+ end
98
+
99
+ # @api private
100
+ def build_directions_from(item)
101
+ direction = mapper.map(item, Direction)
102
+ Success(direction)
103
+ end
104
+ end
105
+ end
106
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Loqate
4
- VERSION = '0.7.0'
4
+ VERSION = '0.8.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.7.0
4
+ version: 0.8.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-03 00:00:00.000000000 Z
11
+ date: 2018-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-struct
@@ -361,6 +361,8 @@ files:
361
361
  - lib/loqate/email/gateway.rb
362
362
  - lib/loqate/error.rb
363
363
  - lib/loqate/gateway.rb
364
+ - lib/loqate/geocoding/direction.rb
365
+ - lib/loqate/geocoding/gateway.rb
364
366
  - lib/loqate/mappers/error_mapper.rb
365
367
  - lib/loqate/mappers/generic_mapper.rb
366
368
  - lib/loqate/phone/gateway.rb