smartystreets_ruby_sdk 2.0.2 → 3.0.0
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/Makefile +1 -1
- data/Vagrantfile +4 -2
- data/examples/international_example.rb +31 -0
- data/examples/us_autocomplete_example.rb +38 -0
- data/examples/us_extract_example.rb +52 -0
- data/examples/us_street_multiple_address_example.rb +11 -9
- data/examples/us_street_single_address_example.rb +3 -3
- data/examples/us_zipcode_multiple_lookup_example.rb +7 -5
- data/examples/us_zipcode_single_lookup_example.rb +3 -3
- data/lib/smartystreets_ruby_sdk/batch.rb +7 -3
- data/lib/smartystreets_ruby_sdk/client_builder.rb +118 -0
- data/lib/smartystreets_ruby_sdk/errors.rb +15 -7
- data/lib/smartystreets_ruby_sdk/exceptions.rb +12 -5
- data/lib/smartystreets_ruby_sdk/international_street.rb +10 -0
- data/lib/smartystreets_ruby_sdk/international_street/analysis.rb +13 -0
- data/lib/smartystreets_ruby_sdk/international_street/candidate.rb +33 -0
- data/lib/smartystreets_ruby_sdk/international_street/client.rb +56 -0
- data/lib/smartystreets_ruby_sdk/international_street/components.rb +55 -0
- data/lib/smartystreets_ruby_sdk/international_street/language_mode.rb +5 -0
- data/lib/smartystreets_ruby_sdk/international_street/lookup.rb +80 -0
- data/lib/smartystreets_ruby_sdk/international_street/metadata.rb +14 -0
- data/lib/smartystreets_ruby_sdk/json_able.rb +3 -3
- data/lib/smartystreets_ruby_sdk/native_sender.rb +6 -2
- data/lib/smartystreets_ruby_sdk/request.rb +2 -1
- data/lib/smartystreets_ruby_sdk/retry_sender.rb +5 -7
- data/lib/smartystreets_ruby_sdk/us_autocomplete.rb +7 -0
- data/lib/smartystreets_ruby_sdk/us_autocomplete/client.rb +66 -0
- data/lib/smartystreets_ruby_sdk/us_autocomplete/geolocation_type.rb +5 -0
- data/lib/smartystreets_ruby_sdk/us_autocomplete/lookup.rb +34 -0
- data/lib/smartystreets_ruby_sdk/us_autocomplete/suggestion.rb +14 -0
- data/lib/smartystreets_ruby_sdk/us_extract.rb +8 -0
- data/lib/smartystreets_ruby_sdk/us_extract/address.rb +22 -0
- data/lib/smartystreets_ruby_sdk/us_extract/client.rb +46 -0
- data/lib/smartystreets_ruby_sdk/us_extract/lookup.rb +20 -0
- data/lib/smartystreets_ruby_sdk/us_extract/metadata.rb +15 -0
- data/lib/smartystreets_ruby_sdk/us_extract/result.rb +19 -0
- data/lib/smartystreets_ruby_sdk/us_street.rb +1 -1
- data/lib/smartystreets_ruby_sdk/us_street/analysis.rb +1 -0
- data/lib/smartystreets_ruby_sdk/us_street/candidate.rb +1 -0
- data/lib/smartystreets_ruby_sdk/us_street/client.rb +9 -5
- data/lib/smartystreets_ruby_sdk/us_street/components.rb +3 -0
- data/lib/smartystreets_ruby_sdk/us_street/lookup.rb +6 -0
- data/lib/smartystreets_ruby_sdk/us_street/match_type.rb +5 -0
- data/lib/smartystreets_ruby_sdk/us_street/metadata.rb +1 -0
- data/lib/smartystreets_ruby_sdk/us_zipcode.rb +1 -1
- data/lib/smartystreets_ruby_sdk/us_zipcode/alternate_county.rb +13 -0
- data/lib/smartystreets_ruby_sdk/us_zipcode/city.rb +2 -0
- data/lib/smartystreets_ruby_sdk/us_zipcode/client.rb +12 -4
- data/lib/smartystreets_ruby_sdk/us_zipcode/lookup.rb +4 -0
- data/lib/smartystreets_ruby_sdk/us_zipcode/result.rb +3 -2
- data/lib/smartystreets_ruby_sdk/us_zipcode/zip_code.rb +16 -3
- data/lib/smartystreets_ruby_sdk/version.rb +1 -1
- metadata +28 -7
- data/lib/smartystreets_ruby_sdk/core_client_builder.rb +0 -57
- data/lib/smartystreets_ruby_sdk/match_type.rb +0 -5
- data/lib/smartystreets_ruby_sdk/us_street/client_builder.rb +0 -15
- data/lib/smartystreets_ruby_sdk/us_zipcode/client_builder.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64962ee9e3575877e78359805f3a0aad0bb6ab33
|
4
|
+
data.tar.gz: a7fe26f68f4dc756ae3955aca126fba7c4c3f0c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5aeb2e1c9161f295dd43400ae198147e357628740c6432c1ee25f28e51d4d89fcf79c4533f89d720bdfc4ec0d1a1cc1cee5d1e6c122fac49c22d67f66bcf18bf
|
7
|
+
data.tar.gz: dc7caf151400097419930d2b8009b6fa7e8b94eef69000c3d0f5287cc4a5266c36f7d78993f6e44efd20205defaf81257d92e31ee01788d0f12c755201637cbb
|
data/Makefile
CHANGED
data/Vagrantfile
CHANGED
@@ -4,10 +4,12 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
|
4
4
|
config.vm.box = "boxcutter/ubuntu1404"
|
5
5
|
config.vm.synced_folder "~/.identity", "/home/vagrant/.identity", create: true
|
6
6
|
config.vm.synced_folder "~/.gnupg", "/home/vagrant/.gnupg", create: true
|
7
|
-
config.vm.provision "shell", path: "https://s3-us-west-1.amazonaws.com/raptr-us-west-1/bootstrap"
|
8
7
|
|
9
8
|
# box-specific
|
10
|
-
config.vm.provision "shell", inline: "apt-get
|
9
|
+
config.vm.provision "shell", inline: "apt-get update"
|
10
|
+
config.vm.provision "shell", inline: "apt-get install -y ruby" # Installs ruby 1.9 but we should install ruby 2.4...
|
11
|
+
config.vm.provision "shell", inline: "apt-get install -y ruby git"
|
12
|
+
config.vm.provision "shell", inline: "gem install minitest"
|
11
13
|
config.vm.synced_folder "~/.gem", "/home/vagrant/.gem", create: true
|
12
14
|
|
13
15
|
config.vm.provider "virtualbox" do |vb|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'smartystreets_ruby_sdk/static_credentials'
|
2
|
+
require 'smartystreets_ruby_sdk/client_builder'
|
3
|
+
require 'smartystreets_ruby_sdk/international_street/lookup'
|
4
|
+
|
5
|
+
class InternationalExample
|
6
|
+
Lookup = InternationalStreet::Lookup
|
7
|
+
|
8
|
+
def run
|
9
|
+
auth_id = ENV['SMARTY_AUTH_ID'] # We recommend storing your keys in environment variables
|
10
|
+
auth_token = ENV['SMARTY_AUTH_TOKEN']
|
11
|
+
credentials = StaticCredentials.new(auth_id, auth_token)
|
12
|
+
client = ClientBuilder.new(credentials).build_international_street_api_client
|
13
|
+
|
14
|
+
lookup = Lookup.new("Rua Padre Antonio D'Angelo 121 Casa Verde, Sao Paulo", 'Brazil')
|
15
|
+
lookup.geocode = true # Must be expressly set to get latitude and longitude.
|
16
|
+
|
17
|
+
candidates = client.send(lookup) # The candidates are also stored in the lookup's 'result' field.
|
18
|
+
|
19
|
+
first_candidate = candidates[0]
|
20
|
+
puts "Address is #{first_candidate.analysis.verification_status}"
|
21
|
+
puts "Address precision: #{first_candidate.analysis.address_precision}\n\n"
|
22
|
+
puts "First Line: #{first_candidate.address1}"
|
23
|
+
puts "Second Line: #{first_candidate.address2}"
|
24
|
+
puts "Third Line: #{first_candidate.address3}"
|
25
|
+
puts "Fourth Line: #{first_candidate.address4}"
|
26
|
+
puts "Latitude: #{first_candidate.metadata.latitude}"
|
27
|
+
puts "Longitude: #{first_candidate.metadata.longitude}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
InternationalExample.new.run
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'smartystreets_ruby_sdk/static_credentials'
|
2
|
+
require 'smartystreets_ruby_sdk/client_builder'
|
3
|
+
require 'smartystreets_ruby_sdk/us_autocomplete/lookup'
|
4
|
+
|
5
|
+
class USAutocompleteExample
|
6
|
+
Lookup = USAutocomplete::Lookup
|
7
|
+
|
8
|
+
def run
|
9
|
+
auth_id = ENV['SMARTY_AUTH_ID'] # We recommend storing your keys in environment variables
|
10
|
+
auth_token = ENV['SMARTY_AUTH_TOKEN']
|
11
|
+
credentials = StaticCredentials.new(auth_id, auth_token)
|
12
|
+
client = ClientBuilder.new(credentials).build_us_autocomplete_api_client
|
13
|
+
lookup = Lookup.new('4770 Lincoln Ave O')
|
14
|
+
|
15
|
+
client.send(lookup)
|
16
|
+
|
17
|
+
puts '*** Result with no filter ***'
|
18
|
+
puts
|
19
|
+
lookup.result.each do |suggestion|
|
20
|
+
puts suggestion.text
|
21
|
+
end
|
22
|
+
|
23
|
+
lookup.add_state_filter('IL')
|
24
|
+
lookup.max_suggestions = 5
|
25
|
+
|
26
|
+
suggestions = client.send(lookup) # The client will also return the suggestions directly
|
27
|
+
|
28
|
+
puts
|
29
|
+
puts '*** Result with some filters ***'
|
30
|
+
|
31
|
+
suggestions.each do |suggestion|
|
32
|
+
puts suggestion.text
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
USAutocompleteExample.new.run
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'smartystreets_ruby_sdk/static_credentials'
|
2
|
+
require 'smartystreets_ruby_sdk/client_builder'
|
3
|
+
require 'smartystreets_ruby_sdk/us_extract/lookup'
|
4
|
+
|
5
|
+
class USExtractExample
|
6
|
+
Lookup = USExtract::Lookup
|
7
|
+
|
8
|
+
def run
|
9
|
+
auth_id = ENV['SMARTY_AUTH_ID'] # We recommend storing your keys in environment variables
|
10
|
+
auth_token = ENV['SMARTY_AUTH_TOKEN']
|
11
|
+
credentials = StaticCredentials.new(auth_id, auth_token)
|
12
|
+
|
13
|
+
client = ClientBuilder.new(credentials).build_us_extract_api_client
|
14
|
+
|
15
|
+
text = "Here is some text.\r\nMy address is 3785 Las Vegs Av." \
|
16
|
+
"\r\nLos Vegas, Nevada." \
|
17
|
+
"\r\nMeet me at 1 Rosedale Baltimore Maryland, not at 123 Phony Street, Boise Idaho."
|
18
|
+
|
19
|
+
lookup = Lookup.new(text)
|
20
|
+
|
21
|
+
result = client.send(lookup)
|
22
|
+
|
23
|
+
metadata = result.metadata
|
24
|
+
puts "Found #{metadata.address_count} addresses."
|
25
|
+
puts "#{metadata.verified_count} of them were valid."
|
26
|
+
puts
|
27
|
+
|
28
|
+
addresses = result.addresses
|
29
|
+
|
30
|
+
puts "Addresses: \r\n**********************\r\n"
|
31
|
+
addresses.each do |address|
|
32
|
+
puts "\"#{address.text}\"\n\n"
|
33
|
+
puts "Verified? #{address.verified}"
|
34
|
+
if address.candidates.any?
|
35
|
+
puts("\nMatches:")
|
36
|
+
|
37
|
+
address.candidates.each do |candidate|
|
38
|
+
puts candidate.delivery_line_1
|
39
|
+
puts candidate.last_line
|
40
|
+
puts
|
41
|
+
end
|
42
|
+
|
43
|
+
else
|
44
|
+
puts
|
45
|
+
end
|
46
|
+
|
47
|
+
puts "**********************\n"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
USExtractExample.new.run
|
@@ -1,41 +1,43 @@
|
|
1
1
|
require 'smartystreets_ruby_sdk/static_credentials'
|
2
|
-
require 'smartystreets_ruby_sdk/
|
2
|
+
require 'smartystreets_ruby_sdk/client_builder'
|
3
3
|
require 'smartystreets_ruby_sdk/us_street/lookup'
|
4
4
|
|
5
5
|
class USStreetMultipleAddressExample
|
6
|
+
Lookup = USStreet::Lookup
|
7
|
+
|
6
8
|
def run
|
7
|
-
auth_id = ENV['SMARTY_AUTH_ID'] # We recommend storing your keys in environment variables
|
9
|
+
auth_id = ENV['SMARTY_AUTH_ID'] # We recommend storing your keys in environment variables.
|
8
10
|
auth_token = ENV['SMARTY_AUTH_TOKEN']
|
9
11
|
credentials = StaticCredentials.new(auth_id, auth_token)
|
10
12
|
|
11
|
-
client =
|
13
|
+
client = ClientBuilder.new(credentials).build_us_street_api_client
|
12
14
|
batch = Batch.new
|
13
15
|
|
14
|
-
batch.add(
|
16
|
+
batch.add(Lookup.new)
|
15
17
|
batch[0].street = '1600 amphitheatre parkway'
|
16
18
|
batch[0].city = 'Mountain view'
|
17
19
|
batch[0].state = 'california'
|
18
20
|
|
19
|
-
batch.add(
|
21
|
+
batch.add(Lookup.new('1 Rosedale, Baltimore, Maryland')) # Freeform addresses work too.
|
20
22
|
batch[1].candidates = 10 # Allows up to ten possible matches to be returned (default is 1).
|
21
23
|
|
22
|
-
batch.add(
|
24
|
+
batch.add(Lookup.new('123 Bogus Street, Pretend Lake, Oklahoma'))
|
23
25
|
|
24
|
-
batch.add(
|
26
|
+
batch.add(Lookup.new)
|
25
27
|
batch[3].street = '1 Infinite Loop'
|
26
28
|
batch[3].zipcode = '95014' # You can just input the street and ZIP if you want.
|
27
29
|
|
28
30
|
begin
|
29
31
|
client.send_batch(batch)
|
30
32
|
rescue SmartyException => err
|
31
|
-
|
33
|
+
puts err
|
32
34
|
return
|
33
35
|
end
|
34
36
|
|
35
37
|
batch.each_with_index do |lookup, i|
|
36
38
|
candidates = lookup.result
|
37
39
|
|
38
|
-
if candidates.
|
40
|
+
if candidates.empty?
|
39
41
|
puts "Address #{i} is invalid.\n\n"
|
40
42
|
next
|
41
43
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'smartystreets_ruby_sdk/static_credentials'
|
2
|
-
require 'smartystreets_ruby_sdk/
|
2
|
+
require 'smartystreets_ruby_sdk/client_builder'
|
3
3
|
require 'smartystreets_ruby_sdk/us_street/lookup'
|
4
4
|
|
5
5
|
class USStreetSingleAddressExample
|
@@ -8,7 +8,7 @@ class USStreetSingleAddressExample
|
|
8
8
|
auth_token = ENV['SMARTY_AUTH_TOKEN']
|
9
9
|
credentials = StaticCredentials.new(auth_id, auth_token)
|
10
10
|
|
11
|
-
client =
|
11
|
+
client = ClientBuilder.new(credentials).build_us_street_api_client
|
12
12
|
|
13
13
|
lookup = USStreet::Lookup.new
|
14
14
|
lookup.street = '1600 Amphitheatre Pkwy'
|
@@ -24,7 +24,7 @@ class USStreetSingleAddressExample
|
|
24
24
|
|
25
25
|
result = lookup.result
|
26
26
|
|
27
|
-
if result
|
27
|
+
if result nil?
|
28
28
|
puts 'No candidates. This means the address is not valid.'
|
29
29
|
return
|
30
30
|
end
|
@@ -1,24 +1,26 @@
|
|
1
1
|
require 'smartystreets_ruby_sdk/static_credentials'
|
2
|
-
require 'smartystreets_ruby_sdk/
|
2
|
+
require 'smartystreets_ruby_sdk/client_builder'
|
3
3
|
require 'smartystreets_ruby_sdk/us_zipcode/lookup'
|
4
4
|
|
5
5
|
class USZipcodeMultipleLookupExample
|
6
|
+
Lookup = USZipcode::Lookup
|
7
|
+
|
6
8
|
def run
|
7
9
|
auth_id = ENV['SMARTY_AUTH_ID'] # We recommend storing your keys in environment variables
|
8
10
|
auth_token = ENV['SMARTY_AUTH_TOKEN']
|
9
11
|
credentials = StaticCredentials.new(auth_id, auth_token)
|
10
12
|
|
11
|
-
client =
|
13
|
+
client = ClientBuilder.new(credentials).build_us_zipcode_api_client
|
12
14
|
batch = Batch.new
|
13
15
|
|
14
|
-
batch.add(
|
16
|
+
batch.add(Lookup.new)
|
15
17
|
batch[0].zipcode = '12345' # A Lookup may have a ZIP Code, city and state, or city, state, and ZIP Code
|
16
18
|
|
17
|
-
batch.add(
|
19
|
+
batch.add(Lookup.new)
|
18
20
|
batch[1].city = 'Phoenix'
|
19
21
|
batch[1].state = 'Arizona'
|
20
22
|
|
21
|
-
batch.add(
|
23
|
+
batch.add(Lookup.new('cupertino', 'CA', '95014')) # You can also set these with arguments
|
22
24
|
|
23
25
|
|
24
26
|
begin
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'smartystreets_ruby_sdk/static_credentials'
|
2
|
-
require 'smartystreets_ruby_sdk/
|
2
|
+
require 'smartystreets_ruby_sdk/client_builder'
|
3
3
|
require 'smartystreets_ruby_sdk/us_zipcode/lookup'
|
4
4
|
|
5
5
|
class UsZipcodeSingleLookupExample
|
6
6
|
def run
|
7
|
-
auth_id = ENV['SMARTY_AUTH_ID'] # We recommend storing your keys in environment variables
|
7
|
+
auth_id = ENV['SMARTY_AUTH_ID'] # We recommend storing your keys in environment variables.
|
8
8
|
auth_token = ENV['SMARTY_AUTH_TOKEN']
|
9
9
|
credentials = StaticCredentials.new(auth_id, auth_token)
|
10
10
|
|
11
|
-
client =
|
11
|
+
client = ClientBuilder.new(credentials).build_us_zipcode_api_client
|
12
12
|
|
13
13
|
lookup = USZipcode::Lookup.new
|
14
14
|
lookup.city = 'Mountain View'
|
@@ -10,11 +10,11 @@ class Batch
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def add(lookup)
|
13
|
-
return false if
|
13
|
+
return false if full?
|
14
14
|
|
15
15
|
@all_lookups.push(lookup)
|
16
16
|
|
17
|
-
return true if lookup.input_id
|
17
|
+
return true if lookup.input_id.nil?
|
18
18
|
|
19
19
|
@named_lookups[lookup.input_id] = lookup
|
20
20
|
true
|
@@ -25,10 +25,14 @@ class Batch
|
|
25
25
|
@all_lookups.clear
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def full?
|
29
29
|
size >= MAX_BATCH_SIZE
|
30
30
|
end
|
31
31
|
|
32
|
+
def empty?
|
33
|
+
size.zero?
|
34
|
+
end
|
35
|
+
|
32
36
|
def size
|
33
37
|
@all_lookups.length
|
34
38
|
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require_relative 'native_serializer'
|
2
|
+
require_relative 'native_sender'
|
3
|
+
require_relative 'status_code_sender'
|
4
|
+
require_relative 'signing_sender'
|
5
|
+
require_relative 'retry_sender'
|
6
|
+
require_relative 'url_prefix_sender'
|
7
|
+
require_relative 'sleeper'
|
8
|
+
require_relative 'logger'
|
9
|
+
require_relative 'us_street/client'
|
10
|
+
require_relative 'us_zipcode/client'
|
11
|
+
require_relative 'us_extract/client'
|
12
|
+
require_relative 'us_autocomplete/client'
|
13
|
+
require_relative 'international_street/client'
|
14
|
+
|
15
|
+
# The ClientBuilder class helps you build a client object for one of the supported SmartyStreets APIs.
|
16
|
+
# You can use ClientBuilder's methods to customize settings like maximum retries or timeout duration.
|
17
|
+
# These methods are chainable, so you can usually get set up with one line of code.
|
18
|
+
class ClientBuilder
|
19
|
+
INTERNATIONAL_STREET_API_URL = 'https://international-street.api.smartystreets.com/verify'.freeze
|
20
|
+
US_AUTOCOMPLETE_API_URL = 'https://us-autocomplete.api.smartystreets.com/suggest'.freeze
|
21
|
+
US_EXTRACT_API_URL = 'https://us-extract.api.smartystreets.com/'.freeze
|
22
|
+
US_STREET_API_URL = 'https://us-street.api.smartystreets.com/street-address'.freeze
|
23
|
+
US_ZIP_CODE_API_URL = 'https://us-zipcode.api.smartystreets.com/lookup'.freeze
|
24
|
+
|
25
|
+
def initialize(signer)
|
26
|
+
@signer = signer
|
27
|
+
@serializer = NativeSerializer.new
|
28
|
+
@http_sender = nil
|
29
|
+
@max_retries = 5
|
30
|
+
@max_timeout = 10000
|
31
|
+
@url_prefix = nil
|
32
|
+
end
|
33
|
+
|
34
|
+
# Sets the maximum number of times to retry sending the request to the API. (Default is 5)
|
35
|
+
#
|
36
|
+
# Returns self to accommodate method chaining.
|
37
|
+
def retry_at_most(max_retries)
|
38
|
+
@max_retries = max_retries
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
# The maximum time (in milliseconds) to wait for a connection, and also to wait for
|
43
|
+
# the response to be read. (Default is 10000)
|
44
|
+
#
|
45
|
+
# Returns self to accommodate method chaining.
|
46
|
+
def with_max_timeout(max_timeout)
|
47
|
+
@max_timeout = max_timeout
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
# Default is a series of nested senders. (See build_sender()
|
52
|
+
#
|
53
|
+
# Returns self to accommodate method chaining.
|
54
|
+
def with_sender(sender)
|
55
|
+
@http_sender = sender
|
56
|
+
self
|
57
|
+
end
|
58
|
+
|
59
|
+
# Changes the Serializer from the default.
|
60
|
+
#
|
61
|
+
# Returns self to accommodate method chaining.
|
62
|
+
def with_serializer(serializer)
|
63
|
+
@serializer = serializer
|
64
|
+
self
|
65
|
+
end
|
66
|
+
|
67
|
+
# This may be useful when using a local installation of the SmartyStreets APIs.
|
68
|
+
# base_url is a string that defaults to the URL for the API corresponding to the Client object being built.
|
69
|
+
#
|
70
|
+
# Returns self to accommodate method chaining.
|
71
|
+
def with_base_url(base_url)
|
72
|
+
@url_prefix = base_url
|
73
|
+
self
|
74
|
+
end
|
75
|
+
|
76
|
+
def build_international_street_api_client
|
77
|
+
ensure_url_prefix_not_null(INTERNATIONAL_STREET_API_URL)
|
78
|
+
InternationalStreet::Client.new(build_sender, @serializer)
|
79
|
+
end
|
80
|
+
|
81
|
+
def build_us_autocomplete_api_client
|
82
|
+
ensure_url_prefix_not_null(US_AUTOCOMPLETE_API_URL)
|
83
|
+
USAutocomplete::Client.new(build_sender, @serializer)
|
84
|
+
end
|
85
|
+
|
86
|
+
def build_us_extract_api_client
|
87
|
+
ensure_url_prefix_not_null(US_EXTRACT_API_URL)
|
88
|
+
USExtract::Client.new(build_sender, @serializer)
|
89
|
+
end
|
90
|
+
|
91
|
+
def build_us_street_api_client
|
92
|
+
ensure_url_prefix_not_null(US_STREET_API_URL)
|
93
|
+
USStreet::Client.new(build_sender, @serializer)
|
94
|
+
end
|
95
|
+
|
96
|
+
def build_us_zipcode_api_client
|
97
|
+
ensure_url_prefix_not_null(US_ZIP_CODE_API_URL)
|
98
|
+
USZipcode::Client.new(build_sender, @serializer)
|
99
|
+
end
|
100
|
+
|
101
|
+
def build_sender
|
102
|
+
return @http_sender unless @http_sender.nil?
|
103
|
+
|
104
|
+
sender = NativeSender.new(@max_timeout)
|
105
|
+
|
106
|
+
sender = StatusCodeSender.new(sender)
|
107
|
+
|
108
|
+
sender = SigningSender.new(@signer, sender) unless @signer.nil?
|
109
|
+
|
110
|
+
sender = RetrySender.new(@max_retries, sender, SmartystreetsRubySdk::Sleeper.new, SmartystreetsRubySdk::Logger.new) if @max_retries > 0
|
111
|
+
|
112
|
+
URLPrefixSender.new(@url_prefix, sender)
|
113
|
+
end
|
114
|
+
|
115
|
+
def ensure_url_prefix_not_null(url)
|
116
|
+
@url_prefix = url if @url_prefix.nil?
|
117
|
+
end
|
118
|
+
end
|
@@ -1,17 +1,25 @@
|
|
1
1
|
BAD_CREDENTIALS = 'Unauthorized: The credentials were provided incorrectly or did not match any existing,
|
2
|
-
active credentials.'
|
2
|
+
active credentials.'.freeze
|
3
3
|
|
4
4
|
PAYMENT_REQUIRED = 'Payment Required: There is no active subscription
|
5
|
-
for the account associated with the credentials submitted with the request.'
|
5
|
+
for the account associated with the credentials submitted with the request.'.freeze
|
6
6
|
|
7
|
-
|
7
|
+
FORBIDDEN = 'Because the international service is currently in a limited release phase, only approved accounts' \
|
8
|
+
' may access the service.'.freeze
|
9
|
+
|
10
|
+
REQUEST_ENTITY_TOO_LARGE = 'Request Entity Too Large: The request body has exceeded the maximum size.'.freeze
|
8
11
|
|
9
12
|
BAD_REQUEST = 'Bad Request (Malformed Payload): A GET request lacked a street field or the request body of a
|
10
|
-
POST request contained malformed JSON.'
|
13
|
+
POST request contained malformed JSON.'.freeze
|
14
|
+
|
15
|
+
UNPROCESSABLE_ENTITY = 'GET request lacked required fields.'.freeze
|
11
16
|
|
12
17
|
TOO_MANY_REQUESTS = 'When using public "website key" authentication,
|
13
|
-
we restrict the number of requests coming from a given source over too short of a time.'
|
18
|
+
we restrict the number of requests coming from a given source over too short of a time.'.freeze
|
19
|
+
|
20
|
+
INTERNAL_SERVER_ERROR = 'Internal Server Error.'.freeze
|
14
21
|
|
15
|
-
|
22
|
+
SERVICE_UNAVAILABLE = 'Service Unavailable. Try again later.'.freeze
|
16
23
|
|
17
|
-
|
24
|
+
GATEWAY_TIMEOUT = 'The upstream data provider did not respond in a timely fashion and the request failed. ' \
|
25
|
+
'A serious, yet rare occurrence indeed.'.freeze
|