Sha256: d5cedc10722d80638b18eccf61586568f3b7fef1c545d2f63e8b6aa3eea6e70b

Contents?: true

Size: 1.8 KB

Versions: 22

Compression:

Stored size: 1.8 KB

Contents

require 'smartystreets_ruby_sdk/static_credentials'
require 'smartystreets_ruby_sdk/client_builder'
require 'smartystreets_ruby_sdk/us_extract/lookup'

class USExtractExample
  Lookup = SmartyStreets::USExtract::Lookup

  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_extract_api_client

    text = "Here is some text.\r\nMy address is 3785 Las Vegs Av." \
           "\r\nLos Vegas, Nevada." \
           "\r\nMeet me at 1 Rosedale Baltimore Maryland, not at 123 Phony Street, Boise Idaho."

    # Documentation for input fields can be found at:
    # https://smartystreets.com/docs/cloud/us-extract-api

    lookup = Lookup.new(text)
    lookup.aggressive = true
    lookup.addresses_have_line_breaks = false
    lookup.addresses_per_line = 2

    result = client.send(lookup)

    metadata = result.metadata
    puts "Found #{metadata.address_count} addresses."
    puts "#{metadata.verified_count} of them were valid."
    puts

    addresses = result.addresses

    puts "Addresses: \r\n**********************\r\n"
    addresses.each do |address|
      puts "\"#{address.text}\"\n\n"
      puts "Verified? #{address.verified}"
      if address.candidates.any?
        puts("\nMatches:")

        address.candidates.each do |candidate|
          puts candidate.delivery_line_1
          puts candidate.last_line
          puts
        end

      else
        puts
      end

      puts "**********************\n"
    end
  end
end

USExtractExample.new.run

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
smartystreets_ruby_sdk-5.14.10 examples/us_extract_example.rb
smartystreets_ruby_sdk-5.14.9 examples/us_extract_example.rb
smartystreets_ruby_sdk-5.14.8 examples/us_extract_example.rb
smartystreets_ruby_sdk-5.14.7 examples/us_extract_example.rb
smartystreets_ruby_sdk-5.14.6 examples/us_extract_example.rb
smartystreets_ruby_sdk-5.14.5 examples/us_extract_example.rb
smartystreets_ruby_sdk-5.14.4 examples/us_extract_example.rb
smartystreets_ruby_sdk-5.14.3 examples/us_extract_example.rb
smartystreets_ruby_sdk-5.14.1 examples/us_extract_example.rb
smartystreets_ruby_sdk-5.14.0 examples/us_extract_example.rb
smartystreets_ruby_sdk-5.13.0 examples/us_extract_example.rb
smartystreets_ruby_sdk-5.12.1 examples/us_extract_example.rb
smartystreets_ruby_sdk-5.12.0 examples/us_extract_example.rb
smartystreets_ruby_sdk-5.11.2 examples/us_extract_example.rb
smartystreets_ruby_sdk-5.11.1 examples/us_extract_example.rb
smartystreets_ruby_sdk-5.11.0 examples/us_extract_example.rb
smartystreets_ruby_sdk-5.10.0 examples/us_extract_example.rb
smartystreets_ruby_sdk-5.9.2 examples/us_extract_example.rb
smartystreets_ruby_sdk-5.9.1 examples/us_extract_example.rb
smartystreets_ruby_sdk-5.9.0 examples/us_extract_example.rb