-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathus_enrichment_example.rb
76 lines (60 loc) · 2.81 KB
/
us_enrichment_example.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
require '../lib/smartystreets_ruby_sdk/static_credentials'
require '../lib/smartystreets_ruby_sdk/shared_credentials'
require '../lib/smartystreets_ruby_sdk/client_builder'
require '../lib/smartystreets_ruby_sdk/us_enrichment/lookup'
class USEnrichmentAddressExample
def run
# key = 'Your SmartyStreets Auth Key here'
# referer = 'Your host name here'
# We recommend storing your secret keys in environment variables instead---it's safer!
# key = ENV['SMARTY_AUTH_WEB']
# referer = ENV['SMARTY_AUTH_REFERER']
# credentials = SmartyStreets::SharedCredentials.new(key, referer)
id = ENV['SMARTY_AUTH_ID']
token = ENV['SMARTY_AUTH_TOKEN']
credentials = SmartyStreets::StaticCredentials.new(id, token)
# The appropriate license values to be used for your subscriptions
# can be found on the Subscriptions page of the account dashboard.
# https://www.smartystreets.com/docs/cloud/licensing
#
# To try with a proxy, add this method call at the end of the chain
# with_proxy('localhost', 8080, 'proxyUser', 'proxyPassword')
client = SmartyStreets::ClientBuilder.new(credentials).
build_us_enrichment_api_client
result = nil
# Create a new lookup instance to search with address components
lookup = SmartyStreets::USEnrichment::Lookup.new
lookup.street = "56 Union Ave"
lookup.city = "Somerville"
lookup.state = "NJ"
lookup.zipcode = "08876"
# lookup.etag = "AUBAGDQDAIGQYCYC"
# lookup.add_custom_parameter('parameter', 'value')
# Or, create a freeform lookup to search using a single line address
freeform_lookup = SmartyStreets::USEnrichment::Lookup.new
freeform_lookup.freeform = "56 Union Ave Somerville NJ 08876"
begin
# Send a lookup with a smarty key using the line below
result = client.send_property_principal_lookup("325023201")
# Uncomment the following lines to perform other types of lookups:
# result = client.send_property_principal_lookup(lookup) # Using address components
# result = client.send_property_principal_lookup(freeform_lookup) # Using freeform address
# Access the other Enrichment datasets using the below functions. All of these functions can take a lookup or a smartykey
# result = client.send_property_financial_lookup("325023201")
# result = client.send_geo_reference_lookup("325023201")
# result = client.send_secondary_lookup("325023201")
# result = client.send_secondary_count_lookup("325023201")
rescue SmartyStreets::SmartyError => err
puts err
return
end
if result.empty?
puts 'No results. This means the smartykey is not valid.'
return
end
puts "Lookup Successful! Here is the result: "
puts result[0].inspect
end
end
example = USEnrichmentAddressExample.new
example.run