smartystreets_ruby_sdk 5.8.0 → 5.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/international_example.rb +5 -1
- data/examples/us_autocomplete_pro_example.rb +48 -0
- data/examples/us_reverse_geo_example.rb +47 -0
- data/examples/us_street_multiple_address_example.rb +4 -1
- data/examples/us_street_single_address_example.rb +4 -1
- data/lib/smartystreets_ruby_sdk.rb +2 -0
- data/lib/smartystreets_ruby_sdk/client_builder.rb +14 -0
- data/lib/smartystreets_ruby_sdk/international_street/client.rb +4 -2
- data/lib/smartystreets_ruby_sdk/shared_credentials.rb +1 -1
- data/lib/smartystreets_ruby_sdk/us_autocomplete_pro.rb +10 -0
- data/lib/smartystreets_ruby_sdk/us_autocomplete_pro/client.rb +77 -0
- data/lib/smartystreets_ruby_sdk/us_autocomplete_pro/geolocation_type.rb +8 -0
- data/lib/smartystreets_ruby_sdk/us_autocomplete_pro/lookup.rb +61 -0
- data/lib/smartystreets_ruby_sdk/us_autocomplete_pro/suggestion.rb +18 -0
- data/lib/smartystreets_ruby_sdk/us_reverse_geo.rb +12 -0
- data/lib/smartystreets_ruby_sdk/us_reverse_geo/address.rb +16 -0
- data/lib/smartystreets_ruby_sdk/us_reverse_geo/client.rb +38 -0
- data/lib/smartystreets_ruby_sdk/us_reverse_geo/coordinate.rb +25 -0
- data/lib/smartystreets_ruby_sdk/us_reverse_geo/lookup.rb +21 -0
- data/lib/smartystreets_ruby_sdk/us_reverse_geo/result.rb +20 -0
- data/lib/smartystreets_ruby_sdk/us_reverse_geo/us_reverse_geo_response.rb +17 -0
- data/lib/smartystreets_ruby_sdk/us_street/analysis.rb +4 -1
- data/lib/smartystreets_ruby_sdk/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df457cd42e87bc1addf658ff0d64ba1a0150861252ac10ae2d5207c4c5311836
|
4
|
+
data.tar.gz: 917654d4567954241f85856f8673a6527343fa5196112c5595f76fc840194527
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9084938032f85260ba05d9fcd2b8e9866662735e637c290571b80309d8946ad2e03f403bff712704a69c352f26786bfaa2abf2a740455fe98cea6af903007c83
|
7
|
+
data.tar.gz: 809a899686525b6d8cfd57e36a8832d0671c90bb4269a92d295e898bb314d9460dd2efafff4e277643382fc857d4540b1578b267692bafb4f60c4a61f2189cc2
|
@@ -14,7 +14,11 @@ class InternationalExample
|
|
14
14
|
# auth_token = ENV['SMARTY_AUTH_TOKEN']
|
15
15
|
|
16
16
|
credentials = SmartyStreets::StaticCredentials.new(auth_id, auth_token)
|
17
|
-
|
17
|
+
|
18
|
+
# The appropriate license values to be used for your subscriptions
|
19
|
+
# can be found on the Subscriptions page of the account dashboard.
|
20
|
+
# https://www.smartystreets.com/docs/cloud/licensing
|
21
|
+
client = SmartyStreets::ClientBuilder.new(credentials).with_licenses(%w('international-global-plus-cloud'))
|
18
22
|
.build_international_street_api_client
|
19
23
|
|
20
24
|
# Documentation for input fields can be found at:
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'smartystreets_ruby_sdk/shared_credentials'
|
2
|
+
require '../lib/smartystreets_ruby_sdk/client_builder'
|
3
|
+
require '../lib/smartystreets_ruby_sdk/us_autocomplete_pro/lookup'
|
4
|
+
|
5
|
+
class USAutocompleteProExample
|
6
|
+
Lookup = SmartyStreets::USAutocompletePro::Lookup
|
7
|
+
|
8
|
+
def run
|
9
|
+
# key = 'Your SmartyStreets Auth ID here'
|
10
|
+
# hostname = 'Your SmartyStreets Auth Token here'
|
11
|
+
|
12
|
+
# We recommend storing your secret keys in environment variables instead---it's safer!
|
13
|
+
key = ENV['SMARTY_AUTH_WEB']
|
14
|
+
referer = ENV['SMARTY_AUTH_REFERER']
|
15
|
+
|
16
|
+
credentials = SmartyStreets::SharedCredentials.new(key, referer)
|
17
|
+
|
18
|
+
# The appropriate license values to be used for your subscriptions
|
19
|
+
# can be found on the Subscriptions page of the account dashboard.
|
20
|
+
# https://www.smartystreets.com/docs/cloud/licensing
|
21
|
+
client = SmartyStreets::ClientBuilder.new(credentials).with_licenses(%w('us-autocomplete-pro-cloud'))
|
22
|
+
.build_us_autocomplete_pro_api_client
|
23
|
+
|
24
|
+
# Documentation for input fields can be found at:
|
25
|
+
# https://smartystreets.com/docs/cloud/us-autocomplete-api
|
26
|
+
|
27
|
+
lookup = Lookup.new('4770 Lincoln Ave O')
|
28
|
+
lookup.max_results = 10
|
29
|
+
lookup.add_city_filter('Ogden')
|
30
|
+
lookup.add_state_filter('IL')
|
31
|
+
lookup.max_results = 5
|
32
|
+
lookup.prefer_ratio = 3
|
33
|
+
|
34
|
+
suggestions = client.send(lookup) # The client will also return the suggestions directly
|
35
|
+
|
36
|
+
puts
|
37
|
+
puts '*** Result with some filters ***'
|
38
|
+
puts
|
39
|
+
|
40
|
+
suggestions.each do |suggestion|
|
41
|
+
puts "#{suggestion.street_line} #{suggestion.city}, #{suggestion.state}"
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
USAutocompleteProExample.new.run
|
48
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'smartystreets_ruby_sdk/static_credentials'
|
2
|
+
require '../lib/smartystreets_ruby_sdk/client_builder'
|
3
|
+
require '../lib/smartystreets_ruby_sdk/us_reverse_geo/lookup'
|
4
|
+
|
5
|
+
class USReverseGeoExample
|
6
|
+
Lookup = SmartyStreets::USReverseGeo::Lookup
|
7
|
+
|
8
|
+
def run
|
9
|
+
auth_id = 'Your SmartyStreets Auth ID here'
|
10
|
+
auth_token = 'Your SmartyStreets Auth Token here'
|
11
|
+
|
12
|
+
# We recommend storing your secret keys in environment variables instead---it's safer!
|
13
|
+
# auth_id = ENV['SMARTY_AUTH_ID']
|
14
|
+
# auth_token = ENV['SMARTY_AUTH_TOKEN']
|
15
|
+
|
16
|
+
credentials = SmartyStreets::StaticCredentials.new(auth_id, auth_token)
|
17
|
+
|
18
|
+
# The appropriate license values to be used for your subscriptions
|
19
|
+
# can be found on the Subscriptions page of the account dashboard.
|
20
|
+
# https://www.smartystreets.com/docs/cloud/licensing
|
21
|
+
client = SmartyStreets::ClientBuilder.new(credentials).with_licenses(%w('us-reverse-geocoding-cloud'))
|
22
|
+
.build_us_reverse_geo_api_client
|
23
|
+
|
24
|
+
# Documentation for input fields can be found at:
|
25
|
+
# https://smartystreets.com/docs/cloud/us-reverse-geo-api#http-request-input-fields
|
26
|
+
|
27
|
+
lookup = Lookup.new(40.111111, -111.111111)
|
28
|
+
|
29
|
+
response = client.send(lookup)
|
30
|
+
result = response.results[0]
|
31
|
+
|
32
|
+
coordinate = result.coordinate
|
33
|
+
puts "Latitude: #{coordinate.latitude}"
|
34
|
+
puts "Longitude: #{coordinate.longitude}\n"
|
35
|
+
|
36
|
+
puts "Distance: #{result.distance}\n"
|
37
|
+
|
38
|
+
address = result.address
|
39
|
+
puts "Street: #{address.street}"
|
40
|
+
puts "City: #{address.city}"
|
41
|
+
puts "State Abbreviation: #{address.state_abbreviation}"
|
42
|
+
puts "ZIP Code: #{address.zipcode}"
|
43
|
+
puts "License: #{coordinate.get_license}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
USReverseGeoExample.new.run
|
@@ -16,7 +16,10 @@ class USStreetMultipleAddressExample
|
|
16
16
|
|
17
17
|
credentials = SmartyStreets::StaticCredentials.new(auth_id, auth_token)
|
18
18
|
|
19
|
-
|
19
|
+
# The appropriate license values to be used for your subscriptions
|
20
|
+
# can be found on the Subscriptions page of the account dashboard.
|
21
|
+
# https://www.smartystreets.com/docs/cloud/licensing
|
22
|
+
client = SmartyStreets::ClientBuilder.new(credentials).with_licenses(%w('us-rooftop-geocoding-cloud'))
|
20
23
|
.build_us_street_api_client
|
21
24
|
batch = SmartyStreets::Batch.new
|
22
25
|
|
@@ -13,7 +13,10 @@ class USStreetSingleAddressExample
|
|
13
13
|
|
14
14
|
credentials = SmartyStreets::StaticCredentials.new(auth_id, auth_token)
|
15
15
|
|
16
|
-
|
16
|
+
# The appropriate license values to be used for your subscriptions
|
17
|
+
# can be found on the Subscriptions page of the account dashboard.
|
18
|
+
# https://www.smartystreets.com/docs/cloud/licensing
|
19
|
+
client = SmartyStreets::ClientBuilder.new(credentials).with_licenses(%w('us-rooftop-geocoding-cloud'))
|
17
20
|
# with_proxy('localhost', 8080, 'proxyUser', 'proxyPassword'). # Uncomment this line to try it with a proxy
|
18
21
|
build_us_street_api_client
|
19
22
|
|
@@ -25,7 +25,9 @@ require 'smartystreets_ruby_sdk/us_extract'
|
|
25
25
|
require 'smartystreets_ruby_sdk/us_street'
|
26
26
|
require 'smartystreets_ruby_sdk/us_zipcode'
|
27
27
|
require 'smartystreets_ruby_sdk/us_autocomplete'
|
28
|
+
require 'smartystreets_ruby_sdk/us_autocomplete_pro'
|
28
29
|
require 'smartystreets_ruby_sdk/international_street'
|
30
|
+
require 'smartystreets_ruby_sdk/us_reverse_geo'
|
29
31
|
|
30
32
|
module SmartyStreets
|
31
33
|
end
|
@@ -14,6 +14,8 @@ require_relative 'us_zipcode/client'
|
|
14
14
|
require_relative 'us_extract/client'
|
15
15
|
require_relative 'us_autocomplete/client'
|
16
16
|
require_relative 'international_street/client'
|
17
|
+
require_relative 'us_reverse_geo/client'
|
18
|
+
require_relative 'us_autocomplete_pro/client'
|
17
19
|
|
18
20
|
module SmartyStreets
|
19
21
|
# The ClientBuilder class helps you build a client object for one of the supported SmartyStreets APIs.
|
@@ -22,9 +24,11 @@ module SmartyStreets
|
|
22
24
|
class ClientBuilder
|
23
25
|
INTERNATIONAL_STREET_API_URL = 'https://international-street.api.smartystreets.com/verify'.freeze
|
24
26
|
US_AUTOCOMPLETE_API_URL = 'https://us-autocomplete.api.smartystreets.com/suggest'.freeze
|
27
|
+
US_AUTOCOMPLETE_PRO_API_URL = 'https://us-autocomplete-pro.api.smartystreets.com/lookup'.freeze
|
25
28
|
US_EXTRACT_API_URL = 'https://us-extract.api.smartystreets.com/'.freeze
|
26
29
|
US_STREET_API_URL = 'https://us-street.api.smartystreets.com/street-address'.freeze
|
27
30
|
US_ZIP_CODE_API_URL = 'https://us-zipcode.api.smartystreets.com/lookup'.freeze
|
31
|
+
US_REVERSE_GEO_API_URL = 'https://us-reverse-geo.api.smartystreets.com/lookup'.freeze
|
28
32
|
|
29
33
|
def initialize(signer)
|
30
34
|
@signer = signer
|
@@ -126,6 +130,11 @@ module SmartyStreets
|
|
126
130
|
USAutocomplete::Client.new(build_sender, @serializer)
|
127
131
|
end
|
128
132
|
|
133
|
+
def build_us_autocomplete_pro_api_client
|
134
|
+
ensure_url_prefix_not_null(US_AUTOCOMPLETE_PRO_API_URL)
|
135
|
+
USAutocompletePro::Client.new(build_sender, @serializer)
|
136
|
+
end
|
137
|
+
|
129
138
|
def build_us_extract_api_client
|
130
139
|
ensure_url_prefix_not_null(US_EXTRACT_API_URL)
|
131
140
|
USExtract::Client.new(build_sender, @serializer)
|
@@ -141,6 +150,11 @@ module SmartyStreets
|
|
141
150
|
USZipcode::Client.new(build_sender, @serializer)
|
142
151
|
end
|
143
152
|
|
153
|
+
def build_us_reverse_geo_api_client
|
154
|
+
ensure_url_prefix_not_null(US_REVERSE_GEO_API_URL)
|
155
|
+
USReverseGeo::Client.new(build_sender, @serializer)
|
156
|
+
end
|
157
|
+
|
144
158
|
# </editor-fold>
|
145
159
|
|
146
160
|
def build_sender
|
@@ -50,8 +50,10 @@ module SmartyStreets
|
|
50
50
|
def convert_candidates(raw_candidates)
|
51
51
|
candidates = []
|
52
52
|
|
53
|
-
raw_candidates.
|
54
|
-
|
53
|
+
unless raw_candidates.nil?
|
54
|
+
raw_candidates.each do |candidate|
|
55
|
+
candidates.push(Candidate.new(candidate))
|
56
|
+
end
|
55
57
|
end
|
56
58
|
|
57
59
|
candidates
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require_relative './us_autocomplete_pro/lookup'
|
2
|
+
require_relative './us_autocomplete_pro/geolocation_type'
|
3
|
+
require_relative './us_autocomplete_pro/suggestion'
|
4
|
+
require_relative './us_autocomplete_pro/client'
|
5
|
+
|
6
|
+
module SmartyStreets
|
7
|
+
module USAutocompletePro
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require_relative '../request'
|
2
|
+
require_relative '../exceptions'
|
3
|
+
require_relative 'geolocation_type'
|
4
|
+
require_relative 'suggestion'
|
5
|
+
|
6
|
+
module SmartyStreets
|
7
|
+
module USAutocompletePro
|
8
|
+
# It is recommended to instantiate this class using ClientBuilder.build_us_autocomplete_pro_api_client
|
9
|
+
class Client
|
10
|
+
def initialize(sender, serializer)
|
11
|
+
@sender = sender
|
12
|
+
@serializer = serializer
|
13
|
+
end
|
14
|
+
|
15
|
+
# Sends a Lookup object to the US Autocomplete Pro API and stores the result in the Lookup's result field.
|
16
|
+
def send(lookup)
|
17
|
+
if not lookup or not lookup.search
|
18
|
+
raise SmartyStreets::SmartyError, 'Send() must be passed a Lookup with the prefix field set.'
|
19
|
+
end
|
20
|
+
|
21
|
+
request = build_request(lookup)
|
22
|
+
|
23
|
+
response = @sender.send(request)
|
24
|
+
|
25
|
+
raise response.error if response.error
|
26
|
+
|
27
|
+
result = @serializer.deserialize(response.payload)
|
28
|
+
suggestions = convert_suggestions(result.fetch('suggestions', []))
|
29
|
+
lookup.result = suggestions
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def build_request(lookup)
|
34
|
+
request = Request.new
|
35
|
+
|
36
|
+
add_parameter(request, 'search', lookup.search)
|
37
|
+
add_parameter(request, 'max_results', lookup.max_results.to_s)
|
38
|
+
add_parameter(request, 'include_only_cities', build_filter_string(lookup.city_filter))
|
39
|
+
add_parameter(request, 'include_only_states', build_filter_string(lookup.state_filter))
|
40
|
+
add_parameter(request, 'include_only_zip_codes', build_filter_string(lookup.zip_filter))
|
41
|
+
add_parameter(request, 'exclude_states', build_filter_string(lookup.exclude_states))
|
42
|
+
add_parameter(request, 'prefer_cities', build_filter_string(lookup.prefer_cities))
|
43
|
+
add_parameter(request, 'prefer_states', build_filter_string(lookup.prefer_states))
|
44
|
+
add_parameter(request, 'prefer_zip_codes', build_filter_string(lookup.prefer_zip_codes))
|
45
|
+
add_parameter(request, 'prefer_ratio', lookup.prefer_ratio.to_s)
|
46
|
+
if lookup.prefer_zip_codes or lookup.zip_filter
|
47
|
+
request.parameters['prefer_geolocation'] = GeolocationType::NONE
|
48
|
+
else
|
49
|
+
add_parameter(request, 'prefer_geolocation', lookup.prefer_geolocation)
|
50
|
+
end
|
51
|
+
add_parameter(request, 'selected', lookup.selected)
|
52
|
+
|
53
|
+
request
|
54
|
+
end
|
55
|
+
|
56
|
+
def build_filter_string(filter_list)
|
57
|
+
filter_list ? filter_list.join(',') : nil
|
58
|
+
end
|
59
|
+
|
60
|
+
def convert_suggestions(suggestion_hashes)
|
61
|
+
converted_suggestions = []
|
62
|
+
return converted_suggestions if suggestion_hashes.nil?
|
63
|
+
|
64
|
+
suggestion_hashes.each do |suggestion|
|
65
|
+
converted_suggestions.push(USAutocompletePro::Suggestion.new(suggestion))
|
66
|
+
end
|
67
|
+
|
68
|
+
converted_suggestions
|
69
|
+
end
|
70
|
+
|
71
|
+
def add_parameter(request, key, value)
|
72
|
+
request.parameters[key] = value unless value.nil? or value.empty?
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require_relative '../json_able'
|
2
|
+
|
3
|
+
module SmartyStreets
|
4
|
+
module USAutocompletePro
|
5
|
+
# In addition to holding all of the input data for this lookup, this class also will contain the result
|
6
|
+
# of the lookup after it comes back from the API.
|
7
|
+
#
|
8
|
+
# See "https://smartystreets.com/docs/cloud/us-autocomplete-api#http-request-input-fields"
|
9
|
+
class Lookup < JSONAble
|
10
|
+
|
11
|
+
attr_accessor :result, :search, :max_results, :city_filter, :state_filter, :zip_filter,
|
12
|
+
:exclude_states, :prefer_cities, :prefer_states, :prefer_zip_codes, :prefer_ratio, :prefer_geolocation, :selected
|
13
|
+
|
14
|
+
def initialize(search=nil, max_results=nil, city_filter=nil, state_filter=nil, zip_filter=nil,
|
15
|
+
exclude_states=nil, prefer_cities=nil, prefer_states=nil, prefer_zips=nil, prefer_ratio=nil,
|
16
|
+
prefer_geolocation=nil, selected=nil)
|
17
|
+
@result = []
|
18
|
+
@search = search
|
19
|
+
@max_results = max_results
|
20
|
+
@city_filter = city_filter ? city_filter : []
|
21
|
+
@state_filter = state_filter ? state_filter : []
|
22
|
+
@zip_filter = zip_filter ? zip_filter : []
|
23
|
+
@exclude_states = exclude_states ? exclude_states : []
|
24
|
+
@prefer_cities = prefer_cities ? prefer_cities : []
|
25
|
+
@prefer_states = prefer_states ? prefer_states : []
|
26
|
+
@prefer_zip_codes = prefer_zips ? prefer_zips : []
|
27
|
+
@prefer_ratio = prefer_ratio
|
28
|
+
@prefer_geolocation = prefer_geolocation
|
29
|
+
@selected = selected
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_city_filter(city)
|
33
|
+
@city_filter.push(city)
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_state_filter(state)
|
37
|
+
@state_filter.push(state)
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_zip_filter(zip)
|
41
|
+
@zip_filter.push(zip)
|
42
|
+
end
|
43
|
+
|
44
|
+
def add_state_exclusion(state)
|
45
|
+
@exclude_states.push(state)
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_preferred_city(city)
|
49
|
+
@prefer_cities.push(city)
|
50
|
+
end
|
51
|
+
|
52
|
+
def add_preferred_state(state)
|
53
|
+
@prefer_states.push(state)
|
54
|
+
end
|
55
|
+
|
56
|
+
def add_preferred_zip(zip)
|
57
|
+
@prefer_zip_codes.push(zip)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module SmartyStreets
|
2
|
+
module USAutocompletePro
|
3
|
+
# See "https://smartystreets.com/docs/cloud/us-autocomplete-api#http-response"
|
4
|
+
class Suggestion
|
5
|
+
|
6
|
+
attr_reader :street_line, :secondary, :city, :state, :zipcode, :entries
|
7
|
+
|
8
|
+
def initialize(obj)
|
9
|
+
@street_line = obj.fetch('street_line', nil)
|
10
|
+
@secondary = obj.fetch('secondary', nil)
|
11
|
+
@city = obj.fetch('city', nil)
|
12
|
+
@state = obj.fetch('state', nil)
|
13
|
+
@zipcode = obj.fetch('zipcode', nil)
|
14
|
+
@entries = obj.fetch('entries', 0)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require_relative './us_reverse_geo/address'
|
2
|
+
require_relative './us_reverse_geo/client'
|
3
|
+
require_relative './us_reverse_geo/coordinate'
|
4
|
+
require_relative './us_reverse_geo/lookup'
|
5
|
+
require_relative './us_reverse_geo/result'
|
6
|
+
require_relative './us_reverse_geo/us_reverse_geo_response'
|
7
|
+
|
8
|
+
module SmartyStreets
|
9
|
+
module USReverseGeo
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module SmartyStreets
|
2
|
+
module USReverseGeo
|
3
|
+
# See "https://smartystreets.com/docs/cloud/us-reverse-geo-api#address"
|
4
|
+
class Address
|
5
|
+
attr_reader :street, :city, :state_abbreviation, :zipcode
|
6
|
+
|
7
|
+
def initialize(obj)
|
8
|
+
@street = obj['street']
|
9
|
+
@city = obj['city']
|
10
|
+
@state_abbreviation = obj['state_abbreviation']
|
11
|
+
@zipcode = obj['zipcode']
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative '../request'
|
2
|
+
require_relative 'us_reverse_geo_response'
|
3
|
+
|
4
|
+
module SmartyStreets
|
5
|
+
module USReverseGeo
|
6
|
+
# It is recommended to instantiate this class using ClientBuilder.build_us_reverse_geo_api_client()
|
7
|
+
class Client
|
8
|
+
def initialize(sender, serializer)
|
9
|
+
@sender = sender
|
10
|
+
@serializer = serializer
|
11
|
+
end
|
12
|
+
|
13
|
+
# Sends a Lookup object to the US Reverse Geo API and stores the result in the Lookup's response field.
|
14
|
+
def send(lookup)
|
15
|
+
request = build_request(lookup)
|
16
|
+
|
17
|
+
response = @sender.send(request)
|
18
|
+
|
19
|
+
raise response.error if response.error
|
20
|
+
|
21
|
+
lookup.response = Response.new(@serializer.deserialize(response.payload))
|
22
|
+
end
|
23
|
+
|
24
|
+
def build_request(lookup)
|
25
|
+
request = SmartyStreets::Request.new
|
26
|
+
|
27
|
+
add_parameter(request, 'latitude', lookup.latitude)
|
28
|
+
add_parameter(request, 'longitude', lookup.longitude)
|
29
|
+
|
30
|
+
request
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_parameter(request, key, value)
|
34
|
+
request.parameters[key] = value unless value.nil? or value.empty?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module SmartyStreets
|
2
|
+
module USReverseGeo
|
3
|
+
# See "https://smartystreets.com/docs/cloud/us-reverse-geo-api#coordinate"
|
4
|
+
class Coordinate
|
5
|
+
attr_reader :latitude, :longitude, :accuracy, :license
|
6
|
+
|
7
|
+
def initialize(obj)
|
8
|
+
@latitude = obj.fetch('latitude', nil)
|
9
|
+
@longitude = obj.fetch('longitude', nil)
|
10
|
+
@accuracy = obj.fetch('accuracy', nil)
|
11
|
+
@license = obj.fetch('license', nil)
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_license()
|
15
|
+
case @license
|
16
|
+
when 1
|
17
|
+
return "SmartyStreets Proprietary"
|
18
|
+
else
|
19
|
+
return "SmartyStreets"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module SmartyStreets
|
2
|
+
module USReverseGeo
|
3
|
+
# In addition to holding all of the input data for this lookup, this class also will contain the
|
4
|
+
# result of the lookup after it comes back from the API.
|
5
|
+
#
|
6
|
+
# Note: Lookups must have certain required fields set with non-blank values.
|
7
|
+
# These can be found at the URL below.
|
8
|
+
#
|
9
|
+
# See "https://smartystreets.com/docs/cloud/us-reverse-geo-api#http-request-input-fields"
|
10
|
+
|
11
|
+
class Lookup
|
12
|
+
|
13
|
+
attr_accessor :latitude, :longitude, :response
|
14
|
+
|
15
|
+
def initialize(latitude, longitude)
|
16
|
+
@latitude = sprintf('%.8f', latitude)
|
17
|
+
@longitude = sprintf('%.8f', longitude)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'coordinate'
|
2
|
+
require_relative 'address'
|
3
|
+
|
4
|
+
module SmartyStreets
|
5
|
+
module USReverseGeo
|
6
|
+
# A result is a possible match for an geocode that was submitted. A lookup can have multiple results.
|
7
|
+
#
|
8
|
+
# See "https://smartystreets.com/docs/cloud/us-reverse-geo-api#result"
|
9
|
+
class Result
|
10
|
+
attr_reader :address, :coordinate, :distance
|
11
|
+
|
12
|
+
def initialize(obj)
|
13
|
+
@address = Address.new(obj.fetch('address', {}))
|
14
|
+
@coordinate = Coordinate.new(obj.fetch('coordinate', {}))
|
15
|
+
@distance = obj['distance']
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative 'result'
|
2
|
+
|
3
|
+
module SmartyStreets
|
4
|
+
module USReverseGeo
|
5
|
+
class Response
|
6
|
+
attr_reader :results
|
7
|
+
|
8
|
+
def initialize(obj)
|
9
|
+
@results = []
|
10
|
+
|
11
|
+
obj['results'].each do |result|
|
12
|
+
@results.push(Result.new(result))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -3,19 +3,22 @@ module SmartyStreets
|
|
3
3
|
# See "https://smartystreets.com/docs/cloud/us-street-api#analysis"
|
4
4
|
class Analysis
|
5
5
|
attr_reader :lacs_link_code, :active, :footnotes, :lacs_link_indicator, :dpv_match_code, :is_suite_link_match,
|
6
|
-
:is_ews_match, :dpv_footnotes, :cmra, :vacant
|
6
|
+
:is_ews_match, :dpv_footnotes, :cmra, :vacant, :no_stat, :match_mode, :match_details
|
7
7
|
|
8
8
|
def initialize(obj)
|
9
9
|
@dpv_match_code = obj['dpv_match_code']
|
10
10
|
@dpv_footnotes = obj['dpv_footnotes']
|
11
11
|
@cmra = obj['dpv_cmra']
|
12
12
|
@vacant = obj['dpv_vacant']
|
13
|
+
@no_stat = obj['dpv_no_stat']
|
13
14
|
@active = obj['active']
|
14
15
|
@is_ews_match = obj['ews_match']
|
15
16
|
@footnotes = obj['footnotes']
|
16
17
|
@lacs_link_code = obj['lacslink_code']
|
17
18
|
@lacs_link_indicator = obj['lacslink_indicator']
|
18
19
|
@is_suite_link_match = obj['suitelink_match']
|
20
|
+
@match_mode = obj['match_mode']
|
21
|
+
@match_details = obj['match_details']
|
19
22
|
end
|
20
23
|
end
|
21
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smartystreets_ruby_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SmartyStreets SDK Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -92,7 +92,9 @@ files:
|
|
92
92
|
- docker-compose.yml
|
93
93
|
- examples/international_example.rb
|
94
94
|
- examples/us_autocomplete_example.rb
|
95
|
+
- examples/us_autocomplete_pro_example.rb
|
95
96
|
- examples/us_extract_example.rb
|
97
|
+
- examples/us_reverse_geo_example.rb
|
96
98
|
- examples/us_street_multiple_address_example.rb
|
97
99
|
- examples/us_street_single_address_example.rb
|
98
100
|
- examples/us_zipcode_multiple_lookup_example.rb
|
@@ -133,12 +135,24 @@ files:
|
|
133
135
|
- lib/smartystreets_ruby_sdk/us_autocomplete/geolocation_type.rb
|
134
136
|
- lib/smartystreets_ruby_sdk/us_autocomplete/lookup.rb
|
135
137
|
- lib/smartystreets_ruby_sdk/us_autocomplete/suggestion.rb
|
138
|
+
- lib/smartystreets_ruby_sdk/us_autocomplete_pro.rb
|
139
|
+
- lib/smartystreets_ruby_sdk/us_autocomplete_pro/client.rb
|
140
|
+
- lib/smartystreets_ruby_sdk/us_autocomplete_pro/geolocation_type.rb
|
141
|
+
- lib/smartystreets_ruby_sdk/us_autocomplete_pro/lookup.rb
|
142
|
+
- lib/smartystreets_ruby_sdk/us_autocomplete_pro/suggestion.rb
|
136
143
|
- lib/smartystreets_ruby_sdk/us_extract.rb
|
137
144
|
- lib/smartystreets_ruby_sdk/us_extract/address.rb
|
138
145
|
- lib/smartystreets_ruby_sdk/us_extract/client.rb
|
139
146
|
- lib/smartystreets_ruby_sdk/us_extract/lookup.rb
|
140
147
|
- lib/smartystreets_ruby_sdk/us_extract/metadata.rb
|
141
148
|
- lib/smartystreets_ruby_sdk/us_extract/result.rb
|
149
|
+
- lib/smartystreets_ruby_sdk/us_reverse_geo.rb
|
150
|
+
- lib/smartystreets_ruby_sdk/us_reverse_geo/address.rb
|
151
|
+
- lib/smartystreets_ruby_sdk/us_reverse_geo/client.rb
|
152
|
+
- lib/smartystreets_ruby_sdk/us_reverse_geo/coordinate.rb
|
153
|
+
- lib/smartystreets_ruby_sdk/us_reverse_geo/lookup.rb
|
154
|
+
- lib/smartystreets_ruby_sdk/us_reverse_geo/result.rb
|
155
|
+
- lib/smartystreets_ruby_sdk/us_reverse_geo/us_reverse_geo_response.rb
|
142
156
|
- lib/smartystreets_ruby_sdk/us_street.rb
|
143
157
|
- lib/smartystreets_ruby_sdk/us_street/analysis.rb
|
144
158
|
- lib/smartystreets_ruby_sdk/us_street/candidate.rb
|