Sha256: fcfbc846cefc26ccf4b61453bead094c5c97ea9119062f3c62a264895413f4cc

Contents?: true

Size: 1.32 KB

Versions: 14

Compression:

Stored size: 1.32 KB

Contents

require 'smartystreets_ruby_sdk/static_credentials'
require 'smartystreets_ruby_sdk/client_builder'
require 'smartystreets_ruby_sdk/us_zipcode/lookup'

class UsZipcodeSingleLookupExample
  def run
    auth_id = 'Your SmartyStreets Auth ID here'
    auth_token = 'Your SmartyStreets Auth Token here'

    # We recommend storing your secret keys in environment variables instead---it's safer!
    # auth_id = ENV['SMARTY_AUTH_ID']
    # auth_token = ENV['SMARTY_AUTH_TOKEN']

    credentials = SmartyStreets::StaticCredentials.new(auth_id, auth_token)

    client = SmartyStreets::ClientBuilder.new(credentials).build_us_zipcode_api_client

    lookup = SmartyStreets::USZipcode::Lookup.new
    lookup.city = 'Mountain View'
    lookup.state = 'California'

    begin
      client.send_lookup(lookup)
    rescue SmartyStreets::SmartyError => err
      puts err
      return
    end

    result = lookup.result
    zipcodes = result.zipcodes
    cities = result.cities

    cities.each do |city|
      puts "\nCity: #{city.city}"
      puts "State: #{city.state}"
      puts "Mailable City: #{city.mailable_city}"
    end

    zipcodes.each do |zipcode|
      puts "\nZIP Code: #{zipcode.zipcode}"
      puts "Latitude: #{zipcode.latitude}"
      puts "Longitude: #{zipcode.longitude}"
    end
  end
end

example = UsZipcodeSingleLookupExample.new
example.run

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
smartystreets_ruby_sdk-5.7.0 examples/us_zipcode_single_lookup_example.rb
smartystreets_ruby_sdk-5.6.2 examples/us_zipcode_single_lookup_example.rb
smartystreets_ruby_sdk-5.6.1 examples/us_zipcode_single_lookup_example.rb
smartystreets_ruby_sdk-5.6.0 examples/us_zipcode_single_lookup_example.rb
smartystreets_ruby_sdk-5.5.4 examples/us_zipcode_single_lookup_example.rb
smartystreets_ruby_sdk-5.5.3 examples/us_zipcode_single_lookup_example.rb
smartystreets_ruby_sdk-5.5.2 examples/us_zipcode_single_lookup_example.rb
smartystreets_ruby_sdk-5.5.1 examples/us_zipcode_single_lookup_example.rb
smartystreets_ruby_sdk-5.5.0 examples/us_zipcode_single_lookup_example.rb
smartystreets_ruby_sdk-5.4.0 examples/us_zipcode_single_lookup_example.rb
smartystreets_ruby_sdk-5.3.3 examples/us_zipcode_single_lookup_example.rb
smartystreets_ruby_sdk-5.3.2 examples/us_zipcode_single_lookup_example.rb
smartystreets_ruby_sdk-5.3.1 examples/us_zipcode_single_lookup_example.rb
smartystreets_ruby_sdk-5.3.0 examples/us_zipcode_single_lookup_example.rb