smartystreets_ruby_sdk 6.4.1 → 10.0.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/.claude/settings.json +18 -0
- data/.github/workflows/ci.yml +10 -0
- data/.github/workflows/publish.yml +29 -0
- data/.github/workflows/test.yml +21 -0
- data/CLAUDE.md +73 -0
- data/Makefile +11 -5
- data/README.md +2 -0
- data/examples/international_autocomplete_example.rb +10 -7
- data/examples/international_example.rb +7 -6
- data/examples/international_postal_code_example.rb +5 -4
- data/examples/us_autocomplete_example.rb +69 -0
- data/examples/us_autocomplete_pro_example.rb +10 -12
- data/examples/us_enrichment_business_example.rb +72 -0
- data/examples/us_enrichment_business_name_search_example.rb +76 -0
- data/examples/us_enrichment_etag_example.rb +130 -0
- data/examples/us_enrichment_example.rb +130 -44
- data/examples/us_extract_example.rb +7 -6
- data/examples/us_reverse_geo_example.rb +10 -6
- data/examples/us_street_component_analysis_example.rb +2 -1
- data/examples/us_street_iana_timezone_example.rb +54 -0
- data/examples/us_street_match_strategy_example.rb +85 -0
- data/examples/us_street_multiple_address_example.rb +7 -6
- data/examples/us_street_single_address_example.rb +7 -6
- data/examples/us_zipcode_multiple_lookup_example.rb +7 -6
- data/examples/us_zipcode_single_lookup_example.rb +7 -6
- data/lib/smartystreets_ruby_sdk/basic_auth_credentials.rb +14 -0
- data/lib/smartystreets_ruby_sdk/client_builder.rb +36 -5
- data/lib/smartystreets_ruby_sdk/custom_header_sender.rb +16 -2
- data/lib/smartystreets_ruby_sdk/errors.rb +16 -11
- data/lib/smartystreets_ruby_sdk/exceptions.rb +12 -0
- data/lib/smartystreets_ruby_sdk/international_autocomplete/client.rb +2 -0
- data/lib/smartystreets_ruby_sdk/international_autocomplete/lookup.rb +4 -2
- data/lib/smartystreets_ruby_sdk/international_street/client.rb +10 -1
- data/lib/smartystreets_ruby_sdk/international_street/components.rb +8 -3
- data/lib/smartystreets_ruby_sdk/international_street/language_mode.rb +20 -3
- data/lib/smartystreets_ruby_sdk/international_street/lookup.rb +5 -12
- data/lib/smartystreets_ruby_sdk/international_street/rootlevel.rb +1 -5
- data/lib/smartystreets_ruby_sdk/native_sender.rb +3 -4
- data/lib/smartystreets_ruby_sdk/native_serializer.rb +1 -0
- data/lib/smartystreets_ruby_sdk/request.rb +2 -1
- data/lib/smartystreets_ruby_sdk/response.rb +13 -0
- data/lib/smartystreets_ruby_sdk/retry_sender.rb +32 -13
- data/lib/smartystreets_ruby_sdk/status_code_sender.rb +39 -22
- data/lib/smartystreets_ruby_sdk/us_autocomplete/client.rb +82 -0
- data/lib/smartystreets_ruby_sdk/us_autocomplete/geolocation_type.rb +8 -0
- data/lib/smartystreets_ruby_sdk/us_autocomplete/lookup.rb +73 -0
- data/lib/smartystreets_ruby_sdk/us_autocomplete/source_type.rb +8 -0
- data/lib/smartystreets_ruby_sdk/us_autocomplete/suggestion.rb +22 -0
- data/lib/smartystreets_ruby_sdk/us_autocomplete.rb +10 -0
- data/lib/smartystreets_ruby_sdk/us_autocomplete_pro/source_type.rb +8 -0
- data/lib/smartystreets_ruby_sdk/us_autocomplete_pro.rb +1 -0
- data/lib/smartystreets_ruby_sdk/us_enrichment/business/detail/attributes.rb +241 -0
- data/lib/smartystreets_ruby_sdk/us_enrichment/business/detail/response.rb +20 -0
- data/lib/smartystreets_ruby_sdk/us_enrichment/business/summary/business_entry.rb +16 -0
- data/lib/smartystreets_ruby_sdk/us_enrichment/business/summary/response.rb +24 -0
- data/lib/smartystreets_ruby_sdk/us_enrichment/client.rb +99 -30
- data/lib/smartystreets_ruby_sdk/us_enrichment/geo_reference/response.rb +2 -3
- data/lib/smartystreets_ruby_sdk/us_enrichment/lookup.rb +42 -9
- data/lib/smartystreets_ruby_sdk/us_enrichment/property/principal/response.rb +3 -4
- data/lib/smartystreets_ruby_sdk/us_enrichment/secondary/count/response.rb +2 -3
- data/lib/smartystreets_ruby_sdk/us_enrichment/secondary/response.rb +2 -3
- data/lib/smartystreets_ruby_sdk/us_enrichment.rb +6 -5
- data/lib/smartystreets_ruby_sdk/us_reverse_geo/source_type.rb +8 -0
- data/lib/smartystreets_ruby_sdk/us_reverse_geo/us_reverse_geo_response.rb +1 -1
- data/lib/smartystreets_ruby_sdk/us_reverse_geo.rb +1 -0
- data/lib/smartystreets_ruby_sdk/us_street/candidate.rb +2 -1
- data/lib/smartystreets_ruby_sdk/us_street/client.rb +10 -3
- data/lib/smartystreets_ruby_sdk/us_street/metadata.rb +5 -1
- data/lib/smartystreets_ruby_sdk/version.rb +1 -1
- data/lib/smartystreets_ruby_sdk.rb +2 -0
- metadata +27 -6
- data/.github/workflows/gem-publish.yml +0 -27
- data/lib/smartystreets_ruby_sdk/us_enrichment/risk/attributes.rb +0 -524
- data/lib/smartystreets_ruby_sdk/us_enrichment/risk/response.rb +0 -19
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
require '../lib/smartystreets_ruby_sdk/static_credentials'
|
|
2
|
+
require '../lib/smartystreets_ruby_sdk/shared_credentials'
|
|
3
|
+
require '../lib/smartystreets_ruby_sdk/basic_auth_credentials'
|
|
4
|
+
require '../lib/smartystreets_ruby_sdk/client_builder'
|
|
5
|
+
require '../lib/smartystreets_ruby_sdk/us_enrichment/lookup'
|
|
6
|
+
|
|
7
|
+
class USEnrichmentEtagExample
|
|
8
|
+
def run
|
|
9
|
+
id = ENV['SMARTY_AUTH_ID']
|
|
10
|
+
token = ENV['SMARTY_AUTH_TOKEN']
|
|
11
|
+
credentials = SmartyStreets::BasicAuthCredentials.new(id, token)
|
|
12
|
+
|
|
13
|
+
@client = SmartyStreets::ClientBuilder.new(credentials).build_us_enrichment_api_client
|
|
14
|
+
smarty_key = "1962995076"
|
|
15
|
+
|
|
16
|
+
business_id = exercise_summary_etag(smarty_key)
|
|
17
|
+
return if business_id.nil?
|
|
18
|
+
|
|
19
|
+
exercise_detail_etag(business_id)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def exercise_summary_etag(smarty_key)
|
|
23
|
+
puts "=== Business.Summary ETag round trip ==="
|
|
24
|
+
|
|
25
|
+
first = SmartyStreets::USEnrichment::Lookup.new(smarty_key, 'business')
|
|
26
|
+
begin
|
|
27
|
+
initial_results = @client.send_business_lookup(first)
|
|
28
|
+
rescue SmartyStreets::SmartyError => err
|
|
29
|
+
puts " Initial Summary call failed: #{err.message}"
|
|
30
|
+
return nil
|
|
31
|
+
end
|
|
32
|
+
captured_etag = first.response_etag
|
|
33
|
+
puts " Call 1 (no Etag): captured Etag=#{display(captured_etag)}, results=#{initial_results.nil? ? 0 : initial_results.length}"
|
|
34
|
+
|
|
35
|
+
if captured_etag.nil? || captured_etag.empty?
|
|
36
|
+
puts " Server did not return an Etag header; skipping conditional calls."
|
|
37
|
+
return first_business_id(initial_results)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
second = SmartyStreets::USEnrichment::Lookup.new(smarty_key, 'business')
|
|
41
|
+
second.request_etag = captured_etag
|
|
42
|
+
begin
|
|
43
|
+
results = @client.send_business_lookup(second)
|
|
44
|
+
if results.empty?
|
|
45
|
+
puts " Call 2 (matching Etag): 304 not modified - cache is still valid. Refreshed Etag=#{display(second.response_etag)}"
|
|
46
|
+
else
|
|
47
|
+
puts " Call 2 (matching Etag): 200 - server did NOT honor the conditional. Etag=#{display(second.response_etag)}"
|
|
48
|
+
end
|
|
49
|
+
rescue SmartyStreets::SmartyError => err
|
|
50
|
+
puts " Call 2 unexpected failure: #{err.class}: #{err.message}"
|
|
51
|
+
return nil
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
third = SmartyStreets::USEnrichment::Lookup.new(smarty_key, 'business')
|
|
55
|
+
third.request_etag = captured_etag + "X"
|
|
56
|
+
begin
|
|
57
|
+
results = @client.send_business_lookup(third)
|
|
58
|
+
if results.empty?
|
|
59
|
+
puts " Call 3 (mutated Etag): 304 - UNEXPECTED. Server treated a different Etag as matching."
|
|
60
|
+
else
|
|
61
|
+
puts " Call 3 (mutated Etag): 200 as expected. Etag=#{display(third.response_etag)}"
|
|
62
|
+
end
|
|
63
|
+
rescue SmartyStreets::SmartyError => err
|
|
64
|
+
puts " Call 3 unexpected failure: #{err.class}: #{err.message}"
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
first_business_id(initial_results)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def exercise_detail_etag(business_id)
|
|
71
|
+
puts
|
|
72
|
+
puts "=== Business.Detail ETag round trip (businessId: #{business_id}) ==="
|
|
73
|
+
|
|
74
|
+
first = SmartyStreets::USEnrichment::BusinessDetailLookup.new(business_id)
|
|
75
|
+
begin
|
|
76
|
+
initial_result = @client.send_business_detail_lookup(first)
|
|
77
|
+
rescue SmartyStreets::SmartyError => err
|
|
78
|
+
puts " Initial Detail call failed: #{err.message}"
|
|
79
|
+
return
|
|
80
|
+
end
|
|
81
|
+
captured_etag = first.response_etag
|
|
82
|
+
puts " Call 1 (no Etag): captured Etag=#{display(captured_etag)}, businessId=#{initial_result ? initial_result.business_id : '<nil>'}"
|
|
83
|
+
|
|
84
|
+
if captured_etag.nil? || captured_etag.empty?
|
|
85
|
+
puts " Server did not return an Etag header; skipping conditional calls."
|
|
86
|
+
return
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
second = SmartyStreets::USEnrichment::BusinessDetailLookup.new(business_id)
|
|
90
|
+
second.request_etag = captured_etag
|
|
91
|
+
begin
|
|
92
|
+
@client.send_business_detail_lookup(second)
|
|
93
|
+
if second.result.nil?
|
|
94
|
+
puts " Call 2 (matching Etag): 304 not modified - cache is still valid. Refreshed Etag=#{display(second.response_etag)}"
|
|
95
|
+
else
|
|
96
|
+
puts " Call 2 (matching Etag): 200 - server did NOT honor the conditional. Etag=#{display(second.response_etag)}"
|
|
97
|
+
end
|
|
98
|
+
rescue SmartyStreets::SmartyError => err
|
|
99
|
+
puts " Call 2 unexpected failure: #{err.class}: #{err.message}"
|
|
100
|
+
return
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
third = SmartyStreets::USEnrichment::BusinessDetailLookup.new(business_id)
|
|
104
|
+
third.request_etag = captured_etag + "X"
|
|
105
|
+
begin
|
|
106
|
+
@client.send_business_detail_lookup(third)
|
|
107
|
+
if third.result.nil?
|
|
108
|
+
puts " Call 3 (mutated Etag): 304 - UNEXPECTED. Server treated a different Etag as matching."
|
|
109
|
+
else
|
|
110
|
+
puts " Call 3 (mutated Etag): 200 as expected. Etag=#{display(third.response_etag)}"
|
|
111
|
+
end
|
|
112
|
+
rescue SmartyStreets::SmartyError => err
|
|
113
|
+
puts " Call 3 unexpected failure: #{err.class}: #{err.message}"
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def first_business_id(summary_results)
|
|
118
|
+
return nil if summary_results.nil? || summary_results.empty?
|
|
119
|
+
first = summary_results[0]
|
|
120
|
+
return nil if first.businesses.nil? || first.businesses.empty?
|
|
121
|
+
first.businesses[0].business_id
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def display(value)
|
|
125
|
+
value.nil? || value.empty? ? "<none>" : value
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
example = USEnrichmentEtagExample.new
|
|
130
|
+
example.run
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
require '../lib/smartystreets_ruby_sdk/static_credentials'
|
|
2
2
|
require '../lib/smartystreets_ruby_sdk/shared_credentials'
|
|
3
|
+
require '../lib/smartystreets_ruby_sdk/basic_auth_credentials'
|
|
3
4
|
require '../lib/smartystreets_ruby_sdk/client_builder'
|
|
4
5
|
require '../lib/smartystreets_ruby_sdk/us_enrichment/lookup'
|
|
5
6
|
|
|
6
7
|
class USEnrichmentAddressExample
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
# We recommend storing your secret keys in environment variables instead---it's safer!
|
|
11
|
-
# key = ENV['SMARTY_AUTH_WEB']
|
|
12
|
-
# referer = ENV['SMARTY_AUTH_REFERER']
|
|
13
|
-
# credentials = SmartyStreets::SharedCredentials.new(key, referer)
|
|
8
|
+
# SmartyKey used for the non-property datasets. The property example uses a
|
|
9
|
+
# separate key because its address happens to have rich financial history.
|
|
10
|
+
SHARED_SMARTY_KEY = '325023201'
|
|
14
11
|
|
|
12
|
+
def run
|
|
15
13
|
id = ENV['SMARTY_AUTH_ID']
|
|
16
14
|
token = ENV['SMARTY_AUTH_TOKEN']
|
|
17
|
-
credentials = SmartyStreets::
|
|
15
|
+
credentials = SmartyStreets::BasicAuthCredentials.new(id, token)
|
|
18
16
|
|
|
19
17
|
# The appropriate license values to be used for your subscriptions
|
|
20
18
|
# can be found on the Subscriptions page of the account dashboard.
|
|
@@ -22,57 +20,145 @@ class USEnrichmentAddressExample
|
|
|
22
20
|
#
|
|
23
21
|
# To try with a proxy, add this method call at the end of the chain
|
|
24
22
|
# with_proxy('localhost', 8080, 'proxyUser', 'proxyPassword')
|
|
25
|
-
client = SmartyStreets::ClientBuilder.new(credentials).
|
|
26
|
-
|
|
27
|
-
result = nil
|
|
23
|
+
@client = SmartyStreets::ClientBuilder.new(credentials).
|
|
24
|
+
build_us_enrichment_api_client
|
|
28
25
|
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
property_principal_example
|
|
27
|
+
geo_reference_example
|
|
28
|
+
secondary_example
|
|
29
|
+
secondary_count_example
|
|
30
|
+
end
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
lookup.state = "NJ"
|
|
36
|
-
lookup.zipcode = "08876"
|
|
37
|
-
lookup.features = "financial"
|
|
38
|
-
# lookup.etag = "AUBAGDQDAIGQYCYC"
|
|
32
|
+
# ---------- property / principal ----------
|
|
33
|
+
def property_principal_example
|
|
34
|
+
banner 'property / principal'
|
|
39
35
|
|
|
36
|
+
lookup = SmartyStreets::USEnrichment::Lookup.new
|
|
37
|
+
lookup.smarty_key = '87844267'
|
|
38
|
+
lookup.street = '56 Union Ave'
|
|
39
|
+
lookup.city = 'Somerville'
|
|
40
|
+
lookup.state = 'NJ'
|
|
41
|
+
lookup.zipcode = '08876'
|
|
42
|
+
lookup.features = 'financial'
|
|
43
|
+
# lookup.request_etag = 'AUBAGDQDAIGQYCYC'
|
|
40
44
|
# lookup.add_custom_parameter('parameter', 'value')
|
|
41
45
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
freeform_lookup.freeform = "56 Union Ave Somerville NJ 08876"
|
|
46
|
+
results = invoke { @client.send_property_principal_lookup(lookup) }
|
|
47
|
+
return if results.nil? || results.empty?
|
|
45
48
|
|
|
46
|
-
|
|
49
|
+
response = results[0]
|
|
50
|
+
attrs = response.attributes
|
|
51
|
+
puts "Smarty Key: #{response.smarty_key}"
|
|
52
|
+
puts "Data Set: #{response.data_set_name}/#{response.data_subset_name}"
|
|
53
|
+
puts "ETag: #{lookup.response_etag}"
|
|
54
|
+
puts
|
|
55
|
+
puts 'Property Address:'
|
|
56
|
+
puts " Full Address: #{attrs.property_address_full}"
|
|
57
|
+
puts " City: #{attrs.property_address_city}, #{attrs.property_address_state} #{attrs.property_address_zipcode}"
|
|
58
|
+
puts "Owner: #{attrs.owner_full_name}"
|
|
59
|
+
puts "Year Built: #{attrs.year_built} Building Sqft: #{attrs.building_sqft}"
|
|
60
|
+
puts "Assessed Value: #{attrs.assessed_value} Total Market Value: #{attrs.total_market_value}"
|
|
61
|
+
unless attrs.financial_history.nil? || attrs.financial_history.empty?
|
|
62
|
+
puts "Financial History entries: #{attrs.financial_history.length}"
|
|
63
|
+
end
|
|
64
|
+
end
|
|
47
65
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
66
|
+
# ---------- geo-reference ----------
|
|
67
|
+
def geo_reference_example
|
|
68
|
+
banner 'geo-reference'
|
|
51
69
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
70
|
+
lookup = SmartyStreets::USEnrichment::Lookup.new(SHARED_SMARTY_KEY)
|
|
71
|
+
results = invoke { @client.send_geo_reference_lookup(lookup) }
|
|
72
|
+
return if results.nil? || results.empty?
|
|
55
73
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
74
|
+
response = results[0]
|
|
75
|
+
attrs = response.attributes
|
|
76
|
+
puts "Smarty Key: #{response.smarty_key}"
|
|
77
|
+
puts "Data Set: #{response.data_set_name} (version: #{response.data_set_version})"
|
|
78
|
+
puts "Matched Address: #{response.matched_address}"
|
|
79
|
+
puts "ETag: #{lookup.response_etag}"
|
|
80
|
+
puts
|
|
81
|
+
print_object('Census Block', attrs.census_block)
|
|
82
|
+
print_object('Census County Division', attrs.census_county_division)
|
|
83
|
+
print_object('Census Tract', attrs.census_tract)
|
|
84
|
+
print_object('Core Based Stat Area', attrs.core_based_stat_area)
|
|
85
|
+
print_object('Place', attrs.place)
|
|
86
|
+
end
|
|
61
87
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
88
|
+
# ---------- secondary ----------
|
|
89
|
+
def secondary_example
|
|
90
|
+
banner 'secondary'
|
|
91
|
+
|
|
92
|
+
lookup = SmartyStreets::USEnrichment::Lookup.new(SHARED_SMARTY_KEY)
|
|
93
|
+
results = invoke { @client.send_secondary_lookup(lookup) }
|
|
94
|
+
return if results.nil? || results.empty?
|
|
95
|
+
|
|
96
|
+
response = results[0]
|
|
97
|
+
puts "Smarty Key: #{response.smarty_key}"
|
|
98
|
+
puts "Matched Address: #{response.matched_address}"
|
|
99
|
+
puts "ETag: #{lookup.response_etag}"
|
|
100
|
+
puts
|
|
101
|
+
print_object('Root Address', response.root_address)
|
|
102
|
+
|
|
103
|
+
unless response.aliases.nil? || response.aliases.empty?
|
|
104
|
+
puts "\nAliases (#{response.aliases.length}):"
|
|
105
|
+
response.aliases.each_with_index { |a, i| puts " [#{i}] #{one_liner(a)}" }
|
|
65
106
|
end
|
|
66
107
|
|
|
67
|
-
|
|
68
|
-
puts
|
|
108
|
+
unless response.secondaries.nil? || response.secondaries.empty?
|
|
109
|
+
puts "\nSecondaries (#{response.secondaries.length}):"
|
|
110
|
+
response.secondaries.first(5).each_with_index { |s, i| puts " [#{i}] #{one_liner(s)}" }
|
|
111
|
+
puts " ...#{response.secondaries.length - 5} more" if response.secondaries.length > 5
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# ---------- secondary / count ----------
|
|
116
|
+
def secondary_count_example
|
|
117
|
+
banner 'secondary / count'
|
|
118
|
+
|
|
119
|
+
lookup = SmartyStreets::USEnrichment::Lookup.new(SHARED_SMARTY_KEY)
|
|
120
|
+
results = invoke { @client.send_secondary_count_lookup(lookup) }
|
|
121
|
+
return if results.nil? || results.empty?
|
|
122
|
+
|
|
123
|
+
response = results[0]
|
|
124
|
+
puts "Smarty Key: #{response.smarty_key}"
|
|
125
|
+
puts "Matched Address: #{response.matched_address}"
|
|
126
|
+
puts "Count: #{response.count}"
|
|
127
|
+
puts "ETag: #{lookup.response_etag}"
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# ---------- helpers ----------
|
|
131
|
+
def banner(title)
|
|
132
|
+
puts
|
|
133
|
+
puts "=== #{title} ==="
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def invoke
|
|
137
|
+
yield
|
|
138
|
+
rescue SmartyStreets::SmartyError => err
|
|
139
|
+
puts " Lookup failed: #{err.class}: #{err.message}"
|
|
140
|
+
nil
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def print_object(label, obj)
|
|
144
|
+
puts "#{label}:"
|
|
145
|
+
if obj.nil?
|
|
146
|
+
puts ' (none)'
|
|
69
147
|
return
|
|
70
148
|
end
|
|
149
|
+
obj.instance_variables.each do |var|
|
|
150
|
+
value = obj.instance_variable_get(var)
|
|
151
|
+
next if value.nil?
|
|
152
|
+
puts " #{var.to_s.delete('@')}: #{value}"
|
|
153
|
+
end
|
|
154
|
+
end
|
|
71
155
|
|
|
72
|
-
|
|
73
|
-
|
|
156
|
+
def one_liner(obj)
|
|
157
|
+
obj.instance_variables.filter do |var|
|
|
158
|
+
value = obj.instance_variable_get(var)
|
|
159
|
+
"#{var.to_s.delete('@')}=#{value}" unless value.nil?
|
|
160
|
+
end.join(' ')
|
|
74
161
|
end
|
|
75
162
|
end
|
|
76
163
|
|
|
77
|
-
|
|
78
|
-
example.run
|
|
164
|
+
USEnrichmentAddressExample.new.run
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require '../lib/smartystreets_ruby_sdk/static_credentials'
|
|
2
2
|
require '../lib/smartystreets_ruby_sdk/shared_credentials'
|
|
3
|
+
require '../lib/smartystreets_ruby_sdk/basic_auth_credentials'
|
|
3
4
|
require '../lib/smartystreets_ruby_sdk/client_builder'
|
|
4
5
|
require '../lib/smartystreets_ruby_sdk/us_extract/lookup'
|
|
5
6
|
require '../lib/smartystreets_ruby_sdk/us_street/match_type'
|
|
@@ -12,13 +13,13 @@ class USExtractExample
|
|
|
12
13
|
# key = 'Your SmartyStreets Auth Key here'
|
|
13
14
|
# referer = 'Your host name here'
|
|
14
15
|
# We recommend storing your secret keys in environment variables instead---it's safer!
|
|
15
|
-
key = ENV['SMARTY_AUTH_WEB']
|
|
16
|
-
referer = ENV['SMARTY_AUTH_REFERER']
|
|
17
|
-
credentials = SmartyStreets::SharedCredentials.new(key, referer)
|
|
16
|
+
# key = ENV['SMARTY_AUTH_WEB']
|
|
17
|
+
# referer = ENV['SMARTY_AUTH_REFERER']
|
|
18
|
+
# credentials = SmartyStreets::SharedCredentials.new(key, referer)
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
id = ENV['SMARTY_AUTH_ID']
|
|
21
|
+
token = ENV['SMARTY_AUTH_TOKEN']
|
|
22
|
+
credentials = SmartyStreets::BasicAuthCredentials.new(id, token)
|
|
22
23
|
|
|
23
24
|
client = SmartyStreets::ClientBuilder.new(credentials).build_us_extract_api_client
|
|
24
25
|
|
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
require '../lib/smartystreets_ruby_sdk/static_credentials'
|
|
2
2
|
require '../lib/smartystreets_ruby_sdk/shared_credentials'
|
|
3
|
+
require '../lib/smartystreets_ruby_sdk/basic_auth_credentials'
|
|
3
4
|
require '../lib/smartystreets_ruby_sdk/client_builder'
|
|
4
5
|
require '../lib/smartystreets_ruby_sdk/us_reverse_geo/lookup'
|
|
6
|
+
require '../lib/smartystreets_ruby_sdk/us_reverse_geo/source_type'
|
|
5
7
|
|
|
6
8
|
class USReverseGeoExample
|
|
7
9
|
Lookup = SmartyStreets::USReverseGeo::Lookup
|
|
10
|
+
SourceType = SmartyStreets::USReverseGeo::SourceType
|
|
8
11
|
|
|
9
12
|
def run
|
|
10
13
|
# key = 'Your SmartyStreets Auth Key here'
|
|
11
14
|
# referer = 'Your host name here'
|
|
12
15
|
# 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
|
-
credentials = SmartyStreets::SharedCredentials.new(key, referer)
|
|
16
|
+
# key = ENV['SMARTY_AUTH_WEB']
|
|
17
|
+
# referer = ENV['SMARTY_AUTH_REFERER']
|
|
18
|
+
# credentials = SmartyStreets::SharedCredentials.new(key, referer)
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
id = ENV['SMARTY_AUTH_ID']
|
|
21
|
+
token = ENV['SMARTY_AUTH_TOKEN']
|
|
22
|
+
credentials = SmartyStreets::BasicAuthCredentials.new(id, token)
|
|
20
23
|
|
|
21
24
|
client = SmartyStreets::ClientBuilder.new(credentials).build_us_reverse_geo_api_client
|
|
22
25
|
|
|
@@ -24,6 +27,7 @@ class USReverseGeoExample
|
|
|
24
27
|
# https://smartystreets.com/docs/cloud/us-reverse-geo-api#http-request-input-fields
|
|
25
28
|
|
|
26
29
|
lookup = Lookup.new(40.111111, -111.111111)
|
|
30
|
+
lookup.source = SourceType::ALL
|
|
27
31
|
|
|
28
32
|
# lookup.add_custom_parameter('parameter', 'value')
|
|
29
33
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require '../lib/smartystreets_ruby_sdk/static_credentials'
|
|
2
2
|
require '../lib/smartystreets_ruby_sdk/shared_credentials'
|
|
3
|
+
require '../lib/smartystreets_ruby_sdk/basic_auth_credentials'
|
|
3
4
|
require '../lib/smartystreets_ruby_sdk/client_builder'
|
|
4
5
|
require '../lib/smartystreets_ruby_sdk/us_street/lookup'
|
|
5
6
|
require '../lib/smartystreets_ruby_sdk/us_street/match_type'
|
|
@@ -14,7 +15,7 @@ class USStreetComponentAnalysisExample
|
|
|
14
15
|
# For server-to-server requests, use this code:
|
|
15
16
|
id = ENV['SMARTY_AUTH_ID']
|
|
16
17
|
token = ENV['SMARTY_AUTH_TOKEN']
|
|
17
|
-
credentials = SmartyStreets::
|
|
18
|
+
credentials = SmartyStreets::BasicAuthCredentials.new(id, token)
|
|
18
19
|
|
|
19
20
|
client = SmartyStreets::ClientBuilder.new(credentials)
|
|
20
21
|
.with_feature_component_analysis() # To add component analysis feature you need to specify when you create the client.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require '../lib/smartystreets_ruby_sdk/static_credentials'
|
|
2
|
+
require '../lib/smartystreets_ruby_sdk/shared_credentials'
|
|
3
|
+
require '../lib/smartystreets_ruby_sdk/basic_auth_credentials'
|
|
4
|
+
require '../lib/smartystreets_ruby_sdk/client_builder'
|
|
5
|
+
require '../lib/smartystreets_ruby_sdk/us_street/lookup'
|
|
6
|
+
require '../lib/smartystreets_ruby_sdk/us_street/match_type'
|
|
7
|
+
|
|
8
|
+
class USStreetIANATimezoneExample
|
|
9
|
+
def run
|
|
10
|
+
# For client-side requests (browser/mobile), use this code:
|
|
11
|
+
# key = ENV['SMARTY_AUTH_WEB']
|
|
12
|
+
# referer = ENV['SMARTY_AUTH_REFERER']
|
|
13
|
+
# credentials = SmartyStreets::SharedCredentials.new(key, referer)
|
|
14
|
+
|
|
15
|
+
# For server-to-server requests, use this code:
|
|
16
|
+
id = ENV['SMARTY_AUTH_ID']
|
|
17
|
+
token = ENV['SMARTY_AUTH_TOKEN']
|
|
18
|
+
credentials = SmartyStreets::BasicAuthCredentials.new(id, token)
|
|
19
|
+
|
|
20
|
+
client = SmartyStreets::ClientBuilder.new(credentials)
|
|
21
|
+
.with_feature_iana_time_zone()
|
|
22
|
+
.build_us_street_api_client
|
|
23
|
+
|
|
24
|
+
lookup = SmartyStreets::USStreet::Lookup.new
|
|
25
|
+
lookup.street = "1 Rosedale"
|
|
26
|
+
lookup.secondary = "APT 2"
|
|
27
|
+
lookup.city = "Baltimore"
|
|
28
|
+
lookup.state = "MD"
|
|
29
|
+
lookup.zipcode = "21229"
|
|
30
|
+
lookup.match = SmartyStreets::USStreet::MatchType::ENHANCED
|
|
31
|
+
|
|
32
|
+
begin
|
|
33
|
+
client.send_lookup(lookup)
|
|
34
|
+
rescue SmartyStreets::SmartyError => err
|
|
35
|
+
puts err
|
|
36
|
+
return
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
result = lookup.result
|
|
40
|
+
|
|
41
|
+
if result.empty?
|
|
42
|
+
return
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
first_candidate = result[0]
|
|
46
|
+
|
|
47
|
+
puts "IANA Time Zone: #{first_candidate.metadata.iana_time_zone}"
|
|
48
|
+
puts "IANA UTC Offset: #{first_candidate.metadata.iana_utc_offset}"
|
|
49
|
+
puts "IANA Obeys DST: #{first_candidate.metadata.iana_obeys_dst}"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
example = USStreetIANATimezoneExample.new
|
|
54
|
+
example.run
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
require '../lib/smartystreets_ruby_sdk/static_credentials'
|
|
2
|
+
require '../lib/smartystreets_ruby_sdk/shared_credentials'
|
|
3
|
+
require '../lib/smartystreets_ruby_sdk/basic_auth_credentials'
|
|
4
|
+
require '../lib/smartystreets_ruby_sdk/client_builder'
|
|
5
|
+
require '../lib/smartystreets_ruby_sdk/batch'
|
|
6
|
+
require '../lib/smartystreets_ruby_sdk/us_street/lookup'
|
|
7
|
+
require '../lib/smartystreets_ruby_sdk/us_street/match_type'
|
|
8
|
+
|
|
9
|
+
class USStreetLookupsWithMatchStrategyExample
|
|
10
|
+
Lookup = SmartyStreets::USStreet::Lookup
|
|
11
|
+
MatchType = SmartyStreets::USStreet::MatchType
|
|
12
|
+
|
|
13
|
+
def run
|
|
14
|
+
# We recommend storing your secret keys in environment variables instead---it's safer!
|
|
15
|
+
id = ENV['SMARTY_AUTH_ID']
|
|
16
|
+
token = ENV['SMARTY_AUTH_TOKEN']
|
|
17
|
+
credentials = SmartyStreets::BasicAuthCredentials.new(id, token)
|
|
18
|
+
client = SmartyStreets::ClientBuilder.new(credentials).build_us_street_api_client
|
|
19
|
+
|
|
20
|
+
# Each address is run through all three match strategies so you can compare how
|
|
21
|
+
# 'strict', 'enhanced', and 'invalid' each handle a valid, an invalid, and an
|
|
22
|
+
# ambiguous address.
|
|
23
|
+
# - strict: only returns candidates that are valid, mailable addresses.
|
|
24
|
+
# - enhanced: returns a more comprehensive dataset (requires a US Core or Rooftop license).
|
|
25
|
+
# - invalid: most permissive; always returns at least one candidate (a best-guess standardization).
|
|
26
|
+
# Documentation for input fields: https://smartystreets.com/docs/cloud/us-street-api
|
|
27
|
+
addresses = [
|
|
28
|
+
['valid (real, deliverable)', '1600 Amphitheatre Pkwy', 'Mountain View', 'CA', '94043'],
|
|
29
|
+
['invalid (no such address)', '9999 W 1150 S', 'Provo', 'UT', '84601'],
|
|
30
|
+
['ambiguous (missing ZIP/unit)', '1 Rosedale St', 'Baltimore', 'MD', '']
|
|
31
|
+
]
|
|
32
|
+
strategies = [MatchType::STRICT, MatchType::ENHANCED, MatchType::INVALID]
|
|
33
|
+
|
|
34
|
+
batch = SmartyStreets::Batch.new
|
|
35
|
+
cases = [] # parallel metadata for each lookup, in the order they are added to the batch
|
|
36
|
+
|
|
37
|
+
addresses.each do |label, street, city, state, zipcode|
|
|
38
|
+
strategies.each do |strategy|
|
|
39
|
+
lookup = Lookup.new
|
|
40
|
+
lookup.street = street
|
|
41
|
+
lookup.city = city
|
|
42
|
+
lookup.state = state
|
|
43
|
+
lookup.zipcode = zipcode
|
|
44
|
+
lookup.match = strategy
|
|
45
|
+
lookup.candidates = 10 # allow ambiguous addresses to return more than one match
|
|
46
|
+
batch.add(lookup)
|
|
47
|
+
cases << [label, "#{street}, #{city}, #{state}", strategy]
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
begin
|
|
52
|
+
client.send_batch(batch)
|
|
53
|
+
rescue SmartyStreets::SmartyError => err
|
|
54
|
+
puts err
|
|
55
|
+
return
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
last_address = nil
|
|
59
|
+
batch.each_with_index do |lookup, i|
|
|
60
|
+
label, address_display, strategy = cases[i]
|
|
61
|
+
|
|
62
|
+
unless address_display == last_address
|
|
63
|
+
puts "\n" + ('=' * 70)
|
|
64
|
+
puts " Address: #{address_display} [#{label}]"
|
|
65
|
+
puts('=' * 70)
|
|
66
|
+
last_address = address_display
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
candidates = lookup.result
|
|
70
|
+
puts "\n--- '#{strategy}' strategy ---"
|
|
71
|
+
|
|
72
|
+
if candidates.empty?
|
|
73
|
+
puts ' 0 candidates - no match returned under this strategy.'
|
|
74
|
+
next
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
puts " #{candidates.length} candidate(s):"
|
|
78
|
+
candidates.each do |candidate|
|
|
79
|
+
puts " [#{candidate.candidate_index}] #{candidate.delivery_line_1} #{candidate.last_line}"
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
USStreetLookupsWithMatchStrategyExample.new.run
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require '../lib/smartystreets_ruby_sdk/static_credentials'
|
|
2
2
|
require '../lib/smartystreets_ruby_sdk/shared_credentials'
|
|
3
|
+
require '../lib/smartystreets_ruby_sdk/basic_auth_credentials'
|
|
3
4
|
require '../lib/smartystreets_ruby_sdk/client_builder'
|
|
4
5
|
require '../lib/smartystreets_ruby_sdk/batch'
|
|
5
6
|
require '../lib/smartystreets_ruby_sdk/us_street/lookup'
|
|
@@ -12,13 +13,13 @@ class USStreetMultipleAddressExample
|
|
|
12
13
|
# key = 'Your SmartyStreets Auth Key here'
|
|
13
14
|
# referer = 'Your host name here'
|
|
14
15
|
# We recommend storing your secret keys in environment variables instead---it's safer!
|
|
15
|
-
key = ENV['SMARTY_AUTH_WEB']
|
|
16
|
-
referer = ENV['SMARTY_AUTH_REFERER']
|
|
17
|
-
credentials = SmartyStreets::SharedCredentials.new(key, referer)
|
|
16
|
+
# key = ENV['SMARTY_AUTH_WEB']
|
|
17
|
+
# referer = ENV['SMARTY_AUTH_REFERER']
|
|
18
|
+
# credentials = SmartyStreets::SharedCredentials.new(key, referer)
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
id = ENV['SMARTY_AUTH_ID']
|
|
21
|
+
token = ENV['SMARTY_AUTH_TOKEN']
|
|
22
|
+
credentials = SmartyStreets::BasicAuthCredentials.new(id, token)
|
|
22
23
|
|
|
23
24
|
client = SmartyStreets::ClientBuilder.new(credentials).build_us_street_api_client
|
|
24
25
|
batch = SmartyStreets::Batch.new
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require '../lib/smartystreets_ruby_sdk/static_credentials'
|
|
2
2
|
require '../lib/smartystreets_ruby_sdk/shared_credentials'
|
|
3
|
+
require '../lib/smartystreets_ruby_sdk/basic_auth_credentials'
|
|
3
4
|
require '../lib/smartystreets_ruby_sdk/client_builder'
|
|
4
5
|
require '../lib/smartystreets_ruby_sdk/us_street/lookup'
|
|
5
6
|
require '../lib/smartystreets_ruby_sdk/us_street/match_type'
|
|
@@ -9,13 +10,13 @@ class USStreetSingleAddressExample
|
|
|
9
10
|
# key = 'Your SmartyStreets Auth Key here'
|
|
10
11
|
# referer = 'Your host name here'
|
|
11
12
|
# We recommend storing your secret keys in environment variables instead---it's safer!
|
|
12
|
-
key = ENV['SMARTY_AUTH_WEB']
|
|
13
|
-
referer = ENV['SMARTY_AUTH_REFERER']
|
|
14
|
-
credentials = SmartyStreets::SharedCredentials.new(key, referer)
|
|
13
|
+
# key = ENV['SMARTY_AUTH_WEB']
|
|
14
|
+
# referer = ENV['SMARTY_AUTH_REFERER']
|
|
15
|
+
# credentials = SmartyStreets::SharedCredentials.new(key, referer)
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
id = ENV['SMARTY_AUTH_ID']
|
|
18
|
+
token = ENV['SMARTY_AUTH_TOKEN']
|
|
19
|
+
credentials = SmartyStreets::BasicAuthCredentials.new(id, token)
|
|
19
20
|
|
|
20
21
|
# To try with a proxy, add this method before build_us_street_api_client
|
|
21
22
|
# with_proxy('localhost', 8080, 'proxyUser', 'proxyPassword')
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require '../lib/smartystreets_ruby_sdk/static_credentials'
|
|
2
2
|
require '../lib/smartystreets_ruby_sdk/shared_credentials'
|
|
3
|
+
require '../lib/smartystreets_ruby_sdk/basic_auth_credentials'
|
|
3
4
|
require '../lib/smartystreets_ruby_sdk/client_builder'
|
|
4
5
|
require '../lib/smartystreets_ruby_sdk/batch'
|
|
5
6
|
require '../lib/smartystreets_ruby_sdk/us_zipcode/lookup'
|
|
@@ -11,13 +12,13 @@ class USZipcodeMultipleLookupExample
|
|
|
11
12
|
# key = 'Your SmartyStreets Auth Key here'
|
|
12
13
|
# referer = 'Your host name here'
|
|
13
14
|
# 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
|
-
credentials = SmartyStreets::SharedCredentials.new(key, referer)
|
|
15
|
+
# key = ENV['SMARTY_AUTH_WEB']
|
|
16
|
+
# referer = ENV['SMARTY_AUTH_REFERER']
|
|
17
|
+
# credentials = SmartyStreets::SharedCredentials.new(key, referer)
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
id = ENV['SMARTY_AUTH_ID']
|
|
20
|
+
token = ENV['SMARTY_AUTH_TOKEN']
|
|
21
|
+
credentials = SmartyStreets::BasicAuthCredentials.new(id, token)
|
|
21
22
|
|
|
22
23
|
client = SmartyStreets::ClientBuilder.new(credentials).build_us_zipcode_api_client
|
|
23
24
|
batch = SmartyStreets::Batch.new
|