smartystreets_ruby_sdk 5.7.0 → 5.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +0 -4
- data/examples/international_example.rb +15 -2
- data/examples/us_autocomplete_example.rb +8 -0
- data/examples/us_extract_example.rb +6 -0
- data/examples/us_reverse_geo_example.rb +43 -0
- data/examples/us_street_multiple_address_example.rb +17 -4
- data/examples/us_street_single_address_example.rb +16 -3
- data/examples/us_zipcode_multiple_lookup_example.rb +4 -0
- data/examples/us_zipcode_single_lookup_example.rb +7 -0
- data/lib/smartystreets_ruby_sdk.rb +2 -0
- data/lib/smartystreets_ruby_sdk/client_builder.rb +19 -0
- data/lib/smartystreets_ruby_sdk/international_street/client.rb +5 -2
- data/lib/smartystreets_ruby_sdk/international_street/lookup.rb +2 -2
- data/lib/smartystreets_ruby_sdk/international_street/rootlevel.rb +3 -2
- data/lib/smartystreets_ruby_sdk/license_sender.rb +15 -0
- data/lib/smartystreets_ruby_sdk/us_extract/result.rb +1 -1
- data/lib/smartystreets_ruby_sdk/us_reverse_geo.rb +12 -0
- data/lib/smartystreets_ruby_sdk/us_reverse_geo/address.rb +16 -0
- data/lib/smartystreets_ruby_sdk/us_reverse_geo/client.rb +38 -0
- data/lib/smartystreets_ruby_sdk/us_reverse_geo/coordinate.rb +25 -0
- data/lib/smartystreets_ruby_sdk/us_reverse_geo/lookup.rb +21 -0
- data/lib/smartystreets_ruby_sdk/us_reverse_geo/result.rb +20 -0
- data/lib/smartystreets_ruby_sdk/us_reverse_geo/us_reverse_geo_response.rb +17 -0
- data/lib/smartystreets_ruby_sdk/us_street/candidate.rb +2 -1
- data/lib/smartystreets_ruby_sdk/us_street/client.rb +1 -0
- data/lib/smartystreets_ruby_sdk/us_zipcode/result.rb +2 -1
- data/lib/smartystreets_ruby_sdk/version.rb +1 -1
- metadata +12 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3bf47c1d7fc05162f580218523c230a1831b5d3a7db41114632ffff8edcd715
|
4
|
+
data.tar.gz: c88966f71a4516c4e89077411eb171ccd8074b7f5d9897c551eb1faf977f2415
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d6c3fb74acd909a9c8c3faa5ccff9ab59fc8edc7a515b3ba265318f75eebeeb42cc24e63714050bdc61ee1dd49ab62a7e85c0f0034e248e143460e9d8fb8c34
|
7
|
+
data.tar.gz: 938c7cfcdc00f22924c66668d25446425a27edc43839193c959b41452f68ea250de64c99790f4c764699e0a180b9c19c35586dd8c57c8b906ddbe2378f20a817
|
data/README.md
CHANGED
@@ -14,14 +14,27 @@ class InternationalExample
|
|
14
14
|
# auth_token = ENV['SMARTY_AUTH_TOKEN']
|
15
15
|
|
16
16
|
credentials = SmartyStreets::StaticCredentials.new(auth_id, auth_token)
|
17
|
-
client = SmartyStreets::ClientBuilder.new(credentials).
|
17
|
+
client = SmartyStreets::ClientBuilder.new(credentials) # .with_licenses(%w(international-fake-license))
|
18
|
+
.build_international_street_api_client
|
18
19
|
|
19
|
-
|
20
|
+
# Documentation for input fields can be found at:
|
21
|
+
# https://smartystreets.com/docs/cloud/international-street-api
|
22
|
+
|
23
|
+
lookup = Lookup.new()
|
24
|
+
lookup.inputId = 'ID-8675309' # Optional ID from your system
|
20
25
|
lookup.geocode = true # Must be expressly set to get latitude and longitude.
|
26
|
+
lookup.organization = 'John Doe'
|
27
|
+
lookup.address1 = "Rua Padre Antonio D'Angelo 121"
|
28
|
+
lookup.address2 = 'Casa Verde'
|
29
|
+
lookup.locality = 'Sao Paulo'
|
30
|
+
lookup.administrative_area = 'SP'
|
31
|
+
lookup.country = 'Brazil'
|
32
|
+
lookup.postal_code = '02516-050'
|
21
33
|
|
22
34
|
candidates = client.send(lookup) # The candidates are also stored in the lookup's 'result' field.
|
23
35
|
|
24
36
|
first_candidate = candidates[0]
|
37
|
+
puts "Input ID: #{first_candidate.input_id}"
|
25
38
|
puts "Address is #{first_candidate.analysis.verification_status}"
|
26
39
|
puts "Address precision: #{first_candidate.analysis.address_precision}\n\n"
|
27
40
|
puts "First Line: #{first_candidate.address1}"
|
@@ -15,7 +15,12 @@ class USAutocompleteExample
|
|
15
15
|
|
16
16
|
credentials = SmartyStreets::StaticCredentials.new(auth_id, auth_token)
|
17
17
|
client = SmartyStreets::ClientBuilder.new(credentials).build_us_autocomplete_api_client
|
18
|
+
|
19
|
+
# Documentation for input fields can be found at:
|
20
|
+
# https://smartystreets.com/docs/cloud/us-autocomplete-api
|
21
|
+
|
18
22
|
lookup = Lookup.new('4770 Lincoln Ave O')
|
23
|
+
lookup.max_suggestions = 10
|
19
24
|
|
20
25
|
client.send(lookup)
|
21
26
|
|
@@ -25,8 +30,11 @@ class USAutocompleteExample
|
|
25
30
|
puts suggestion.text
|
26
31
|
end
|
27
32
|
|
33
|
+
lookup.add_city_filter('Ogden')
|
28
34
|
lookup.add_state_filter('IL')
|
35
|
+
lookup.add_prefer('Ogden, IL')
|
29
36
|
lookup.max_suggestions = 5
|
37
|
+
lookup.prefer_ratio = 0.333333
|
30
38
|
|
31
39
|
suggestions = client.send(lookup) # The client will also return the suggestions directly
|
32
40
|
|
@@ -21,7 +21,13 @@ class USExtractExample
|
|
21
21
|
"\r\nLos Vegas, Nevada." \
|
22
22
|
"\r\nMeet me at 1 Rosedale Baltimore Maryland, not at 123 Phony Street, Boise Idaho."
|
23
23
|
|
24
|
+
# Documentation for input fields can be found at:
|
25
|
+
# https://smartystreets.com/docs/cloud/us-extract-api
|
26
|
+
|
24
27
|
lookup = Lookup.new(text)
|
28
|
+
lookup.aggressive = true
|
29
|
+
lookup.addresses_have_line_breaks = false
|
30
|
+
lookup.addresses_per_line = 2
|
25
31
|
|
26
32
|
result = client.send(lookup)
|
27
33
|
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'smartystreets_ruby_sdk/static_credentials'
|
2
|
+
require '../lib/smartystreets_ruby_sdk/client_builder'
|
3
|
+
require '../lib/smartystreets_ruby_sdk/us_reverse_geo/lookup'
|
4
|
+
|
5
|
+
class USReverseGeoExample
|
6
|
+
Lookup = SmartyStreets::USReverseGeo::Lookup
|
7
|
+
|
8
|
+
def run
|
9
|
+
auth_id = 'Your SmartyStreets Auth ID here'
|
10
|
+
auth_token = 'Your SmartyStreets Auth Token here'
|
11
|
+
|
12
|
+
# We recommend storing your secret keys in environment variables instead---it's safer!
|
13
|
+
# auth_id = ENV['SMARTY_AUTH_ID']
|
14
|
+
# auth_token = ENV['SMARTY_AUTH_TOKEN']
|
15
|
+
|
16
|
+
credentials = SmartyStreets::StaticCredentials.new(auth_id, auth_token)
|
17
|
+
client = SmartyStreets::ClientBuilder.new(credentials)
|
18
|
+
.build_us_reverse_geo_api_client
|
19
|
+
|
20
|
+
# Documentation for input fields can be found at:
|
21
|
+
# https://smartystreets.com/docs/cloud/us-reverse-geo-api#http-request-input-fields
|
22
|
+
|
23
|
+
lookup = Lookup.new(40.111111, -111.111111)
|
24
|
+
|
25
|
+
response = client.send(lookup)
|
26
|
+
result = response.results[0]
|
27
|
+
|
28
|
+
coordinate = result.coordinate
|
29
|
+
puts "Latitude: #{coordinate.latitude}"
|
30
|
+
puts "Longitude: #{coordinate.longitude}\n"
|
31
|
+
|
32
|
+
puts "Distance: #{result.distance}\n"
|
33
|
+
|
34
|
+
address = result.address
|
35
|
+
puts "Street: #{address.street}"
|
36
|
+
puts "City: #{address.city}"
|
37
|
+
puts "State Abbreviation: #{address.state_abbreviation}"
|
38
|
+
puts "ZIP Code: #{address.zipcode}"
|
39
|
+
puts "License: #{coordinate.get_license}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
USReverseGeoExample.new.run
|
@@ -16,14 +16,26 @@ class USStreetMultipleAddressExample
|
|
16
16
|
|
17
17
|
credentials = SmartyStreets::StaticCredentials.new(auth_id, auth_token)
|
18
18
|
|
19
|
-
client = SmartyStreets::ClientBuilder.new(credentials).
|
19
|
+
client = SmartyStreets::ClientBuilder.new(credentials) # .with_licenses(%w(us-rooftop-geocoding-cloud))
|
20
|
+
.build_us_street_api_client
|
20
21
|
batch = SmartyStreets::Batch.new
|
21
22
|
|
23
|
+
# Documentation for input fields can be found at:
|
24
|
+
# https://smartystreets.com/docs/cloud/us-street-api
|
25
|
+
|
22
26
|
batch.add(Lookup.new)
|
27
|
+
batch[0].input_id = '8675309' # Optional ID from your system
|
28
|
+
batch[0].addressee = 'John Doe'
|
23
29
|
batch[0].street = '1600 amphitheatre parkway'
|
24
|
-
batch[0].
|
25
|
-
batch[0].
|
26
|
-
batch[0].
|
30
|
+
batch[0].street2 = 'second star to the right'
|
31
|
+
batch[0].secondary = 'APT 2'
|
32
|
+
batch[0].urbanization = '' # Only applies to Puerto Rico addresses
|
33
|
+
batch[0].lastline = 'Mountain view, California'
|
34
|
+
batch[0].zipcode = '21229'
|
35
|
+
batch[0].candidates = 3
|
36
|
+
batch[0].match = 'invalid'.freeze # "invalid" is the most permissive match,
|
37
|
+
# this will always return at least one result even if the address is invalid.
|
38
|
+
# Refer to the documentation for additional Match Strategy options.
|
27
39
|
|
28
40
|
batch.add(Lookup.new('1 Rosedale, Baltimore, Maryland')) # Freeform addresses work too.
|
29
41
|
batch[1].candidates = 10 # Allows up to ten possible matches to be returned (default is 1).
|
@@ -56,6 +68,7 @@ class USStreetMultipleAddressExample
|
|
56
68
|
metadata = candidate.metadata
|
57
69
|
|
58
70
|
puts "\nCandidate #{candidate.candidate_index} : "
|
71
|
+
puts "Input ID: #{candidate.input_id}"
|
59
72
|
puts "Delivery line 1: #{candidate.delivery_line_1}"
|
60
73
|
puts "Last line: #{candidate.last_line}"
|
61
74
|
puts "ZIP Code: #{components.zipcode}-#{components.plus4_code}"
|
@@ -14,14 +14,26 @@ class USStreetSingleAddressExample
|
|
14
14
|
credentials = SmartyStreets::StaticCredentials.new(auth_id, auth_token)
|
15
15
|
|
16
16
|
client = SmartyStreets::ClientBuilder.new(credentials).
|
17
|
-
|
18
|
-
|
17
|
+
# with_proxy('localhost', 8080, 'proxyUser', 'proxyPassword'). # Uncomment this line to try it with a proxy
|
18
|
+
build_us_street_api_client
|
19
|
+
|
20
|
+
# Documentation for input fields can be found at:
|
21
|
+
# https://smartystreets.com/docs/cloud/us-street-api
|
19
22
|
|
20
23
|
lookup = SmartyStreets::USStreet::Lookup.new
|
24
|
+
lookup.input_id = '24601' # Optional ID from your system
|
25
|
+
lookup.addressee = 'John Doe'
|
21
26
|
lookup.street = '1600 Amphitheatre Pkwy'
|
27
|
+
lookup.street2 = 'closet under the stairs'
|
28
|
+
lookup.secondary = 'APT 2'
|
29
|
+
lookup.urbanization = '' # Only applies to Puerto Rico addresses
|
22
30
|
lookup.city = 'Mountain View'
|
23
31
|
lookup.state = 'CA'
|
24
|
-
lookup.
|
32
|
+
lookup.zipcode = '21229'
|
33
|
+
lookup.candidates = 3
|
34
|
+
lookup.match = 'invalid'.freeze # "invalid" is the most permissive match,
|
35
|
+
# this will always return at least one result even if the address is invalid.
|
36
|
+
# Refer to the documentation for additional Match Strategy options.
|
25
37
|
|
26
38
|
begin
|
27
39
|
client.send_lookup(lookup)
|
@@ -40,6 +52,7 @@ class USStreetSingleAddressExample
|
|
40
52
|
first_candidate = result[0]
|
41
53
|
|
42
54
|
puts "Address is valid. (There is at least one candidate)\n"
|
55
|
+
puts "Input ID: #{first_candidate.input_id}"
|
43
56
|
puts "ZIP Code: #{first_candidate.components.zipcode}"
|
44
57
|
puts "County: #{first_candidate.metadata.county_name}"
|
45
58
|
puts "Latitude: #{first_candidate.metadata.latitude}"
|
@@ -19,7 +19,11 @@ class USZipcodeMultipleLookupExample
|
|
19
19
|
client = SmartyStreets::ClientBuilder.new(credentials).build_us_zipcode_api_client
|
20
20
|
batch = SmartyStreets::Batch.new
|
21
21
|
|
22
|
+
# Documentation for input fields can be found at:
|
23
|
+
# https://smartystreets.com/docs/cloud/us-zipcode-api
|
24
|
+
|
22
25
|
batch.add(Lookup.new)
|
26
|
+
batch[0].input_id = '01189998819991197253' # Optional ID from your system
|
23
27
|
batch[0].zipcode = '12345' # A Lookup may have a ZIP Code, city and state, or city, state, and ZIP Code
|
24
28
|
|
25
29
|
batch.add(Lookup.new)
|
@@ -15,9 +15,14 @@ class UsZipcodeSingleLookupExample
|
|
15
15
|
|
16
16
|
client = SmartyStreets::ClientBuilder.new(credentials).build_us_zipcode_api_client
|
17
17
|
|
18
|
+
# Documentation for input fields can be found at:
|
19
|
+
# https://smartystreets.com/docs/cloud/us-zipcode-api
|
20
|
+
|
18
21
|
lookup = SmartyStreets::USZipcode::Lookup.new
|
22
|
+
lookup.input_id = 'dfc33cb6-829e-4fea-aa1b-b6d6580f0817' # Optional ID from your system
|
19
23
|
lookup.city = 'Mountain View'
|
20
24
|
lookup.state = 'California'
|
25
|
+
lookup.zipcode = '94043'
|
21
26
|
|
22
27
|
begin
|
23
28
|
client.send_lookup(lookup)
|
@@ -30,6 +35,8 @@ class UsZipcodeSingleLookupExample
|
|
30
35
|
zipcodes = result.zipcodes
|
31
36
|
cities = result.cities
|
32
37
|
|
38
|
+
puts "Input ID: #{result.input_id}"
|
39
|
+
|
33
40
|
cities.each do |city|
|
34
41
|
puts "\nCity: #{city.city}"
|
35
42
|
puts "State: #{city.state}"
|
@@ -14,6 +14,7 @@ require 'smartystreets_ruby_sdk/native_serializer'
|
|
14
14
|
require 'smartystreets_ruby_sdk/request'
|
15
15
|
require 'smartystreets_ruby_sdk/response'
|
16
16
|
require 'smartystreets_ruby_sdk/retry_sender'
|
17
|
+
require 'smartystreets_ruby_sdk/license_sender'
|
17
18
|
require 'smartystreets_ruby_sdk/shared_credentials'
|
18
19
|
require 'smartystreets_ruby_sdk/signing_sender'
|
19
20
|
require 'smartystreets_ruby_sdk/static_credentials'
|
@@ -25,6 +26,7 @@ require 'smartystreets_ruby_sdk/us_street'
|
|
25
26
|
require 'smartystreets_ruby_sdk/us_zipcode'
|
26
27
|
require 'smartystreets_ruby_sdk/us_autocomplete'
|
27
28
|
require 'smartystreets_ruby_sdk/international_street'
|
29
|
+
require 'smartystreets_ruby_sdk/us_reverse_geo'
|
28
30
|
|
29
31
|
module SmartyStreets
|
30
32
|
end
|
@@ -4,6 +4,7 @@ require_relative 'status_code_sender'
|
|
4
4
|
require_relative 'signing_sender'
|
5
5
|
require_relative 'retry_sender'
|
6
6
|
require_relative 'url_prefix_sender'
|
7
|
+
require_relative 'license_sender'
|
7
8
|
require_relative 'sleeper'
|
8
9
|
require_relative 'logger'
|
9
10
|
require_relative 'proxy'
|
@@ -13,6 +14,7 @@ require_relative 'us_zipcode/client'
|
|
13
14
|
require_relative 'us_extract/client'
|
14
15
|
require_relative 'us_autocomplete/client'
|
15
16
|
require_relative 'international_street/client'
|
17
|
+
require_relative 'us_reverse_geo/client'
|
16
18
|
|
17
19
|
module SmartyStreets
|
18
20
|
# The ClientBuilder class helps you build a client object for one of the supported SmartyStreets APIs.
|
@@ -24,6 +26,7 @@ module SmartyStreets
|
|
24
26
|
US_EXTRACT_API_URL = 'https://us-extract.api.smartystreets.com/'.freeze
|
25
27
|
US_STREET_API_URL = 'https://us-street.api.smartystreets.com/street-address'.freeze
|
26
28
|
US_ZIP_CODE_API_URL = 'https://us-zipcode.api.smartystreets.com/lookup'.freeze
|
29
|
+
US_REVERSE_GEO_API_URL = 'https://us-reverse-geo.api.smartystreets.com/lookup'.freeze
|
27
30
|
|
28
31
|
def initialize(signer)
|
29
32
|
@signer = signer
|
@@ -34,6 +37,7 @@ module SmartyStreets
|
|
34
37
|
@url_prefix = nil
|
35
38
|
@proxy = nil
|
36
39
|
@headers = nil
|
40
|
+
@licenses = %w()
|
37
41
|
@debug = nil
|
38
42
|
end
|
39
43
|
|
@@ -96,6 +100,14 @@ module SmartyStreets
|
|
96
100
|
self
|
97
101
|
end
|
98
102
|
|
103
|
+
# Allows the caller to specify the subscription license (aka "track") they wish to use.
|
104
|
+
#
|
105
|
+
# Returns self to accommodate method chaining.
|
106
|
+
def with_licenses(licenses)
|
107
|
+
@licenses.concat licenses
|
108
|
+
self
|
109
|
+
end
|
110
|
+
|
99
111
|
# Enables debug mode, which will print information about the HTTP request and response to $stdout.
|
100
112
|
#
|
101
113
|
# Returns self to accommodate method chaining.
|
@@ -131,6 +143,11 @@ module SmartyStreets
|
|
131
143
|
USZipcode::Client.new(build_sender, @serializer)
|
132
144
|
end
|
133
145
|
|
146
|
+
def build_us_reverse_geo_api_client
|
147
|
+
ensure_url_prefix_not_null(US_REVERSE_GEO_API_URL)
|
148
|
+
USReverseGeo::Client.new(build_sender, @serializer)
|
149
|
+
end
|
150
|
+
|
134
151
|
# </editor-fold>
|
135
152
|
|
136
153
|
def build_sender
|
@@ -146,6 +163,8 @@ module SmartyStreets
|
|
146
163
|
|
147
164
|
sender = RetrySender.new(@max_retries, sender, SmartyStreets::Sleeper.new,SmartyStreets::Logger.new) if @max_retries > 0
|
148
165
|
|
166
|
+
sender = LicenseSender.new(sender, @licenses)
|
167
|
+
|
149
168
|
URLPrefixSender.new(@url_prefix, sender)
|
150
169
|
end
|
151
170
|
|
@@ -26,6 +26,7 @@ module SmartyStreets
|
|
26
26
|
def build_request(lookup)
|
27
27
|
request = SmartyStreets::Request.new
|
28
28
|
|
29
|
+
add_parameter(request, 'input_id', lookup.input_id)
|
29
30
|
add_parameter(request, 'country', lookup.country)
|
30
31
|
add_parameter(request, 'geocode', lookup.geocode.to_s)
|
31
32
|
add_parameter(request, 'language', lookup.language)
|
@@ -49,8 +50,10 @@ module SmartyStreets
|
|
49
50
|
def convert_candidates(raw_candidates)
|
50
51
|
candidates = []
|
51
52
|
|
52
|
-
raw_candidates.
|
53
|
-
|
53
|
+
unless raw_candidates.nil?
|
54
|
+
raw_candidates.each do |candidate|
|
55
|
+
candidates.push(Candidate.new(candidate))
|
56
|
+
end
|
54
57
|
end
|
55
58
|
|
56
59
|
candidates
|
@@ -14,13 +14,13 @@ module SmartyStreets
|
|
14
14
|
# When set to language_mode.LATIN, the results will always be provided using a Latin character set.
|
15
15
|
class Lookup
|
16
16
|
|
17
|
-
attr_accessor :freeform, :locality, :postal_code, :address3, :address2, :inputId, :address1,
|
17
|
+
attr_accessor :input_id, :freeform, :locality, :postal_code, :address3, :address2, :inputId, :address1,
|
18
18
|
:geocode, :administrative_area, :country, :organization, :language, :address4, :result
|
19
19
|
|
20
20
|
def initialize(freeform=nil, country=nil)
|
21
21
|
@result = []
|
22
22
|
|
23
|
-
@
|
23
|
+
@input_id = nil
|
24
24
|
@country = country
|
25
25
|
@geocode = nil
|
26
26
|
@language = nil
|
@@ -1,10 +1,11 @@
|
|
1
1
|
module SmartyStreets
|
2
2
|
module InternationalStreet
|
3
3
|
class RootLevel
|
4
|
-
attr_reader :organization, :address1, :address2, :address3, :address4, :address5, :address6, :address7,
|
5
|
-
:address9, :address10, :address11, :address12
|
4
|
+
attr_reader :input_id, :organization, :address1, :address2, :address3, :address4, :address5, :address6, :address7,
|
5
|
+
:address8, :address9, :address10, :address11, :address12
|
6
6
|
|
7
7
|
def initialize(obj)
|
8
|
+
@input_id = obj.fetch('input_id', nil)
|
8
9
|
@organization = obj.fetch('organization', nil)
|
9
10
|
@address1 = obj.fetch('address1', nil)
|
10
11
|
@address2 = obj.fetch('address2', nil)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module SmartyStreets
|
2
|
+
class LicenseSender
|
3
|
+
def initialize(inner, licenses)
|
4
|
+
@inner = inner
|
5
|
+
@licenses = licenses
|
6
|
+
end
|
7
|
+
|
8
|
+
def send(request)
|
9
|
+
if @licenses.length > 0
|
10
|
+
request.parameters['license'] = @licenses.join(',')
|
11
|
+
end
|
12
|
+
@inner.send(request)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require_relative './us_reverse_geo/address'
|
2
|
+
require_relative './us_reverse_geo/client'
|
3
|
+
require_relative './us_reverse_geo/coordinate'
|
4
|
+
require_relative './us_reverse_geo/lookup'
|
5
|
+
require_relative './us_reverse_geo/result'
|
6
|
+
require_relative './us_reverse_geo/us_reverse_geo_response'
|
7
|
+
|
8
|
+
module SmartyStreets
|
9
|
+
module USReverseGeo
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module SmartyStreets
|
2
|
+
module USReverseGeo
|
3
|
+
# See "https://smartystreets.com/docs/cloud/us-reverse-geo-api#address"
|
4
|
+
class Address
|
5
|
+
attr_reader :street, :city, :state_abbreviation, :zipcode
|
6
|
+
|
7
|
+
def initialize(obj)
|
8
|
+
@street = obj['street']
|
9
|
+
@city = obj['city']
|
10
|
+
@state_abbreviation = obj['state_abbreviation']
|
11
|
+
@zipcode = obj['zipcode']
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative '../request'
|
2
|
+
require_relative 'us_reverse_geo_response'
|
3
|
+
|
4
|
+
module SmartyStreets
|
5
|
+
module USReverseGeo
|
6
|
+
# It is recommended to instantiate this class using ClientBuilder.build_us_reverse_geo_api_client()
|
7
|
+
class Client
|
8
|
+
def initialize(sender, serializer)
|
9
|
+
@sender = sender
|
10
|
+
@serializer = serializer
|
11
|
+
end
|
12
|
+
|
13
|
+
# Sends a Lookup object to the US Reverse Geo API and stores the result in the Lookup's response field.
|
14
|
+
def send(lookup)
|
15
|
+
request = build_request(lookup)
|
16
|
+
|
17
|
+
response = @sender.send(request)
|
18
|
+
|
19
|
+
raise response.error if response.error
|
20
|
+
|
21
|
+
lookup.response = Response.new(@serializer.deserialize(response.payload))
|
22
|
+
end
|
23
|
+
|
24
|
+
def build_request(lookup)
|
25
|
+
request = SmartyStreets::Request.new
|
26
|
+
|
27
|
+
add_parameter(request, 'latitude', lookup.latitude)
|
28
|
+
add_parameter(request, 'longitude', lookup.longitude)
|
29
|
+
|
30
|
+
request
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_parameter(request, key, value)
|
34
|
+
request.parameters[key] = value unless value.nil? or value.empty?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module SmartyStreets
|
2
|
+
module USReverseGeo
|
3
|
+
# See "https://smartystreets.com/docs/cloud/us-reverse-geo-api#coordinate"
|
4
|
+
class Coordinate
|
5
|
+
attr_reader :latitude, :longitude, :accuracy, :license
|
6
|
+
|
7
|
+
def initialize(obj)
|
8
|
+
@latitude = obj.fetch('latitude', nil)
|
9
|
+
@longitude = obj.fetch('longitude', nil)
|
10
|
+
@accuracy = obj.fetch('accuracy', nil)
|
11
|
+
@license = obj.fetch('license', nil)
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_license()
|
15
|
+
case @license
|
16
|
+
when 1
|
17
|
+
return "SmartyStreets Proprietary"
|
18
|
+
else
|
19
|
+
return "SmartyStreets"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module SmartyStreets
|
2
|
+
module USReverseGeo
|
3
|
+
# In addition to holding all of the input data for this lookup, this class also will contain the
|
4
|
+
# result of the lookup after it comes back from the API.
|
5
|
+
#
|
6
|
+
# Note: Lookups must have certain required fields set with non-blank values.
|
7
|
+
# These can be found at the URL below.
|
8
|
+
#
|
9
|
+
# See "https://smartystreets.com/docs/cloud/us-reverse-geo-api#http-request-input-fields"
|
10
|
+
|
11
|
+
class Lookup
|
12
|
+
|
13
|
+
attr_accessor :latitude, :longitude, :response
|
14
|
+
|
15
|
+
def initialize(latitude, longitude)
|
16
|
+
@latitude = sprintf('%.8f', latitude)
|
17
|
+
@longitude = sprintf('%.8f', longitude)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'coordinate'
|
2
|
+
require_relative 'address'
|
3
|
+
|
4
|
+
module SmartyStreets
|
5
|
+
module USReverseGeo
|
6
|
+
# A result is a possible match for an geocode that was submitted. A lookup can have multiple results.
|
7
|
+
#
|
8
|
+
# See "https://smartystreets.com/docs/cloud/us-reverse-geo-api#result"
|
9
|
+
class Result
|
10
|
+
attr_reader :address, :coordinate, :distance
|
11
|
+
|
12
|
+
def initialize(obj)
|
13
|
+
@address = Address.new(obj.fetch('address', {}))
|
14
|
+
@coordinate = Coordinate.new(obj.fetch('coordinate', {}))
|
15
|
+
@distance = obj['distance']
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative 'result'
|
2
|
+
|
3
|
+
module SmartyStreets
|
4
|
+
module USReverseGeo
|
5
|
+
class Response
|
6
|
+
attr_reader :results
|
7
|
+
|
8
|
+
def initialize(obj)
|
9
|
+
@results = []
|
10
|
+
|
11
|
+
obj['results'].each do |result|
|
12
|
+
@results.push(Result.new(result))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -6,10 +6,11 @@ module SmartyStreets
|
|
6
6
|
module USStreet
|
7
7
|
# See "https://smartystreets.com/docs/cloud/us-street-api#metadata"
|
8
8
|
class Candidate
|
9
|
-
attr_reader :input_index, :candidate_index, :addressee, :delivery_line_1, :delivery_line_2, :delivery_point_barcode,
|
9
|
+
attr_reader :input_id, :input_index, :candidate_index, :addressee, :delivery_line_1, :delivery_line_2, :delivery_point_barcode,
|
10
10
|
:last_line, :metadata, :components, :analysis
|
11
11
|
|
12
12
|
def initialize(obj)
|
13
|
+
@input_id = obj['input_id']
|
13
14
|
@input_index = obj['input_index']
|
14
15
|
@candidate_index = obj['candidate_index']
|
15
16
|
@addressee = obj['addressee']
|
@@ -48,6 +48,7 @@ module SmartyStreets
|
|
48
48
|
obj.each do |lookup|
|
49
49
|
converted_lookup = {}
|
50
50
|
|
51
|
+
converted_lookup['input_id'] = lookup.input_id
|
51
52
|
converted_lookup['street'] = lookup.street
|
52
53
|
converted_lookup['street2'] = lookup.street2
|
53
54
|
converted_lookup['secondary'] = lookup.secondary
|
@@ -5,11 +5,12 @@ module SmartyStreets
|
|
5
5
|
module USZipcode
|
6
6
|
# See "https://smartystreets.com/docs/cloud/us-zipcode-api#root"
|
7
7
|
class Result
|
8
|
-
attr_reader :reason, :input_index, :cities, :zipcodes, :status
|
8
|
+
attr_reader :reason, :input_id, :input_index, :cities, :zipcodes, :status
|
9
9
|
|
10
10
|
def initialize(obj)
|
11
11
|
@status = obj['status']
|
12
12
|
@reason = obj['reason']
|
13
|
+
@input_id = obj['input_id']
|
13
14
|
@input_index = obj['input_index']
|
14
15
|
@cities = obj.fetch('city_states', [])
|
15
16
|
@zipcodes = obj.fetch('zipcodes', [])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smartystreets_ruby_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SmartyStreets SDK Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- examples/international_example.rb
|
94
94
|
- examples/us_autocomplete_example.rb
|
95
95
|
- examples/us_extract_example.rb
|
96
|
+
- examples/us_reverse_geo_example.rb
|
96
97
|
- examples/us_street_multiple_address_example.rb
|
97
98
|
- examples/us_street_single_address_example.rb
|
98
99
|
- examples/us_zipcode_multiple_lookup_example.rb
|
@@ -114,6 +115,7 @@ files:
|
|
114
115
|
- lib/smartystreets_ruby_sdk/international_street/metadata.rb
|
115
116
|
- lib/smartystreets_ruby_sdk/international_street/rootlevel.rb
|
116
117
|
- lib/smartystreets_ruby_sdk/json_able.rb
|
118
|
+
- lib/smartystreets_ruby_sdk/license_sender.rb
|
117
119
|
- lib/smartystreets_ruby_sdk/logger.rb
|
118
120
|
- lib/smartystreets_ruby_sdk/native_sender.rb
|
119
121
|
- lib/smartystreets_ruby_sdk/native_serializer.rb
|
@@ -138,6 +140,13 @@ files:
|
|
138
140
|
- lib/smartystreets_ruby_sdk/us_extract/lookup.rb
|
139
141
|
- lib/smartystreets_ruby_sdk/us_extract/metadata.rb
|
140
142
|
- lib/smartystreets_ruby_sdk/us_extract/result.rb
|
143
|
+
- lib/smartystreets_ruby_sdk/us_reverse_geo.rb
|
144
|
+
- lib/smartystreets_ruby_sdk/us_reverse_geo/address.rb
|
145
|
+
- lib/smartystreets_ruby_sdk/us_reverse_geo/client.rb
|
146
|
+
- lib/smartystreets_ruby_sdk/us_reverse_geo/coordinate.rb
|
147
|
+
- lib/smartystreets_ruby_sdk/us_reverse_geo/lookup.rb
|
148
|
+
- lib/smartystreets_ruby_sdk/us_reverse_geo/result.rb
|
149
|
+
- lib/smartystreets_ruby_sdk/us_reverse_geo/us_reverse_geo_response.rb
|
141
150
|
- lib/smartystreets_ruby_sdk/us_street.rb
|
142
151
|
- lib/smartystreets_ruby_sdk/us_street/analysis.rb
|
143
152
|
- lib/smartystreets_ruby_sdk/us_street/candidate.rb
|
@@ -175,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
184
|
- !ruby/object:Gem::Version
|
176
185
|
version: '0'
|
177
186
|
requirements: []
|
178
|
-
rubygems_version: 3.
|
187
|
+
rubygems_version: 3.1.2
|
179
188
|
signing_key:
|
180
189
|
specification_version: 4
|
181
190
|
summary: An official library for the SmartyStreets APIs
|