smartystreets_ruby_sdk 5.9.1 → 5.11.2
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 +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 +5 -1
- 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 +1 -0
- data/lib/smartystreets_ruby_sdk/client_builder.rb +7 -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_street/analysis.rb +3 -1
- data/lib/smartystreets_ruby_sdk/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cab0fb9db3564b7caedea4931eafe8e57a5ada51972384880bc1a4a039a7ab7
|
4
|
+
data.tar.gz: 41de034cf22edcc134ff1b03bbef740235d78703e873e3c195cdcb4df890b5af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68c005e8b8998c1fb75360740c749a5b55062aeb6ba7d32820e4da91794b0d2dece81c04f6021e2a9f4802b0f2ed9c9dfdf4111157ed973971352b656da1a261
|
7
|
+
data.tar.gz: 9d38f269c9203f7d5845ee1c04454ed5cf89ef846b4a07a189fcd74a229b9eb4e7b5df25355dfb4783ee0d09d1701b27ba7b31d864c45a6e5230af7063a12505
|
@@ -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(['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(['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
|
+
|
@@ -14,7 +14,11 @@ class USReverseGeoExample
|
|
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(['us-reverse-geocoding-cloud'])
|
18
22
|
.build_us_reverse_geo_api_client
|
19
23
|
|
20
24
|
# Documentation for input fields can be found at:
|
@@ -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(['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(['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,6 +25,7 @@ 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'
|
29
30
|
require 'smartystreets_ruby_sdk/us_reverse_geo'
|
30
31
|
|
@@ -15,6 +15,7 @@ require_relative 'us_extract/client'
|
|
15
15
|
require_relative 'us_autocomplete/client'
|
16
16
|
require_relative 'international_street/client'
|
17
17
|
require_relative 'us_reverse_geo/client'
|
18
|
+
require_relative 'us_autocomplete_pro/client'
|
18
19
|
|
19
20
|
module SmartyStreets
|
20
21
|
# The ClientBuilder class helps you build a client object for one of the supported SmartyStreets APIs.
|
@@ -23,6 +24,7 @@ module SmartyStreets
|
|
23
24
|
class ClientBuilder
|
24
25
|
INTERNATIONAL_STREET_API_URL = 'https://international-street.api.smartystreets.com/verify'.freeze
|
25
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
|
26
28
|
US_EXTRACT_API_URL = 'https://us-extract.api.smartystreets.com/'.freeze
|
27
29
|
US_STREET_API_URL = 'https://us-street.api.smartystreets.com/street-address'.freeze
|
28
30
|
US_ZIP_CODE_API_URL = 'https://us-zipcode.api.smartystreets.com/lookup'.freeze
|
@@ -128,6 +130,11 @@ module SmartyStreets
|
|
128
130
|
USAutocomplete::Client.new(build_sender, @serializer)
|
129
131
|
end
|
130
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
|
+
|
131
138
|
def build_us_extract_api_client
|
132
139
|
ensure_url_prefix_not_null(US_EXTRACT_API_URL)
|
133
140
|
USExtract::Client.new(build_sender, @serializer)
|
@@ -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
|
@@ -3,19 +3,21 @@ 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, :enhanced_match
|
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
|
+
@enhanced_match = obj['enhanced_match']
|
19
21
|
end
|
20
22
|
end
|
21
23
|
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.2
|
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-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -92,6 +92,7 @@ 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
|
96
97
|
- examples/us_reverse_geo_example.rb
|
97
98
|
- examples/us_street_multiple_address_example.rb
|
@@ -134,6 +135,11 @@ files:
|
|
134
135
|
- lib/smartystreets_ruby_sdk/us_autocomplete/geolocation_type.rb
|
135
136
|
- lib/smartystreets_ruby_sdk/us_autocomplete/lookup.rb
|
136
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
|
137
143
|
- lib/smartystreets_ruby_sdk/us_extract.rb
|
138
144
|
- lib/smartystreets_ruby_sdk/us_extract/address.rb
|
139
145
|
- lib/smartystreets_ruby_sdk/us_extract/client.rb
|