smartystreets_ruby_sdk 3.1.0 → 4.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.
- 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
@@ -1,11 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module SmartyStreets
|
2
|
+
class CustomHeaderSender
|
3
|
+
def initialize(inner, headers)
|
4
|
+
@inner = inner
|
5
|
+
@headers = headers
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def send(request)
|
9
|
+
request.headers = @headers
|
10
|
+
@inner.send(request)
|
11
|
+
end
|
10
12
|
end
|
11
13
|
end
|
@@ -1,25 +1,27 @@
|
|
1
|
-
|
1
|
+
module SmartyStreets
|
2
|
+
BAD_CREDENTIALS = 'Unauthorized: The credentials were provided incorrectly or did not match any existing,
|
2
3
|
active credentials.'.freeze
|
3
4
|
|
4
|
-
PAYMENT_REQUIRED = 'Payment Required: There is no active subscription
|
5
|
+
PAYMENT_REQUIRED = 'Payment Required: There is no active subscription
|
5
6
|
for the account associated with the credentials submitted with the request.'.freeze
|
6
7
|
|
7
|
-
FORBIDDEN = 'Because the international service is currently in a limited release phase, only approved accounts' \
|
8
|
+
FORBIDDEN = 'Because the international service is currently in a limited release phase, only approved accounts' \
|
8
9
|
' may access the service.'.freeze
|
9
10
|
|
10
|
-
REQUEST_ENTITY_TOO_LARGE = 'Request Entity Too Large: The request body has exceeded the maximum size.'.freeze
|
11
|
+
REQUEST_ENTITY_TOO_LARGE = 'Request Entity Too Large: The request body has exceeded the maximum size.'.freeze
|
11
12
|
|
12
|
-
BAD_REQUEST = 'Bad Request (Malformed Payload): A GET request lacked a street field or the request body of a
|
13
|
+
BAD_REQUEST = 'Bad Request (Malformed Payload): A GET request lacked a street field or the request body of a
|
13
14
|
POST request contained malformed JSON.'.freeze
|
14
15
|
|
15
|
-
UNPROCESSABLE_ENTITY = 'GET request lacked required fields.'.freeze
|
16
|
+
UNPROCESSABLE_ENTITY = 'GET request lacked required fields.'.freeze
|
16
17
|
|
17
|
-
TOO_MANY_REQUESTS = 'When using public "website key" authentication,
|
18
|
+
TOO_MANY_REQUESTS = 'When using public "website key" authentication,
|
18
19
|
we restrict the number of requests coming from a given source over too short of a time.'.freeze
|
19
20
|
|
20
|
-
INTERNAL_SERVER_ERROR = 'Internal Server Error.'.freeze
|
21
|
+
INTERNAL_SERVER_ERROR = 'Internal Server Error.'.freeze
|
21
22
|
|
22
|
-
SERVICE_UNAVAILABLE = 'Service Unavailable. Try again later.'.freeze
|
23
|
+
SERVICE_UNAVAILABLE = 'Service Unavailable. Try again later.'.freeze
|
23
24
|
|
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
|
25
|
+
GATEWAY_TIMEOUT = 'The upstream data provider did not respond in a timely fashion and the request failed. ' \
|
26
|
+
'A serious, yet rare occurrence indeed.'.freeze
|
27
|
+
end
|
@@ -1,35 +1,39 @@
|
|
1
|
-
|
2
|
-
end
|
1
|
+
module SmartyStreets
|
3
2
|
|
4
|
-
class
|
5
|
-
end
|
3
|
+
class SmartyError < StandardError
|
4
|
+
end
|
6
5
|
|
7
|
-
class
|
8
|
-
end
|
6
|
+
class BadCredentialsError < SmartyError
|
7
|
+
end
|
9
8
|
|
10
|
-
class
|
11
|
-
end
|
9
|
+
class ForbiddenError < SmartyError
|
10
|
+
end
|
12
11
|
|
13
|
-
class
|
14
|
-
end
|
12
|
+
class PaymentRequiredError < SmartyError
|
13
|
+
end
|
15
14
|
|
16
|
-
class
|
17
|
-
end
|
15
|
+
class RequestEntityTooLargeError < SmartyError
|
16
|
+
end
|
18
17
|
|
19
|
-
class
|
20
|
-
end
|
18
|
+
class BadRequestError < SmartyError
|
19
|
+
end
|
21
20
|
|
22
|
-
class
|
23
|
-
end
|
21
|
+
class UnprocessableEntityError < SmartyError
|
22
|
+
end
|
24
23
|
|
25
|
-
class
|
26
|
-
end
|
24
|
+
class TooManyRequestsError < SmartyError
|
25
|
+
end
|
27
26
|
|
28
|
-
class
|
29
|
-
end
|
27
|
+
class InternalServerError < SmartyError
|
28
|
+
end
|
30
29
|
|
31
|
-
class
|
32
|
-
end
|
30
|
+
class ServiceUnavailableError < SmartyError
|
31
|
+
end
|
32
|
+
|
33
|
+
class GatewayTimeoutError < SmartyError
|
34
|
+
end
|
35
|
+
|
36
|
+
class BatchFullError < SmartyError
|
37
|
+
end
|
33
38
|
|
34
|
-
class BatchFullError < SmartyException
|
35
39
|
end
|
@@ -1,13 +1,15 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
1
|
+
module SmartyStreets
|
2
|
+
module InternationalStreet
|
3
|
+
# See "https://smartystreets.com/docs/cloud/international-street-api#analysis"
|
4
|
+
class Analysis
|
4
5
|
|
5
|
-
|
6
|
+
attr_reader :max_address_precision, :verification_status, :address_precision
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
def initialize(obj)
|
9
|
+
@verification_status = obj.fetch('verification_status', nil)
|
10
|
+
@address_precision = obj.fetch('address_precision', nil)
|
11
|
+
@max_address_precision = obj.fetch('max_address_precision', nil)
|
12
|
+
end
|
11
13
|
end
|
12
14
|
end
|
13
|
-
end
|
15
|
+
end
|
@@ -2,32 +2,34 @@ require_relative 'components'
|
|
2
2
|
require_relative 'metadata'
|
3
3
|
require_relative 'analysis'
|
4
4
|
|
5
|
-
module
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
module SmartyStreets
|
6
|
+
module InternationalStreet
|
7
|
+
# A candidate is a possible match for an address that was submitted. A lookup can have multiple
|
8
|
+
# candidates if the address was ambiguous.
|
9
|
+
#
|
10
|
+
# See "https://smartystreets.com/docs/cloud/international-street-api#root"
|
11
|
+
class Candidate
|
12
|
+
attr_reader :metadata, :address3, :address11, :address2, :address12, :address1, :address10,
|
13
|
+
:address9, :address8, :address7, :organization, :address6, :address5, :address4, :components, :analysis
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
15
|
+
def initialize(obj)
|
16
|
+
@organization = obj.fetch('organization', nil)
|
17
|
+
@address1 = obj.fetch('address1', nil)
|
18
|
+
@address2 = obj.fetch('address2', nil)
|
19
|
+
@address3 = obj.fetch('address3', nil)
|
20
|
+
@address4 = obj.fetch('address4', nil)
|
21
|
+
@address5 = obj.fetch('address5', nil)
|
22
|
+
@address6 = obj.fetch('address6', nil)
|
23
|
+
@address7 = obj.fetch('address7', nil)
|
24
|
+
@address8 = obj.fetch('address8', nil)
|
25
|
+
@address9 = obj.fetch('address9', nil)
|
26
|
+
@address10 = obj.fetch('address10', nil)
|
27
|
+
@address11 = obj.fetch('address11', nil)
|
28
|
+
@address12 = obj.fetch('address12', nil)
|
29
|
+
@components = Components.new(obj.fetch('components', {}))
|
30
|
+
@metadata = Metadata.new(obj.fetch('metadata', {}))
|
31
|
+
@analysis = Analysis.new(obj.fetch('analysis', {}))
|
32
|
+
end
|
31
33
|
end
|
32
34
|
end
|
33
|
-
end
|
35
|
+
end
|
@@ -1,56 +1,58 @@
|
|
1
1
|
require_relative '../request'
|
2
2
|
require_relative 'candidate'
|
3
3
|
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
module SmartyStreets
|
5
|
+
module InternationalStreet
|
6
|
+
# It is recommended to instantiate this class using ClientBuilder.build_international_street_api_client()
|
7
|
+
class Client
|
8
|
+
def initialize(sender, serializer)
|
9
|
+
@sender = sender
|
10
|
+
@serializer = serializer
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
# Sends a Lookup object to the International Street API and stores the result in the Lookup's result field.
|
14
|
+
def send(lookup)
|
15
|
+
lookup.ensure_enough_info
|
16
|
+
request = build_request(lookup)
|
16
17
|
|
17
|
-
|
18
|
+
response = @sender.send(request)
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
candidates = convert_candidates(@serializer.deserialize(response.payload))
|
21
|
+
lookup.result = candidates
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
24
|
+
def build_request(lookup)
|
25
|
+
request = SmartyStreets::Request.new
|
26
|
+
|
27
|
+
add_parameter(request, 'country', lookup.country)
|
28
|
+
add_parameter(request, 'geocode', lookup.geocode.to_s)
|
29
|
+
add_parameter(request, 'language', lookup.language)
|
30
|
+
add_parameter(request, 'freeform', lookup.freeform)
|
31
|
+
add_parameter(request, 'address1', lookup.address1)
|
32
|
+
add_parameter(request, 'address2', lookup.address2)
|
33
|
+
add_parameter(request, 'address3', lookup.address3)
|
34
|
+
add_parameter(request, 'address4', lookup.address4)
|
35
|
+
add_parameter(request, 'organization', lookup.organization)
|
36
|
+
add_parameter(request, 'locality', lookup.locality)
|
37
|
+
add_parameter(request, 'administrative_area', lookup.administrative_area)
|
38
|
+
add_parameter(request, 'postal_code', lookup.postal_code)
|
39
|
+
|
40
|
+
request
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
def add_parameter(request, key, value)
|
44
|
+
request.parameters[key] = value unless value.nil? or value.empty?
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
-
|
47
|
+
def convert_candidates(raw_candidates)
|
48
|
+
candidates = []
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
raw_candidates.each do |candidate|
|
51
|
+
candidates.push(Candidate.new(candidate))
|
52
|
+
end
|
52
53
|
|
53
|
-
|
54
|
+
candidates
|
55
|
+
end
|
54
56
|
end
|
55
57
|
end
|
56
|
-
end
|
58
|
+
end
|
@@ -1,55 +1,57 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
module SmartyStreets
|
2
|
+
module InternationalStreet
|
3
|
+
# See "https://smartystreets.com/docs/cloud/international-street-api#components"
|
4
|
+
class Components
|
5
|
+
attr_reader :premise, :thoroughfare_trailing_type, :sub_building, :locality, :post_box_number,
|
6
|
+
:thoroughfare_name, :thoroughfare_postdirection, :dependent_thoroughfare,
|
7
|
+
:thoroughfare, :dependent_thoroughfare_name, :postal_code_short, :dependent_thoroughfare_trailing_type,
|
8
|
+
:administrative_area, :post_box, :building_leading_type, :dependent_locality_name, :thoroughfare_type,
|
9
|
+
:dependent_thoroughfare_postdirection, :double_dependent_locality, :premise_number,
|
10
|
+
:dependent_thoroughfare_type, :post_box_type, :building, :sub_administrative_area, :postal_code_extra,
|
11
|
+
:sub_building_name, :postal_code, :dependent_locality, :premise_type, :sub_building_number,
|
12
|
+
:super_administrative_area, :premise_extra, :dependent_thoroughfare_predirection,
|
13
|
+
:building_trailing_type, :thoroughfare_predirection, :building_name, :country_iso_3, :sub_building_type
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
15
|
+
def initialize(obj)
|
16
|
+
@country_iso_3 = obj.fetch('country_iso_3', nil)
|
17
|
+
@super_administrative_area = obj.fetch('super_administrative_area', nil)
|
18
|
+
@administrative_area = obj.fetch('administrative_area', nil)
|
19
|
+
@sub_administrative_area = obj.fetch('sub_administrative_area', nil)
|
20
|
+
@dependent_locality= obj.fetch('dependent_locality', nil)
|
21
|
+
@dependent_locality_name = obj.fetch('dependent_locality_name', nil)
|
22
|
+
@double_dependent_locality = obj.fetch('double_dependent_locality', nil)
|
23
|
+
@locality = obj.fetch('locality', nil)
|
24
|
+
@postal_code = obj.fetch('postal_code', nil)
|
25
|
+
@postal_code_short = obj.fetch('postal_code_short', nil)
|
26
|
+
@postal_code_extra = obj.fetch('postal_code_extra', nil)
|
27
|
+
@premise = obj.fetch('premise', nil)
|
28
|
+
@premise_extra = obj.fetch('premise_extra', nil)
|
29
|
+
@premise_number = obj.fetch('premise_number', nil)
|
30
|
+
@premise_type = obj.fetch('premise_type', nil)
|
31
|
+
@thoroughfare = obj.fetch('thoroughfare', nil)
|
32
|
+
@thoroughfare_predirection = obj.fetch('thoroughfare_predirection', nil)
|
33
|
+
@thoroughfare_postdirection = obj.fetch('thoroughfare_postdirection', nil)
|
34
|
+
@thoroughfare_name = obj.fetch('thoroughfare_name', nil)
|
35
|
+
@thoroughfare_trailing_type = obj.fetch('thoroughfare_trailing_type', nil)
|
36
|
+
@thoroughfare_type = obj.fetch('thoroughfare_type', nil)
|
37
|
+
@dependent_thoroughfare = obj.fetch('dependent_thoroughfare', nil)
|
38
|
+
@dependent_thoroughfare_predirection = obj.fetch('dependent_thoroughfare_predirection', nil)
|
39
|
+
@dependent_thoroughfare_postdirection = obj.fetch('dependent_thoroughfare_postdirection', nil)
|
40
|
+
@dependent_thoroughfare_name = obj.fetch('dependent_thoroughfare_name', nil)
|
41
|
+
@dependent_thoroughfare_trailing_type = obj.fetch('dependent_thoroughfare_trailing_type', nil)
|
42
|
+
@dependent_thoroughfare_type = obj.fetch('dependent_thoroughfare_type', nil)
|
43
|
+
@building = obj.fetch('building', nil)
|
44
|
+
@building_leading_type = obj.fetch('building_leading_type', nil)
|
45
|
+
@building_name = obj.fetch('building_name', nil)
|
46
|
+
@building_trailing_type = obj.fetch('building_trailing_type', nil)
|
47
|
+
@sub_building_type = obj.fetch('sub_building_type', nil)
|
48
|
+
@sub_building_number = obj.fetch('sub_building_number', nil)
|
49
|
+
@sub_building_name = obj.fetch('sub_building_name', nil)
|
50
|
+
@sub_building = obj.fetch('sub_building', nil)
|
51
|
+
@post_box = obj.fetch('post_box', nil)
|
52
|
+
@post_box_type = obj.fetch('post_box_type', nil)
|
53
|
+
@post_box_number = obj.fetch('post_box_number', nil)
|
54
|
+
end
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|