smartystreets_ruby_sdk 5.9.2 → 5.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/us_autocomplete_pro_example.rb +43 -0
- data/lib/smartystreets_ruby_sdk.rb +1 -0
- data/lib/smartystreets_ruby_sdk/client_builder.rb +7 -0
- 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 +2 -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: f89f84d4011a28b76ab8d465d6739df79e5a1627913aba1727a86db053e3af30
|
4
|
+
data.tar.gz: 4a14fd611da96954d6741aa14298f86e6348deeae245306d10eb52630f23a670
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e2d508cb7906c19db797a60feb00adbd5e132e4aadd2b656b7e362253a74308a1e792bef5e8216b2e1bb741ccd5228a86e329ea16835151d1cf094b5097dbe7
|
7
|
+
data.tar.gz: 7bf6945deeb19c48e22bd3f5aa78b42e5aa4a678a977c6a9aeef00fa4457423e7748e69e8a4f4f9798683c618e2a24c2b55f632f86c50d2541b03717f8f382bf
|
@@ -0,0 +1,43 @@
|
|
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
|
+
client = SmartyStreets::ClientBuilder.new(credentials).build_us_autocomplete_pro_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_results = 10
|
24
|
+
lookup.add_city_filter('Ogden')
|
25
|
+
lookup.add_state_filter('IL')
|
26
|
+
lookup.max_results = 5
|
27
|
+
lookup.prefer_ratio = 3
|
28
|
+
|
29
|
+
suggestions = client.send(lookup) # The client will also return the suggestions directly
|
30
|
+
|
31
|
+
puts
|
32
|
+
puts '*** Result with some filters ***'
|
33
|
+
puts
|
34
|
+
|
35
|
+
suggestions.each do |suggestion|
|
36
|
+
puts "#{suggestion.street_line} #{suggestion.city}, #{suggestion.state}"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
USAutocompleteProExample.new.run
|
43
|
+
|
@@ -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)
|
@@ -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,13 +3,14 @@ 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
|
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']
|
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.10.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-03-23 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
|