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
@@ -1,31 +1,32 @@
|
|
1
1
|
require_relative '../json_able'
|
2
|
+
module SmartyStreets
|
3
|
+
module USStreet
|
4
|
+
# In addition to holding all of the input data for this lookup, this class also will contain
|
5
|
+
# the result of the lookup after it comes back from the API.
|
6
|
+
#
|
7
|
+
# See "https://smartystreets.com/docs/cloud/us-street-api#input-fields"
|
8
|
+
#
|
9
|
+
# @match:: Must be set to 'strict', 'range', or 'invalid'. Constants for these are in match_type.rb
|
10
|
+
class Lookup < JSONAble
|
11
|
+
attr_accessor :input_id, :street, :street2, :secondary, :city, :state, :zipcode, :lastline, :addressee, :urbanization,
|
12
|
+
:match, :candidates, :result
|
2
13
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
@secondary = secondary
|
20
|
-
@city = city
|
21
|
-
@state = state
|
22
|
-
@zipcode = zipcode
|
23
|
-
@lastline = lastline
|
24
|
-
@addressee = addressee
|
25
|
-
@urbanization = urbanization
|
26
|
-
@match = match
|
27
|
-
@candidates = candidates
|
28
|
-
@result = []
|
14
|
+
def initialize(street=nil, street2=nil, secondary=nil, city=nil, state=nil, zipcode=nil, lastline=nil,
|
15
|
+
addressee=nil, urbanization=nil, match=nil, candidates=1, input_id=nil)
|
16
|
+
@input_id = input_id
|
17
|
+
@street = street
|
18
|
+
@street2 = street2
|
19
|
+
@secondary = secondary
|
20
|
+
@city = city
|
21
|
+
@state = state
|
22
|
+
@zipcode = zipcode
|
23
|
+
@lastline = lastline
|
24
|
+
@addressee = addressee
|
25
|
+
@urbanization = urbanization
|
26
|
+
@match = match
|
27
|
+
@candidates = candidates
|
28
|
+
@result = []
|
29
|
+
end
|
29
30
|
end
|
30
31
|
end
|
31
32
|
end
|
@@ -1,5 +1,9 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module SmartyStreets
|
2
|
+
module USStreet
|
3
|
+
module MatchType
|
4
|
+
STRICT = 'strict'.freeze
|
5
|
+
RANGE = 'range'.freeze
|
6
|
+
INVALID = 'invalid'.freeze
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -1,27 +1,29 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module SmartyStreets
|
2
|
+
module USStreet
|
3
|
+
# See "https://smartystreets.com/docs/cloud/us-street-api#metadata"
|
4
|
+
class Metadata
|
5
|
+
attr_reader :elot_sort, :longitude, :elot_sequence, :county_fips, :building_default_indicator, :rdi,
|
6
|
+
:congressional_district, :latitude, :precision, :time_zone, :zip_type, :county_name, :utc_offset,
|
7
|
+
:record_type, :carrier_route, :obeys_dst
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
9
|
+
def initialize(obj)
|
10
|
+
@record_type = obj['record_type']
|
11
|
+
@zip_type = obj['zip_type']
|
12
|
+
@county_fips = obj['county_fips']
|
13
|
+
@county_name = obj['county_name']
|
14
|
+
@carrier_route = obj['carrier_route']
|
15
|
+
@congressional_district = obj['congressional_district']
|
16
|
+
@building_default_indicator = obj['building_default_indicator']
|
17
|
+
@rdi = obj['rdi']
|
18
|
+
@elot_sequence = obj['elot_sequence']
|
19
|
+
@elot_sort = obj['elot_sort']
|
20
|
+
@latitude = obj['latitude']
|
21
|
+
@longitude = obj['longitude']
|
22
|
+
@precision = obj['precision']
|
23
|
+
@time_zone = obj['time_zone']
|
24
|
+
@utc_offset = obj['utc_offset']
|
25
|
+
@obeys_dst = obj['dst']
|
26
|
+
end
|
25
27
|
end
|
26
28
|
end
|
27
|
-
end
|
29
|
+
end
|
@@ -1,13 +1,15 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module SmartyStreets
|
2
|
+
module USZipcode
|
3
|
+
# See "https://smartystreets.com/docs/cloud/us-zipcode-api#zipcodes"
|
4
|
+
class AlternateCounty
|
5
|
+
attr_reader :state_abbreviation, :state, :county_name, :county_fips
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
def initialize(obj)
|
8
|
+
@county_fips = obj.fetch('county_fips', nil)
|
9
|
+
@county_name = obj.fetch('county_name', nil)
|
10
|
+
@state_abbreviation = obj.fetch('state_abbreviation', nil)
|
11
|
+
@state = obj.fetch('state', nil)
|
12
|
+
end
|
11
13
|
end
|
12
14
|
end
|
13
|
-
end
|
15
|
+
end
|
@@ -1,14 +1,16 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module SmartyStreets
|
2
|
+
module USZipcode
|
3
|
+
# Known in the SmartyStreets US ZIP Code API documentation as a city_state
|
4
|
+
# See "https://smartystreets.com/docs/cloud/us-zipcode-api#cities"
|
5
|
+
class City
|
6
|
+
attr_reader :mailable_city, :state_abbreviation, :state, :city
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
def initialize(obj)
|
9
|
+
@city = obj['city']
|
10
|
+
@mailable_city = obj['mailable_city']
|
11
|
+
@state_abbreviation = obj['state_abbreviation']
|
12
|
+
@state = obj['state']
|
13
|
+
end
|
12
14
|
end
|
13
15
|
end
|
14
|
-
end
|
16
|
+
end
|
@@ -2,64 +2,66 @@ require_relative 'result'
|
|
2
2
|
require_relative '../batch'
|
3
3
|
require_relative '../request'
|
4
4
|
|
5
|
-
module
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
module SmartyStreets
|
6
|
+
module USZipcode
|
7
|
+
# It is recommended to instantiate this class using ClientBuilder.build_us_zipcode_api_client.
|
8
|
+
class Client
|
9
|
+
def initialize(sender, serializer)
|
10
|
+
@sender = sender
|
11
|
+
@serializer = serializer
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
# Sends a Lookup object to the US ZIP Code API and stores the result in the Lookup's result field.
|
15
|
+
def send_lookup(lookup)
|
16
|
+
batch = Batch.new
|
17
|
+
batch.add(lookup)
|
18
|
+
send_batch(batch)
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
# Sends a Batch object containing no more than 100 Lookup objects to the US ZIP Code API and stores the
|
22
|
+
# results in the result field of the Lookup object.
|
23
|
+
def send_batch(batch)
|
24
|
+
smarty_request = Request.new
|
24
25
|
|
25
|
-
|
26
|
+
return if batch.empty?
|
26
27
|
|
27
|
-
|
28
|
-
|
28
|
+
converted_lookups = remap_keys(batch.all_lookups)
|
29
|
+
smarty_request.payload = @serializer.serialize(converted_lookups)
|
29
30
|
|
30
|
-
|
31
|
+
response = @sender.send(smarty_request)
|
31
32
|
|
32
|
-
|
33
|
+
raise response.error if response.error
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
results = @serializer.deserialize(response.payload)
|
36
|
+
results = [] if results == nil
|
37
|
+
assign_results_to_lookups(batch, results)
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
def assign_results_to_lookups(batch, results)
|
41
|
+
results.each do |raw_result|
|
42
|
+
result = Result.new(raw_result)
|
43
|
+
batch[result.input_index].result = result
|
44
|
+
end
|
43
45
|
end
|
44
|
-
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
def remap_keys(obj)
|
48
|
+
converted_obj = []
|
49
|
+
obj.each do |lookup|
|
50
|
+
converted_lookup = {}
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
52
|
+
add_field(converted_lookup, 'city', lookup.city)
|
53
|
+
add_field(converted_lookup, 'state', lookup.state)
|
54
|
+
add_field(converted_lookup, 'zipcode', lookup.zipcode)
|
54
55
|
|
55
|
-
|
56
|
-
|
56
|
+
converted_obj.push(converted_lookup)
|
57
|
+
end
|
57
58
|
|
58
|
-
|
59
|
-
|
59
|
+
converted_obj
|
60
|
+
end
|
60
61
|
|
61
|
-
|
62
|
-
|
62
|
+
def add_field(converted_lookup, key, value)
|
63
|
+
converted_lookup[key] = value unless value.nil? or value.empty?
|
64
|
+
end
|
63
65
|
end
|
64
66
|
end
|
65
67
|
end
|
@@ -1,18 +1,21 @@
|
|
1
1
|
require_relative '../json_able'
|
2
|
-
module USZipcode
|
3
|
-
# In addition to holding all of the input data for this lookup, this class also
|
4
|
-
# will contain the result of the lookup after it comes back from the API.
|
5
|
-
#
|
6
|
-
# See "https://smartystreets.com/docs/cloud/us-zipcode-api#http-request-input-fields"
|
7
|
-
class Lookup < JSONAble
|
8
|
-
attr_accessor :result, :state, :zipcode, :input_id, :city
|
9
2
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
3
|
+
module SmartyStreets
|
4
|
+
module USZipcode
|
5
|
+
# In addition to holding all of the input data for this lookup, this class also
|
6
|
+
# will contain the result of the lookup after it comes back from the API.
|
7
|
+
#
|
8
|
+
# See "https://smartystreets.com/docs/cloud/us-zipcode-api#http-request-input-fields"
|
9
|
+
class Lookup < JSONAble
|
10
|
+
attr_accessor :result, :state, :zipcode, :input_id, :city
|
11
|
+
|
12
|
+
def initialize(city=nil, state=nil, zipcode=nil, input_id=nil)
|
13
|
+
@result = nil
|
14
|
+
@input_id = input_id
|
15
|
+
@city = city
|
16
|
+
@state = state
|
17
|
+
@zipcode = zipcode
|
18
|
+
end
|
16
19
|
end
|
17
20
|
end
|
18
21
|
end
|
@@ -1,44 +1,46 @@
|
|
1
1
|
require_relative 'city'
|
2
2
|
require_relative 'zip_code'
|
3
3
|
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
4
|
+
module SmartyStreets
|
5
|
+
module USZipcode
|
6
|
+
# See "https://smartystreets.com/docs/cloud/us-zipcode-api#root"
|
7
|
+
class Result
|
8
|
+
attr_reader :reason, :input_index, :cities, :zipcodes, :status
|
9
|
+
|
10
|
+
def initialize(obj)
|
11
|
+
@status = obj['status']
|
12
|
+
@reason = obj['reason']
|
13
|
+
@input_index = obj['input_index']
|
14
|
+
@cities = obj.fetch('city_states', [])
|
15
|
+
@zipcodes = obj.fetch('zipcodes', [])
|
16
|
+
|
17
|
+
@cities = convert_cities
|
18
|
+
@zipcodes = convert_zipcodes
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def valid?
|
22
|
+
@status.nil? and @reason.nil?
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
25
|
+
def convert_cities
|
26
|
+
converted_cities = []
|
26
27
|
|
27
|
-
|
28
|
-
|
28
|
+
@cities.each do |city|
|
29
|
+
converted_cities.push(City.new(city))
|
30
|
+
end
|
31
|
+
|
32
|
+
converted_cities
|
29
33
|
end
|
30
34
|
|
31
|
-
|
32
|
-
|
35
|
+
def convert_zipcodes
|
36
|
+
converted_zipcodes = []
|
33
37
|
|
34
|
-
|
35
|
-
|
38
|
+
@zipcodes.each do |zipcode|
|
39
|
+
converted_zipcodes.push(ZipCode.new(zipcode))
|
40
|
+
end
|
36
41
|
|
37
|
-
|
38
|
-
converted_zipcodes.push(ZipCode.new(zipcode))
|
42
|
+
converted_zipcodes
|
39
43
|
end
|
40
|
-
|
41
|
-
converted_zipcodes
|
42
44
|
end
|
43
45
|
end
|
44
|
-
end
|
46
|
+
end
|
@@ -1,30 +1,33 @@
|
|
1
1
|
require_relative 'alternate_county'
|
2
2
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
module SmartyStreets
|
4
|
+
module USZipcode
|
5
|
+
# See "https://smartystreets.com/docs/cloud/us-zipcode-api#zipcodes"
|
6
|
+
class ZipCode
|
7
|
+
attr_reader :longitude, :county_name, :zipcode, :zipcode_type, :county_fips,
|
8
|
+
:latitude, :precision, :default_city, :alternate_counties,
|
9
|
+
:state_abbreviation, :state
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
def initialize(obj)
|
12
|
+
@zipcode = obj['zipcode']
|
13
|
+
@zipcode_type = obj['zipcode_type']
|
14
|
+
@default_city = obj['default_city']
|
15
|
+
@county_fips = obj['county_fips']
|
16
|
+
@county_name = obj['county_name']
|
17
|
+
@latitude = obj['latitude']
|
18
|
+
@longitude = obj['longitude']
|
19
|
+
@precision = obj['precision']
|
20
|
+
@state = obj['state']
|
21
|
+
@state_abbreviation = obj['state_abbreviation']
|
22
|
+
alternate_counties = obj.fetch('alternate_counties', [])
|
22
23
|
|
23
|
-
|
24
|
+
@alternate_counties = []
|
24
25
|
|
25
|
-
|
26
|
-
|
26
|
+
alternate_counties.each do |county|
|
27
|
+
@alternate_counties.push(USZipcode::AlternateCounty.new(county))
|
28
|
+
end
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
33
|
+
|