smartystreets_ruby_sdk 5.11.2 → 5.14.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 +4 -4
- data/examples/international_autocomplete_example.rb +47 -0
- data/examples/us_autocomplete_pro_example.rb +1 -0
- data/examples/us_street_multiple_address_example.rb +1 -1
- data/examples/us_street_single_address_example.rb +1 -1
- data/lib/smartystreets_ruby_sdk/client_builder.rb +7 -1
- data/lib/smartystreets_ruby_sdk/international_autocomplete/client.rb +61 -0
- data/lib/smartystreets_ruby_sdk/international_autocomplete/lookup.rb +21 -0
- data/lib/smartystreets_ruby_sdk/international_autocomplete/suggestion.rb +16 -0
- data/lib/smartystreets_ruby_sdk/us_autocomplete_pro/client.rb +1 -0
- data/lib/smartystreets_ruby_sdk/us_autocomplete_pro/lookup.rb +4 -2
- data/lib/smartystreets_ruby_sdk/us_street/match_type.rb +2 -1
- data/lib/smartystreets_ruby_sdk/version.rb +1 -1
- data/smartystreets_ruby_sdk.gemspec +2 -2
- metadata +15 -12
- data/examples/us_autocomplete_example.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb354ac31fa7cc2bd045b1bb7877e8a0daf5b491d3863d23ea27ace3f38ed637
|
4
|
+
data.tar.gz: 86ad9f8c1371467d314f59e0f7f7588e5c66d10fcf4d6ba039cdf7afedfa6295
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85550fb289d9a64084aaa321f7d71a13f95c6d2bd116e6ac81728c3ad12030182778899a00659124957975875c11b5c5d49b24ffa62feb09b1c712f114f82651
|
7
|
+
data.tar.gz: e3af8c142b7dbadae883ccb9b3af2e62cf37c242c3fe6dd214df13bfe1f1cbe0d1b993d695bbbb678fdf1a5ce8d529e58c9c8dba8bf15ca35296d8d8927c188a
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'smartystreets_ruby_sdk/shared_credentials'
|
2
|
+
require '../lib/smartystreets_ruby_sdk/client_builder'
|
3
|
+
require '../lib/smartystreets_ruby_sdk/international_autocomplete/lookup'
|
4
|
+
require '../lib/smartystreets_ruby_sdk/international_autocomplete/client'
|
5
|
+
|
6
|
+
class USAutocompleteProExample
|
7
|
+
Lookup = SmartyStreets::InternationalAutocomplete::Lookup
|
8
|
+
|
9
|
+
def run
|
10
|
+
# key = 'Your SmartyStreets Auth ID here'
|
11
|
+
# hostname = 'Your SmartyStreets Auth Token here'
|
12
|
+
|
13
|
+
# We recommend storing your secret keys in environment variables instead---it's safer!
|
14
|
+
key = ENV['SMARTY_AUTH_WEB']
|
15
|
+
referer = ENV['SMARTY_AUTH_REFERER']
|
16
|
+
|
17
|
+
credentials = SmartyStreets::SharedCredentials.new(key, referer)
|
18
|
+
|
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(['international-autocomplete-cloud'])
|
23
|
+
.build_international_autocomplete_api_client
|
24
|
+
|
25
|
+
# Documentation for input fields can be found at:
|
26
|
+
# https://smartystreets.com/docs/cloud/us-autocomplete-api
|
27
|
+
|
28
|
+
lookup = Lookup.new('Louis')
|
29
|
+
lookup.country = "FRA"
|
30
|
+
lookup.locality = "Paris"
|
31
|
+
|
32
|
+
suggestions = client.send(lookup) # The client will also return the suggestions directly
|
33
|
+
|
34
|
+
puts
|
35
|
+
puts '*** Result with some filters ***'
|
36
|
+
puts
|
37
|
+
|
38
|
+
suggestions.each do |suggestion|
|
39
|
+
puts "#{suggestion.street} #{suggestion.locality}, #{suggestion.country_iso3}"
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
USAutocompleteProExample.new.run
|
46
|
+
|
47
|
+
|
@@ -36,7 +36,7 @@ class USStreetMultipleAddressExample
|
|
36
36
|
batch[0].lastline = 'Mountain view, California'
|
37
37
|
batch[0].zipcode = '21229'
|
38
38
|
batch[0].candidates = 3
|
39
|
-
batch[0].match =
|
39
|
+
batch[0].match = Lookup.INVALID # "invalid" is the most permissive match,
|
40
40
|
# this will always return at least one result even if the address is invalid.
|
41
41
|
# Refer to the documentation for additional Match Strategy options.
|
42
42
|
|
@@ -34,7 +34,7 @@ class USStreetSingleAddressExample
|
|
34
34
|
lookup.state = 'CA'
|
35
35
|
lookup.zipcode = '21229'
|
36
36
|
lookup.candidates = 3
|
37
|
-
lookup.match =
|
37
|
+
lookup.match = Lookup.INVALID # "invalid" is the most permissive match,
|
38
38
|
# this will always return at least one result even if the address is invalid.
|
39
39
|
# Refer to the documentation for additional Match Strategy options.
|
40
40
|
|
@@ -23,6 +23,7 @@ module SmartyStreets
|
|
23
23
|
# These methods are chainable, so you can usually get set up with one line of code.
|
24
24
|
class ClientBuilder
|
25
25
|
INTERNATIONAL_STREET_API_URL = 'https://international-street.api.smartystreets.com/verify'.freeze
|
26
|
+
INTERNATIONAL_AUTOCOMPLETE_API_URL = "https://international-autocomplete.api.smartystreets.com/lookup".freeze
|
26
27
|
US_AUTOCOMPLETE_API_URL = 'https://us-autocomplete.api.smartystreets.com/suggest'.freeze
|
27
28
|
US_AUTOCOMPLETE_PRO_API_URL = 'https://us-autocomplete-pro.api.smartystreets.com/lookup'.freeze
|
28
29
|
US_EXTRACT_API_URL = 'https://us-extract.api.smartystreets.com/'.freeze
|
@@ -125,7 +126,12 @@ module SmartyStreets
|
|
125
126
|
InternationalStreet::Client.new(build_sender, @serializer)
|
126
127
|
end
|
127
128
|
|
128
|
-
def
|
129
|
+
def build_international_autocomplete_api_client
|
130
|
+
ensure_url_prefix_not_null(INTERNATIONAL_AUTOCOMPLETE_API_URL)
|
131
|
+
InternationalAutocomplete::Client.new(build_sender, @serializer)
|
132
|
+
end
|
133
|
+
|
134
|
+
def build_us_autocomplete_api_client # Deprecated
|
129
135
|
ensure_url_prefix_not_null(US_AUTOCOMPLETE_API_URL)
|
130
136
|
USAutocomplete::Client.new(build_sender, @serializer)
|
131
137
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require_relative '../request'
|
2
|
+
require_relative '../exceptions'
|
3
|
+
require_relative 'suggestion'
|
4
|
+
|
5
|
+
module SmartyStreets
|
6
|
+
module InternationalAutocomplete
|
7
|
+
# It is recommended to instantiate this class using ClientBuilder.build_international_autocomplete_api_client
|
8
|
+
class Client
|
9
|
+
def initialize(sender, serializer)
|
10
|
+
@sender = sender
|
11
|
+
@serializer = serializer
|
12
|
+
end
|
13
|
+
|
14
|
+
# Sends a Lookup object to the International Autocomplete API and stores the result in the Lookup's result field.
|
15
|
+
def send(lookup)
|
16
|
+
if not lookup or not lookup.search
|
17
|
+
raise SmartyStreets::SmartyError, 'Send() must be passed a Lookup with the prefix field set.'
|
18
|
+
end
|
19
|
+
|
20
|
+
request = build_request(lookup)
|
21
|
+
|
22
|
+
response = @sender.send(request)
|
23
|
+
|
24
|
+
raise response.error if response.error
|
25
|
+
|
26
|
+
result = @serializer.deserialize(response.payload)
|
27
|
+
suggestions = convert_suggestions(result)
|
28
|
+
lookup.result = suggestions
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def build_request(lookup)
|
33
|
+
request = Request.new
|
34
|
+
|
35
|
+
add_parameter(request, 'search', lookup.search)
|
36
|
+
add_parameter(request, 'country', lookup.country)
|
37
|
+
add_parameter(request, 'include_only_administrative_area', lookup.administrative_area)
|
38
|
+
add_parameter(request, 'include_only_locality', lookup.locality)
|
39
|
+
add_parameter(request, 'include_only_postal_code', lookup.postal_code)
|
40
|
+
|
41
|
+
request
|
42
|
+
end
|
43
|
+
|
44
|
+
def convert_suggestions(suggestion_hashes)
|
45
|
+
converted_suggestions = []
|
46
|
+
return converted_suggestions if suggestion_hashes.nil?
|
47
|
+
|
48
|
+
suggestion_hashes.each do |suggestion|
|
49
|
+
converted_suggestions.push(InternationalAutocomplete::Suggestion.new(suggestion))
|
50
|
+
end
|
51
|
+
|
52
|
+
converted_suggestions
|
53
|
+
end
|
54
|
+
|
55
|
+
def add_parameter(request, key, value)
|
56
|
+
request.parameters[key] = value unless value.nil? or value.empty?
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative '../json_able'
|
2
|
+
|
3
|
+
module SmartyStreets
|
4
|
+
module InternationalAutocomplete
|
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
|
+
class Lookup < JSONAble
|
8
|
+
|
9
|
+
attr_accessor :result, :search, :country, :administrative_area, :locality, :postal_code
|
10
|
+
|
11
|
+
def initialize(search=nil, country=nil, administrative_area=nil, locality=nil, postal_code=nil)
|
12
|
+
@result = []
|
13
|
+
@search = search
|
14
|
+
@country = country
|
15
|
+
@administrative_area = administrative_area
|
16
|
+
@locality = locality
|
17
|
+
@postal_code = postal_code
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module SmartyStreets
|
2
|
+
module InternationalAutocomplete
|
3
|
+
class Suggestion
|
4
|
+
|
5
|
+
attr_reader :street, :locality, :administrative_area, :postal_code, :country_iso3
|
6
|
+
|
7
|
+
def initialize(obj)
|
8
|
+
@street = obj.fetch('street', nil)
|
9
|
+
@locality = obj.fetch('locality', nil)
|
10
|
+
@administrative_area = obj.fetch('administrative_area', nil)
|
11
|
+
@postal_code = obj.fetch('postal_code', nil)
|
12
|
+
@country_iso3 = obj.fetch('country_iso3', nil)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -43,6 +43,7 @@ module SmartyStreets
|
|
43
43
|
add_parameter(request, 'prefer_states', build_filter_string(lookup.prefer_states))
|
44
44
|
add_parameter(request, 'prefer_zip_codes', build_filter_string(lookup.prefer_zip_codes))
|
45
45
|
add_parameter(request, 'prefer_ratio', lookup.prefer_ratio.to_s)
|
46
|
+
add_parameter(request, 'source', lookup.source)
|
46
47
|
if lookup.prefer_zip_codes or lookup.zip_filter
|
47
48
|
request.parameters['prefer_geolocation'] = GeolocationType::NONE
|
48
49
|
else
|
@@ -9,11 +9,12 @@ module SmartyStreets
|
|
9
9
|
class Lookup < JSONAble
|
10
10
|
|
11
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,
|
12
|
+
:exclude_states, :prefer_cities, :prefer_states, :prefer_zip_codes, :prefer_ratio,
|
13
|
+
:prefer_geolocation, :selected, :source
|
13
14
|
|
14
15
|
def initialize(search=nil, max_results=nil, city_filter=nil, state_filter=nil, zip_filter=nil,
|
15
16
|
exclude_states=nil, prefer_cities=nil, prefer_states=nil, prefer_zips=nil, prefer_ratio=nil,
|
16
|
-
prefer_geolocation=nil, selected=nil)
|
17
|
+
prefer_geolocation=nil, selected=nil, source=nil)
|
17
18
|
@result = []
|
18
19
|
@search = search
|
19
20
|
@max_results = max_results
|
@@ -27,6 +28,7 @@ module SmartyStreets
|
|
27
28
|
@prefer_ratio = prefer_ratio
|
28
29
|
@prefer_geolocation = prefer_geolocation
|
29
30
|
@selected = selected
|
31
|
+
@source = source
|
30
32
|
end
|
31
33
|
|
32
34
|
def add_city_filter(city)
|
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_development_dependency 'bundler', '~>
|
23
|
-
spec.add_development_dependency 'rake', '~>
|
22
|
+
spec.add_development_dependency 'bundler', '~> 2.2.27'
|
23
|
+
spec.add_development_dependency 'rake', '~> 12.3.3'
|
24
24
|
spec.add_development_dependency 'minitest', '~> 5.8', '>= 5.8.3'
|
25
25
|
spec.add_development_dependency 'simplecov', '~> 0.12.0'
|
26
26
|
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.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SmartyStreets SDK Team
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.2.27
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.2.27
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,7 +72,7 @@ dependencies:
|
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: 0.12.0
|
75
|
-
description:
|
75
|
+
description:
|
76
76
|
email:
|
77
77
|
- support@smartystreets.com
|
78
78
|
executables: []
|
@@ -90,8 +90,8 @@ files:
|
|
90
90
|
- bin/console
|
91
91
|
- bin/setup
|
92
92
|
- docker-compose.yml
|
93
|
+
- examples/international_autocomplete_example.rb
|
93
94
|
- examples/international_example.rb
|
94
|
-
- examples/us_autocomplete_example.rb
|
95
95
|
- examples/us_autocomplete_pro_example.rb
|
96
96
|
- examples/us_extract_example.rb
|
97
97
|
- examples/us_reverse_geo_example.rb
|
@@ -105,6 +105,9 @@ files:
|
|
105
105
|
- lib/smartystreets_ruby_sdk/custom_header_sender.rb
|
106
106
|
- lib/smartystreets_ruby_sdk/errors.rb
|
107
107
|
- lib/smartystreets_ruby_sdk/exceptions.rb
|
108
|
+
- lib/smartystreets_ruby_sdk/international_autocomplete/client.rb
|
109
|
+
- lib/smartystreets_ruby_sdk/international_autocomplete/lookup.rb
|
110
|
+
- lib/smartystreets_ruby_sdk/international_autocomplete/suggestion.rb
|
108
111
|
- lib/smartystreets_ruby_sdk/international_street.rb
|
109
112
|
- lib/smartystreets_ruby_sdk/international_street/analysis.rb
|
110
113
|
- lib/smartystreets_ruby_sdk/international_street/candidate.rb
|
@@ -175,7 +178,7 @@ homepage: https://github.com/smartystreets/smartystreets-ruby-sdk
|
|
175
178
|
licenses:
|
176
179
|
- Apache-2.0
|
177
180
|
metadata: {}
|
178
|
-
post_install_message:
|
181
|
+
post_install_message:
|
179
182
|
rdoc_options: []
|
180
183
|
require_paths:
|
181
184
|
- lib
|
@@ -190,8 +193,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
193
|
- !ruby/object:Gem::Version
|
191
194
|
version: '0'
|
192
195
|
requirements: []
|
193
|
-
rubygems_version: 3.
|
194
|
-
signing_key:
|
196
|
+
rubygems_version: 3.2.22
|
197
|
+
signing_key:
|
195
198
|
specification_version: 4
|
196
199
|
summary: An official library for the SmartyStreets APIs
|
197
200
|
test_files: []
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'smartystreets_ruby_sdk/static_credentials'
|
2
|
-
require 'smartystreets_ruby_sdk/client_builder'
|
3
|
-
require 'smartystreets_ruby_sdk/us_autocomplete/lookup'
|
4
|
-
|
5
|
-
class USAutocompleteExample
|
6
|
-
Lookup = SmartyStreets::USAutocomplete::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
|
-
client = SmartyStreets::ClientBuilder.new(credentials).build_us_autocomplete_api_client
|
18
|
-
|
19
|
-
# Documentation for input fields can be found at:
|
20
|
-
# https://smartystreets.com/docs/cloud/us-autocomplete-api
|
21
|
-
|
22
|
-
lookup = Lookup.new('4770 Lincoln Ave O')
|
23
|
-
lookup.max_suggestions = 10
|
24
|
-
|
25
|
-
client.send(lookup)
|
26
|
-
|
27
|
-
puts '*** Result with no filter ***'
|
28
|
-
puts
|
29
|
-
lookup.result.each do |suggestion|
|
30
|
-
puts suggestion.text
|
31
|
-
end
|
32
|
-
|
33
|
-
lookup.add_city_filter('Ogden')
|
34
|
-
lookup.add_state_filter('IL')
|
35
|
-
lookup.add_prefer('Ogden, IL')
|
36
|
-
lookup.max_suggestions = 5
|
37
|
-
lookup.prefer_ratio = 0.333333
|
38
|
-
|
39
|
-
suggestions = client.send(lookup) # The client will also return the suggestions directly
|
40
|
-
|
41
|
-
puts
|
42
|
-
puts '*** Result with some filters ***'
|
43
|
-
puts
|
44
|
-
|
45
|
-
suggestions.each do |suggestion|
|
46
|
-
puts suggestion.text
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
USAutocompleteExample.new.run
|