Sha256: eafbbb156b51bdecd819a6ea4b07e4c15a81a119b80e978f9a213cb328bed43d

Contents?: true

Size: 1.81 KB

Versions: 20

Compression:

Stored size: 1.81 KB

Contents

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)

    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

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
smartystreets_ruby_sdk-5.20.4 examples/us_reverse_geo_example.rb
smartystreets_ruby_sdk-5.20.3 examples/us_reverse_geo_example.rb
smartystreets_ruby_sdk-5.20.2 examples/us_reverse_geo_example.rb
smartystreets_ruby_sdk-5.19.0 examples/us_reverse_geo_example.rb
smartystreets_ruby_sdk-5.18.1 examples/us_reverse_geo_example.rb
smartystreets_ruby_sdk-5.18.0 examples/us_reverse_geo_example.rb
smartystreets_ruby_sdk-5.17.2 examples/us_reverse_geo_example.rb
smartystreets_ruby_sdk-5.17.1 examples/us_reverse_geo_example.rb
smartystreets_ruby_sdk-5.17.0 examples/us_reverse_geo_example.rb
smartystreets_ruby_sdk-5.16.2 examples/us_reverse_geo_example.rb
smartystreets_ruby_sdk-5.16.1 examples/us_reverse_geo_example.rb
smartystreets_ruby_sdk-5.16.0 examples/us_reverse_geo_example.rb
smartystreets_ruby_sdk-5.15.4 examples/us_reverse_geo_example.rb
smartystreets_ruby_sdk-5.15.3 examples/us_reverse_geo_example.rb
smartystreets_ruby_sdk-5.15.2 examples/us_reverse_geo_example.rb
smartystreets_ruby_sdk-5.15.1 examples/us_reverse_geo_example.rb
smartystreets_ruby_sdk-5.15.0 examples/us_reverse_geo_example.rb
smartystreets_ruby_sdk-5.14.22 examples/us_reverse_geo_example.rb
smartystreets_ruby_sdk-5.14.19 examples/us_reverse_geo_example.rb
smartystreets_ruby_sdk-5.14.18 examples/us_reverse_geo_example.rb