-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathus_reverse_geo_example.rb
52 lines (40 loc) · 1.87 KB
/
us_reverse_geo_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
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_reverse_geo/lookup'
class USReverseGeoExample
Lookup = SmartyStreets::USReverseGeo::Lookup
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
client = SmartyStreets::ClientBuilder.new(credentials).with_licenses(['us-reverse-geocoding-cloud'])
.build_us_reverse_geo_api_client
# Documentation for input fields can be found at:
# https://smartystreets.com/docs/cloud/us-reverse-geo-api#http-request-input-fields
lookup = Lookup.new(40.111111, -111.111111)
# lookup.add_custom_parameter('parameter', 'value')
response = client.send(lookup)
result = response.results[0]
coordinate = result.coordinate
puts "Latitude: #{coordinate.latitude}"
puts "Longitude: #{coordinate.longitude}\n"
puts "Distance: #{result.distance}\n"
address = result.address
puts "Street: #{address.street}"
puts "City: #{address.city}"
puts "State Abbreviation: #{address.state_abbreviation}"
puts "ZIP Code: #{address.zipcode}"
puts "License: #{coordinate.get_license}"
end
end
USReverseGeoExample.new.run