smartystreets_ruby_sdk 3.1.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Makefile +1 -1
- data/examples/international_example.rb +3 -3
- data/examples/us_autocomplete_example.rb +3 -3
- data/examples/us_extract_example.rb +3 -3
- data/examples/us_street_multiple_address_example.rb +6 -5
- data/examples/us_street_single_address_example.rb +5 -5
- data/examples/us_zipcode_multiple_lookup_example.rb +6 -5
- data/examples/us_zipcode_single_lookup_example.rb +4 -4
- data/lib/smartystreets_ruby_sdk.rb +26 -4
- data/lib/smartystreets_ruby_sdk/batch.rb +44 -41
- data/lib/smartystreets_ruby_sdk/client_builder.rb +115 -113
- data/lib/smartystreets_ruby_sdk/custom_header_sender.rb +10 -8
- data/lib/smartystreets_ruby_sdk/errors.rb +13 -11
- data/lib/smartystreets_ruby_sdk/exceptions.rb +27 -23
- data/lib/smartystreets_ruby_sdk/international_street.rb +3 -1
- data/lib/smartystreets_ruby_sdk/international_street/analysis.rb +11 -9
- data/lib/smartystreets_ruby_sdk/international_street/candidate.rb +28 -26
- data/lib/smartystreets_ruby_sdk/international_street/client.rb +45 -43
- data/lib/smartystreets_ruby_sdk/international_street/components.rb +53 -51
- data/lib/smartystreets_ruby_sdk/international_street/language_mode.rb +7 -3
- data/lib/smartystreets_ruby_sdk/international_street/lookup.rb +63 -61
- data/lib/smartystreets_ruby_sdk/international_street/metadata.rb +12 -10
- data/lib/smartystreets_ruby_sdk/json_able.rb +13 -11
- data/lib/smartystreets_ruby_sdk/logger.rb +2 -2
- data/lib/smartystreets_ruby_sdk/native_sender.rb +58 -56
- data/lib/smartystreets_ruby_sdk/native_serializer.rb +9 -7
- data/lib/smartystreets_ruby_sdk/proxy.rb +2 -2
- data/lib/smartystreets_ruby_sdk/request.rb +11 -9
- data/lib/smartystreets_ruby_sdk/response.rb +9 -7
- data/lib/smartystreets_ruby_sdk/retry_sender.rb +26 -24
- data/lib/smartystreets_ruby_sdk/shared_credentials.rb +11 -9
- data/lib/smartystreets_ruby_sdk/signing_sender.rb +11 -9
- data/lib/smartystreets_ruby_sdk/sleeper.rb +1 -1
- data/lib/smartystreets_ruby_sdk/static_credentials.rb +11 -9
- data/lib/smartystreets_ruby_sdk/status_code_sender.rb +31 -29
- data/lib/smartystreets_ruby_sdk/url_prefix_sender.rb +11 -9
- data/lib/smartystreets_ruby_sdk/us_autocomplete.rb +3 -1
- data/lib/smartystreets_ruby_sdk/us_autocomplete/client.rb +47 -45
- data/lib/smartystreets_ruby_sdk/us_autocomplete/geolocation_type.rb +9 -5
- data/lib/smartystreets_ruby_sdk/us_autocomplete/lookup.rb +26 -24
- data/lib/smartystreets_ruby_sdk/us_autocomplete/suggestion.rb +11 -9
- data/lib/smartystreets_ruby_sdk/us_extract.rb +4 -2
- data/lib/smartystreets_ruby_sdk/us_extract/address.rb +18 -16
- data/lib/smartystreets_ruby_sdk/us_extract/client.rb +34 -32
- data/lib/smartystreets_ruby_sdk/us_extract/lookup.rb +16 -14
- data/lib/smartystreets_ruby_sdk/us_extract/metadata.rb +13 -11
- data/lib/smartystreets_ruby_sdk/us_extract/result.rb +13 -11
- data/lib/smartystreets_ruby_sdk/us_street.rb +4 -2
- data/lib/smartystreets_ruby_sdk/us_street/analysis.rb +19 -17
- data/lib/smartystreets_ruby_sdk/us_street/candidate.rb +19 -17
- data/lib/smartystreets_ruby_sdk/us_street/client.rb +51 -49
- data/lib/smartystreets_ruby_sdk/us_street/components.rb +32 -30
- data/lib/smartystreets_ruby_sdk/us_street/lookup.rb +27 -26
- data/lib/smartystreets_ruby_sdk/us_street/match_type.rb +9 -5
- data/lib/smartystreets_ruby_sdk/us_street/metadata.rb +26 -24
- data/lib/smartystreets_ruby_sdk/us_zipcode.rb +4 -2
- data/lib/smartystreets_ruby_sdk/us_zipcode/alternate_county.rb +12 -10
- data/lib/smartystreets_ruby_sdk/us_zipcode/city.rb +13 -11
- data/lib/smartystreets_ruby_sdk/us_zipcode/client.rb +46 -44
- data/lib/smartystreets_ruby_sdk/us_zipcode/lookup.rb +16 -13
- data/lib/smartystreets_ruby_sdk/us_zipcode/result.rb +33 -31
- data/lib/smartystreets_ruby_sdk/us_zipcode/zip_code.rb +24 -21
- data/lib/smartystreets_ruby_sdk/version.rb +2 -2
- data/smartystreets_ruby_sdk.gemspec +1 -1
- metadata +2 -2
data/Makefile
CHANGED
@@ -3,13 +3,13 @@ require 'smartystreets_ruby_sdk/client_builder'
|
|
3
3
|
require 'smartystreets_ruby_sdk/international_street/lookup'
|
4
4
|
|
5
5
|
class InternationalExample
|
6
|
-
Lookup = InternationalStreet::Lookup
|
6
|
+
Lookup = SmartyStreets::InternationalStreet::Lookup
|
7
7
|
|
8
8
|
def run
|
9
9
|
auth_id = ENV['SMARTY_AUTH_ID'] # We recommend storing your keys in environment variables
|
10
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
|
11
|
+
credentials = SmartyStreets::StaticCredentials.new(auth_id, auth_token)
|
12
|
+
client = SmartyStreets::ClientBuilder.new(credentials).build_international_street_api_client
|
13
13
|
|
14
14
|
lookup = Lookup.new("Rua Padre Antonio D'Angelo 121 Casa Verde, Sao Paulo", 'Brazil')
|
15
15
|
lookup.geocode = true # Must be expressly set to get latitude and longitude.
|
@@ -3,13 +3,13 @@ require 'smartystreets_ruby_sdk/client_builder'
|
|
3
3
|
require 'smartystreets_ruby_sdk/us_autocomplete/lookup'
|
4
4
|
|
5
5
|
class USAutocompleteExample
|
6
|
-
Lookup = USAutocomplete::Lookup
|
6
|
+
Lookup = SmartyStreets::USAutocomplete::Lookup
|
7
7
|
|
8
8
|
def run
|
9
9
|
auth_id = ENV['SMARTY_AUTH_ID'] # We recommend storing your keys in environment variables
|
10
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
|
11
|
+
credentials = SmartyStreets::StaticCredentials.new(auth_id, auth_token)
|
12
|
+
client = SmartyStreets::ClientBuilder.new(credentials).build_us_autocomplete_api_client
|
13
13
|
lookup = Lookup.new('4770 Lincoln Ave O')
|
14
14
|
|
15
15
|
client.send(lookup)
|
@@ -3,14 +3,14 @@ require 'smartystreets_ruby_sdk/client_builder'
|
|
3
3
|
require 'smartystreets_ruby_sdk/us_extract/lookup'
|
4
4
|
|
5
5
|
class USExtractExample
|
6
|
-
Lookup = USExtract::Lookup
|
6
|
+
Lookup = SmartyStreets::USExtract::Lookup
|
7
7
|
|
8
8
|
def run
|
9
9
|
auth_id = ENV['SMARTY_AUTH_ID'] # We recommend storing your keys in environment variables
|
10
10
|
auth_token = ENV['SMARTY_AUTH_TOKEN']
|
11
|
-
credentials = StaticCredentials.new(auth_id, auth_token)
|
11
|
+
credentials = SmartyStreets::StaticCredentials.new(auth_id, auth_token)
|
12
12
|
|
13
|
-
client = ClientBuilder.new(credentials).build_us_extract_api_client
|
13
|
+
client = SmartyStreets::ClientBuilder.new(credentials).build_us_extract_api_client
|
14
14
|
|
15
15
|
text = "Here is some text.\r\nMy address is 3785 Las Vegs Av." \
|
16
16
|
"\r\nLos Vegas, Nevada." \
|
@@ -1,17 +1,18 @@
|
|
1
1
|
require 'smartystreets_ruby_sdk/static_credentials'
|
2
2
|
require 'smartystreets_ruby_sdk/client_builder'
|
3
|
+
require 'smartystreets_ruby_sdk/batch'
|
3
4
|
require 'smartystreets_ruby_sdk/us_street/lookup'
|
4
5
|
|
5
6
|
class USStreetMultipleAddressExample
|
6
|
-
Lookup = USStreet::Lookup
|
7
|
+
Lookup = SmartyStreets::USStreet::Lookup
|
7
8
|
|
8
9
|
def run
|
9
10
|
auth_id = ENV['SMARTY_AUTH_ID'] # We recommend storing your keys in environment variables.
|
10
11
|
auth_token = ENV['SMARTY_AUTH_TOKEN']
|
11
|
-
credentials = StaticCredentials.new(auth_id, auth_token)
|
12
|
+
credentials = SmartyStreets::StaticCredentials.new(auth_id, auth_token)
|
12
13
|
|
13
|
-
client = ClientBuilder.new(credentials).build_us_street_api_client
|
14
|
-
batch = Batch.new
|
14
|
+
client = SmartyStreets::ClientBuilder.new(credentials).build_us_street_api_client
|
15
|
+
batch = SmartyStreets::Batch.new
|
15
16
|
|
16
17
|
batch.add(Lookup.new)
|
17
18
|
batch[0].street = '1600 amphitheatre parkway'
|
@@ -29,7 +30,7 @@ class USStreetMultipleAddressExample
|
|
29
30
|
|
30
31
|
begin
|
31
32
|
client.send_batch(batch)
|
32
|
-
rescue
|
33
|
+
rescue SmartyError => err
|
33
34
|
puts err
|
34
35
|
return
|
35
36
|
end
|
@@ -6,25 +6,25 @@ class USStreetSingleAddressExample
|
|
6
6
|
def run
|
7
7
|
auth_id = ENV['SMARTY_AUTH_ID'] # We recommend storing your keys in environment variables
|
8
8
|
auth_token = ENV['SMARTY_AUTH_TOKEN']
|
9
|
-
credentials = StaticCredentials.new(auth_id, auth_token)
|
9
|
+
credentials = SmartyStreets::StaticCredentials.new(auth_id, auth_token)
|
10
10
|
|
11
|
-
client = ClientBuilder.new(credentials).build_us_street_api_client
|
11
|
+
client = SmartyStreets::ClientBuilder.new(credentials).build_us_street_api_client
|
12
12
|
|
13
|
-
lookup = USStreet::Lookup.new
|
13
|
+
lookup = SmartyStreets::USStreet::Lookup.new
|
14
14
|
lookup.street = '1600 Amphitheatre Pkwy'
|
15
15
|
lookup.city = 'Mountain View'
|
16
16
|
lookup.state = 'CA'
|
17
17
|
|
18
18
|
begin
|
19
19
|
client.send_lookup(lookup)
|
20
|
-
rescue
|
20
|
+
rescue SmartyStreets::SmartyError => err
|
21
21
|
puts err
|
22
22
|
return
|
23
23
|
end
|
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,17 +1,18 @@
|
|
1
1
|
require 'smartystreets_ruby_sdk/static_credentials'
|
2
2
|
require 'smartystreets_ruby_sdk/client_builder'
|
3
|
+
require 'smartystreets_ruby_sdk/batch'
|
3
4
|
require 'smartystreets_ruby_sdk/us_zipcode/lookup'
|
4
5
|
|
5
6
|
class USZipcodeMultipleLookupExample
|
6
|
-
Lookup = USZipcode::Lookup
|
7
|
+
Lookup = SmartyStreets::USZipcode::Lookup
|
7
8
|
|
8
9
|
def run
|
9
10
|
auth_id = ENV['SMARTY_AUTH_ID'] # We recommend storing your keys in environment variables
|
10
11
|
auth_token = ENV['SMARTY_AUTH_TOKEN']
|
11
|
-
credentials = StaticCredentials.new(auth_id, auth_token)
|
12
|
+
credentials = SmartyStreets::StaticCredentials.new(auth_id, auth_token)
|
12
13
|
|
13
|
-
client = ClientBuilder.new(credentials).build_us_zipcode_api_client
|
14
|
-
batch = Batch.new
|
14
|
+
client = SmartyStreets::ClientBuilder.new(credentials).build_us_zipcode_api_client
|
15
|
+
batch = SmartyStreets::Batch.new
|
15
16
|
|
16
17
|
batch.add(Lookup.new)
|
17
18
|
batch[0].zipcode = '12345' # A Lookup may have a ZIP Code, city and state, or city, state, and ZIP Code
|
@@ -25,7 +26,7 @@ class USZipcodeMultipleLookupExample
|
|
25
26
|
|
26
27
|
begin
|
27
28
|
client.send_batch(batch)
|
28
|
-
rescue
|
29
|
+
rescue SmartyError => err
|
29
30
|
puts err
|
30
31
|
return
|
31
32
|
end
|
@@ -6,17 +6,17 @@ class UsZipcodeSingleLookupExample
|
|
6
6
|
def run
|
7
7
|
auth_id = ENV['SMARTY_AUTH_ID'] # We recommend storing your keys in environment variables.
|
8
8
|
auth_token = ENV['SMARTY_AUTH_TOKEN']
|
9
|
-
credentials = StaticCredentials.new(auth_id, auth_token)
|
9
|
+
credentials = SmartyStreets::StaticCredentials.new(auth_id, auth_token)
|
10
10
|
|
11
|
-
client = ClientBuilder.new(credentials).build_us_zipcode_api_client
|
11
|
+
client = SmartyStreets::ClientBuilder.new(credentials).build_us_zipcode_api_client
|
12
12
|
|
13
|
-
lookup = USZipcode::Lookup.new
|
13
|
+
lookup = SmartyStreets::USZipcode::Lookup.new
|
14
14
|
lookup.city = 'Mountain View'
|
15
15
|
lookup.state = 'California'
|
16
16
|
|
17
17
|
begin
|
18
18
|
client.send_lookup(lookup)
|
19
|
-
rescue
|
19
|
+
rescue SmartyError => err
|
20
20
|
puts err
|
21
21
|
return
|
22
22
|
end
|
@@ -1,6 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require 'smartystreets_ruby_sdk/version'
|
2
|
+
require 'smartystreets_ruby_sdk/logger'
|
3
|
+
require 'smartystreets_ruby_sdk/sleeper'
|
4
4
|
|
5
|
-
|
5
|
+
require 'smartystreets_ruby_sdk/batch'
|
6
|
+
require 'smartystreets_ruby_sdk/client_builder'
|
7
|
+
require 'smartystreets_ruby_sdk/custom_header_sender'
|
8
|
+
require 'smartystreets_ruby_sdk/errors'
|
9
|
+
require 'smartystreets_ruby_sdk/exceptions'
|
10
|
+
require 'smartystreets_ruby_sdk/json_able'
|
11
|
+
require 'smartystreets_ruby_sdk/logger'
|
12
|
+
require 'smartystreets_ruby_sdk/native_sender'
|
13
|
+
require 'smartystreets_ruby_sdk/native_serializer'
|
14
|
+
require 'smartystreets_ruby_sdk/request'
|
15
|
+
require 'smartystreets_ruby_sdk/response'
|
16
|
+
require 'smartystreets_ruby_sdk/retry_sender'
|
17
|
+
require 'smartystreets_ruby_sdk/shared_credentials'
|
18
|
+
require 'smartystreets_ruby_sdk/signing_sender'
|
19
|
+
require 'smartystreets_ruby_sdk/static_credentials'
|
20
|
+
require 'smartystreets_ruby_sdk/status_code_sender'
|
21
|
+
require 'smartystreets_ruby_sdk/url_prefix_sender'
|
22
|
+
|
23
|
+
require 'smartystreets_ruby_sdk/us_extract'
|
24
|
+
require 'smartystreets_ruby_sdk/us_street'
|
25
|
+
require 'smartystreets_ruby_sdk/us_zipcode'
|
26
|
+
|
27
|
+
module SmartyStreets
|
6
28
|
end
|
@@ -1,56 +1,59 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
module SmartyStreets
|
2
|
+
# The Batch class is used to send up to 100 lookups at once
|
3
|
+
class Batch
|
4
|
+
include Enumerable
|
5
|
+
MAX_BATCH_SIZE = 100
|
4
6
|
|
5
|
-
|
7
|
+
attr_reader :all_lookups, :named_lookups
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
def initialize
|
10
|
+
@named_lookups = {}
|
11
|
+
@all_lookups = []
|
12
|
+
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
+
def add(lookup)
|
15
|
+
return false if full?
|
14
16
|
|
15
|
-
|
17
|
+
@all_lookups.push(lookup)
|
16
18
|
|
17
|
-
|
19
|
+
return true if lookup.input_id.nil?
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
@named_lookups[lookup.input_id] = lookup
|
22
|
+
true
|
23
|
+
end
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
def clear
|
26
|
+
@named_lookups.clear
|
27
|
+
@all_lookups.clear
|
28
|
+
end
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
def full?
|
31
|
+
size >= MAX_BATCH_SIZE
|
32
|
+
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
def empty?
|
35
|
+
size.zero?
|
36
|
+
end
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
38
|
+
def size
|
39
|
+
@all_lookups.length
|
40
|
+
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
|
42
|
+
def get_by_input_id(input_id)
|
43
|
+
@named_lookups[input_id]
|
44
|
+
end
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
-
|
46
|
+
def get_by_index(index)
|
47
|
+
@all_lookups[index]
|
48
|
+
end
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
-
|
50
|
+
def each(&block)
|
51
|
+
@all_lookups.each(&block)
|
52
|
+
end
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
-
|
54
|
+
def [](index)
|
55
|
+
@all_lookups[index]
|
56
|
+
end
|
55
57
|
|
56
|
-
end
|
58
|
+
end
|
59
|
+
end
|
@@ -12,117 +12,119 @@ require_relative 'us_extract/client'
|
|
12
12
|
require_relative 'us_autocomplete/client'
|
13
13
|
require_relative 'international_street/client'
|
14
14
|
|
15
|
-
|
16
|
-
#
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
15
|
+
module SmartyStreets
|
16
|
+
# The ClientBuilder class helps you build a client object for one of the supported SmartyStreets APIs.
|
17
|
+
# You can use ClientBuilder's methods to customize settings like maximum retries or timeout duration.
|
18
|
+
# These methods are chainable, so you can usually get set up with one line of code.
|
19
|
+
class ClientBuilder
|
20
|
+
INTERNATIONAL_STREET_API_URL = 'https://international-street.api.smartystreets.com/verify'.freeze
|
21
|
+
US_AUTOCOMPLETE_API_URL = 'https://us-autocomplete.api.smartystreets.com/suggest'.freeze
|
22
|
+
US_EXTRACT_API_URL = 'https://us-extract.api.smartystreets.com/'.freeze
|
23
|
+
US_STREET_API_URL = 'https://us-street.api.smartystreets.com/street-address'.freeze
|
24
|
+
US_ZIP_CODE_API_URL = 'https://us-zipcode.api.smartystreets.com/lookup'.freeze
|
25
|
+
|
26
|
+
def initialize(signer)
|
27
|
+
@signer = signer
|
28
|
+
@serializer = NativeSerializer.new
|
29
|
+
@http_sender = nil
|
30
|
+
@max_retries = 5
|
31
|
+
@max_timeout = 10_000
|
32
|
+
@url_prefix = nil
|
33
|
+
@proxy = nil
|
34
|
+
end
|
35
|
+
|
36
|
+
# Sets the maximum number of times to retry sending the request to the API. (Default is 5)
|
37
|
+
#
|
38
|
+
# Returns self to accommodate method chaining.
|
39
|
+
def retry_at_most(max_retries)
|
40
|
+
@max_retries = max_retries
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
# The maximum time (in milliseconds) to wait for a connection, and also to wait for
|
45
|
+
# the response to be read. (Default is 10000)
|
46
|
+
#
|
47
|
+
# Returns self to accommodate method chaining.
|
48
|
+
def with_max_timeout(max_timeout)
|
49
|
+
@max_timeout = max_timeout
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
53
|
+
# Default is a series of nested senders. (See build_sender()
|
54
|
+
#
|
55
|
+
# Returns self to accommodate method chaining.
|
56
|
+
def with_sender(sender)
|
57
|
+
@http_sender = sender
|
58
|
+
self
|
59
|
+
end
|
60
|
+
|
61
|
+
# Changes the Serializer from the default.
|
62
|
+
#
|
63
|
+
# Returns self to accommodate method chaining.
|
64
|
+
def with_serializer(serializer)
|
65
|
+
@serializer = serializer
|
66
|
+
self
|
67
|
+
end
|
68
|
+
|
69
|
+
# This may be useful when using a local installation of the SmartyStreets APIs.
|
70
|
+
# base_url is a string that defaults to the URL for the API corresponding to the Client object being built.
|
71
|
+
#
|
72
|
+
# Returns self to accommodate method chaining.
|
73
|
+
def with_base_url(base_url)
|
74
|
+
@url_prefix = base_url
|
75
|
+
self
|
76
|
+
end
|
77
|
+
|
78
|
+
# Assigns a proxy through which all requests will be sent.
|
79
|
+
# proxy is a Proxy object from this module.
|
80
|
+
#
|
81
|
+
# Returns self to accommodate method chaining.
|
82
|
+
def with_proxy(proxy)
|
83
|
+
@proxy = proxy
|
84
|
+
self
|
85
|
+
end
|
86
|
+
|
87
|
+
def build_international_street_api_client
|
88
|
+
ensure_url_prefix_not_null(INTERNATIONAL_STREET_API_URL)
|
89
|
+
InternationalStreet::Client.new(build_sender, @serializer)
|
90
|
+
end
|
91
|
+
|
92
|
+
def build_us_autocomplete_api_client
|
93
|
+
ensure_url_prefix_not_null(US_AUTOCOMPLETE_API_URL)
|
94
|
+
USAutocomplete::Client.new(build_sender, @serializer)
|
95
|
+
end
|
96
|
+
|
97
|
+
def build_us_extract_api_client
|
98
|
+
ensure_url_prefix_not_null(US_EXTRACT_API_URL)
|
99
|
+
USExtract::Client.new(build_sender, @serializer)
|
100
|
+
end
|
101
|
+
|
102
|
+
def build_us_street_api_client
|
103
|
+
ensure_url_prefix_not_null(US_STREET_API_URL)
|
104
|
+
USStreet::Client.new(build_sender, @serializer)
|
105
|
+
end
|
106
|
+
|
107
|
+
def build_us_zipcode_api_client
|
108
|
+
ensure_url_prefix_not_null(US_ZIP_CODE_API_URL)
|
109
|
+
USZipcode::Client.new(build_sender, @serializer)
|
110
|
+
end
|
111
|
+
|
112
|
+
def build_sender
|
113
|
+
return @http_sender unless @http_sender.nil?
|
114
|
+
|
115
|
+
sender = NativeSender.new(@max_timeout, @proxy)
|
116
|
+
|
117
|
+
sender = StatusCodeSender.new(sender)
|
118
|
+
|
119
|
+
sender = SigningSender.new(@signer, sender) unless @signer.nil?
|
120
|
+
|
121
|
+
sender = RetrySender.new(@max_retries, sender, SmartyStreets::Sleeper.new,SmartyStreets::Logger.new) if @max_retries > 0
|
122
|
+
|
123
|
+
URLPrefixSender.new(@url_prefix, sender)
|
124
|
+
end
|
125
|
+
|
126
|
+
def ensure_url_prefix_not_null(url)
|
127
|
+
@url_prefix = url if @url_prefix.nil?
|
128
|
+
end
|
33
129
|
end
|
34
|
-
|
35
|
-
# Sets the maximum number of times to retry sending the request to the API. (Default is 5)
|
36
|
-
#
|
37
|
-
# Returns self to accommodate method chaining.
|
38
|
-
def retry_at_most(max_retries)
|
39
|
-
@max_retries = max_retries
|
40
|
-
self
|
41
|
-
end
|
42
|
-
|
43
|
-
# The maximum time (in milliseconds) to wait for a connection, and also to wait for
|
44
|
-
# the response to be read. (Default is 10000)
|
45
|
-
#
|
46
|
-
# Returns self to accommodate method chaining.
|
47
|
-
def with_max_timeout(max_timeout)
|
48
|
-
@max_timeout = max_timeout
|
49
|
-
self
|
50
|
-
end
|
51
|
-
|
52
|
-
# Default is a series of nested senders. (See build_sender()
|
53
|
-
#
|
54
|
-
# Returns self to accommodate method chaining.
|
55
|
-
def with_sender(sender)
|
56
|
-
@http_sender = sender
|
57
|
-
self
|
58
|
-
end
|
59
|
-
|
60
|
-
# Changes the Serializer from the default.
|
61
|
-
#
|
62
|
-
# Returns self to accommodate method chaining.
|
63
|
-
def with_serializer(serializer)
|
64
|
-
@serializer = serializer
|
65
|
-
self
|
66
|
-
end
|
67
|
-
|
68
|
-
# This may be useful when using a local installation of the SmartyStreets APIs.
|
69
|
-
# base_url is a string that defaults to the URL for the API corresponding to the Client object being built.
|
70
|
-
#
|
71
|
-
# Returns self to accommodate method chaining.
|
72
|
-
def with_base_url(base_url)
|
73
|
-
@url_prefix = base_url
|
74
|
-
self
|
75
|
-
end
|
76
|
-
|
77
|
-
# Assigns a proxy through which all requests will be sent.
|
78
|
-
# proxy is a Proxy object from this module.
|
79
|
-
#
|
80
|
-
# Returns self to accommodate method chaining.
|
81
|
-
def with_proxy(proxy)
|
82
|
-
@proxy = proxy
|
83
|
-
self
|
84
|
-
end
|
85
|
-
|
86
|
-
def build_international_street_api_client
|
87
|
-
ensure_url_prefix_not_null(INTERNATIONAL_STREET_API_URL)
|
88
|
-
InternationalStreet::Client.new(build_sender, @serializer)
|
89
|
-
end
|
90
|
-
|
91
|
-
def build_us_autocomplete_api_client
|
92
|
-
ensure_url_prefix_not_null(US_AUTOCOMPLETE_API_URL)
|
93
|
-
USAutocomplete::Client.new(build_sender, @serializer)
|
94
|
-
end
|
95
|
-
|
96
|
-
def build_us_extract_api_client
|
97
|
-
ensure_url_prefix_not_null(US_EXTRACT_API_URL)
|
98
|
-
USExtract::Client.new(build_sender, @serializer)
|
99
|
-
end
|
100
|
-
|
101
|
-
def build_us_street_api_client
|
102
|
-
ensure_url_prefix_not_null(US_STREET_API_URL)
|
103
|
-
USStreet::Client.new(build_sender, @serializer)
|
104
|
-
end
|
105
|
-
|
106
|
-
def build_us_zipcode_api_client
|
107
|
-
ensure_url_prefix_not_null(US_ZIP_CODE_API_URL)
|
108
|
-
USZipcode::Client.new(build_sender, @serializer)
|
109
|
-
end
|
110
|
-
|
111
|
-
def build_sender
|
112
|
-
return @http_sender unless @http_sender.nil?
|
113
|
-
|
114
|
-
sender = NativeSender.new(@max_timeout, @proxy)
|
115
|
-
|
116
|
-
sender = StatusCodeSender.new(sender)
|
117
|
-
|
118
|
-
sender = SigningSender.new(@signer, sender) unless @signer.nil?
|
119
|
-
|
120
|
-
sender = RetrySender.new(@max_retries, sender, SmartystreetsRubySdk::Sleeper.new, SmartystreetsRubySdk::Logger.new) if @max_retries > 0
|
121
|
-
|
122
|
-
URLPrefixSender.new(@url_prefix, sender)
|
123
|
-
end
|
124
|
-
|
125
|
-
def ensure_url_prefix_not_null(url)
|
126
|
-
@url_prefix = url if @url_prefix.nil?
|
127
|
-
end
|
128
|
-
end
|
130
|
+
end
|