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.
Files changed (65) hide show
  1. data/Makefile +1 -1
  2. data/examples/international_example.rb +3 -3
  3. data/examples/us_autocomplete_example.rb +3 -3
  4. data/examples/us_extract_example.rb +3 -3
  5. data/examples/us_street_multiple_address_example.rb +6 -5
  6. data/examples/us_street_single_address_example.rb +5 -5
  7. data/examples/us_zipcode_multiple_lookup_example.rb +6 -5
  8. data/examples/us_zipcode_single_lookup_example.rb +4 -4
  9. data/lib/smartystreets_ruby_sdk.rb +26 -4
  10. data/lib/smartystreets_ruby_sdk/batch.rb +44 -41
  11. data/lib/smartystreets_ruby_sdk/client_builder.rb +115 -113
  12. data/lib/smartystreets_ruby_sdk/custom_header_sender.rb +10 -8
  13. data/lib/smartystreets_ruby_sdk/errors.rb +13 -11
  14. data/lib/smartystreets_ruby_sdk/exceptions.rb +27 -23
  15. data/lib/smartystreets_ruby_sdk/international_street.rb +3 -1
  16. data/lib/smartystreets_ruby_sdk/international_street/analysis.rb +11 -9
  17. data/lib/smartystreets_ruby_sdk/international_street/candidate.rb +28 -26
  18. data/lib/smartystreets_ruby_sdk/international_street/client.rb +45 -43
  19. data/lib/smartystreets_ruby_sdk/international_street/components.rb +53 -51
  20. data/lib/smartystreets_ruby_sdk/international_street/language_mode.rb +7 -3
  21. data/lib/smartystreets_ruby_sdk/international_street/lookup.rb +63 -61
  22. data/lib/smartystreets_ruby_sdk/international_street/metadata.rb +12 -10
  23. data/lib/smartystreets_ruby_sdk/json_able.rb +13 -11
  24. data/lib/smartystreets_ruby_sdk/logger.rb +2 -2
  25. data/lib/smartystreets_ruby_sdk/native_sender.rb +58 -56
  26. data/lib/smartystreets_ruby_sdk/native_serializer.rb +9 -7
  27. data/lib/smartystreets_ruby_sdk/proxy.rb +2 -2
  28. data/lib/smartystreets_ruby_sdk/request.rb +11 -9
  29. data/lib/smartystreets_ruby_sdk/response.rb +9 -7
  30. data/lib/smartystreets_ruby_sdk/retry_sender.rb +26 -24
  31. data/lib/smartystreets_ruby_sdk/shared_credentials.rb +11 -9
  32. data/lib/smartystreets_ruby_sdk/signing_sender.rb +11 -9
  33. data/lib/smartystreets_ruby_sdk/sleeper.rb +1 -1
  34. data/lib/smartystreets_ruby_sdk/static_credentials.rb +11 -9
  35. data/lib/smartystreets_ruby_sdk/status_code_sender.rb +31 -29
  36. data/lib/smartystreets_ruby_sdk/url_prefix_sender.rb +11 -9
  37. data/lib/smartystreets_ruby_sdk/us_autocomplete.rb +3 -1
  38. data/lib/smartystreets_ruby_sdk/us_autocomplete/client.rb +47 -45
  39. data/lib/smartystreets_ruby_sdk/us_autocomplete/geolocation_type.rb +9 -5
  40. data/lib/smartystreets_ruby_sdk/us_autocomplete/lookup.rb +26 -24
  41. data/lib/smartystreets_ruby_sdk/us_autocomplete/suggestion.rb +11 -9
  42. data/lib/smartystreets_ruby_sdk/us_extract.rb +4 -2
  43. data/lib/smartystreets_ruby_sdk/us_extract/address.rb +18 -16
  44. data/lib/smartystreets_ruby_sdk/us_extract/client.rb +34 -32
  45. data/lib/smartystreets_ruby_sdk/us_extract/lookup.rb +16 -14
  46. data/lib/smartystreets_ruby_sdk/us_extract/metadata.rb +13 -11
  47. data/lib/smartystreets_ruby_sdk/us_extract/result.rb +13 -11
  48. data/lib/smartystreets_ruby_sdk/us_street.rb +4 -2
  49. data/lib/smartystreets_ruby_sdk/us_street/analysis.rb +19 -17
  50. data/lib/smartystreets_ruby_sdk/us_street/candidate.rb +19 -17
  51. data/lib/smartystreets_ruby_sdk/us_street/client.rb +51 -49
  52. data/lib/smartystreets_ruby_sdk/us_street/components.rb +32 -30
  53. data/lib/smartystreets_ruby_sdk/us_street/lookup.rb +27 -26
  54. data/lib/smartystreets_ruby_sdk/us_street/match_type.rb +9 -5
  55. data/lib/smartystreets_ruby_sdk/us_street/metadata.rb +26 -24
  56. data/lib/smartystreets_ruby_sdk/us_zipcode.rb +4 -2
  57. data/lib/smartystreets_ruby_sdk/us_zipcode/alternate_county.rb +12 -10
  58. data/lib/smartystreets_ruby_sdk/us_zipcode/city.rb +13 -11
  59. data/lib/smartystreets_ruby_sdk/us_zipcode/client.rb +46 -44
  60. data/lib/smartystreets_ruby_sdk/us_zipcode/lookup.rb +16 -13
  61. data/lib/smartystreets_ruby_sdk/us_zipcode/result.rb +33 -31
  62. data/lib/smartystreets_ruby_sdk/us_zipcode/zip_code.rb +24 -21
  63. data/lib/smartystreets_ruby_sdk/version.rb +2 -2
  64. data/smartystreets_ruby_sdk.gemspec +1 -1
  65. 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
- 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
13
-
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 = []
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 MatchType
2
- STRICT = 'strict'.freeze
3
- RANGE = 'range'.freeze
4
- INVALID = 'invalid'.freeze
5
- end
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 USStreet
2
- # See "https://smartystreets.com/docs/cloud/us-street-api#metadata"
3
- class Metadata
4
- attr_reader :elot_sort, :longitude, :elot_sequence, :county_fips, :building_default_indicator, :rdi,
5
- :congressional_district, :latitude, :precision, :time_zone, :zip_type, :county_name, :utc_offset,
6
- :record_type, :carrier_route, :obeys_dst
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
- def initialize(obj)
9
- @record_type = obj['record_type']
10
- @zip_type = obj['zip_type']
11
- @county_fips = obj['county_fips']
12
- @county_name = obj['county_name']
13
- @carrier_route = obj['carrier_route']
14
- @congressional_district = obj['congressional_district']
15
- @building_default_indicator = obj['building_default_indicator']
16
- @rdi = obj['rdi']
17
- @elot_sequence = obj['elot_sequence']
18
- @elot_sort = obj['elot_sort']
19
- @latitude = obj['latitude']
20
- @longitude = obj['longitude']
21
- @precision = obj['precision']
22
- @time_zone = obj['time_zone']
23
- @utc_offset = obj['utc_offset']
24
- @obeys_dst = obj['dst']
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
@@ -5,5 +5,7 @@ require_relative './us_zipcode/result'
5
5
  require_relative './us_zipcode/zip_code'
6
6
  require_relative './us_zipcode/alternate_county'
7
7
 
8
- module USZipcode
9
- end
8
+ module SmartyStreets
9
+ module USZipcode
10
+ end
11
+ end
@@ -1,13 +1,15 @@
1
- module USZipcode
2
- # See "https://smartystreets.com/docs/cloud/us-zipcode-api#zipcodes"
3
- class AlternateCounty
4
- attr_reader :state_abbreviation, :state, :county_name, :county_fips
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
- def initialize(obj)
7
- @county_fips = obj.fetch('county_fips', nil)
8
- @county_name = obj.fetch('county_name', nil)
9
- @state_abbreviation = obj.fetch('state_abbreviation', nil)
10
- @state = obj.fetch('state', nil)
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 USZipcode
2
- # Known in the SmartyStreets US ZIP Code API documentation as a city_state
3
- # See "https://smartystreets.com/docs/cloud/us-zipcode-api#cities"
4
- class City
5
- attr_reader :mailable_city, :state_abbreviation, :state, :city
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
- def initialize(obj)
8
- @city = obj['city']
9
- @mailable_city = obj['mailable_city']
10
- @state_abbreviation = obj['state_abbreviation']
11
- @state = obj['state']
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 USZipcode
6
- # It is recommended to instantiate this class using ClientBuilder.build_us_zipcode_api_client.
7
- class Client
8
- def initialize(sender, serializer)
9
- @sender = sender
10
- @serializer = serializer
11
- end
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
- # Sends a Lookup object to the US ZIP Code API and stores the result in the Lookup's result field.
14
- def send_lookup(lookup)
15
- batch = Batch.new
16
- batch.add(lookup)
17
- send_batch(batch)
18
- end
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
- # Sends a Batch object containing no more than 100 Lookup objects to the US ZIP Code API and stores the
21
- # results in the result field of the Lookup object.
22
- def send_batch(batch)
23
- smarty_request = Request.new
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
- return if batch.empty?
26
+ return if batch.empty?
26
27
 
27
- converted_lookups = remap_keys(batch.all_lookups)
28
- smarty_request.payload = @serializer.serialize(converted_lookups)
28
+ converted_lookups = remap_keys(batch.all_lookups)
29
+ smarty_request.payload = @serializer.serialize(converted_lookups)
29
30
 
30
- response = @sender.send(smarty_request)
31
+ response = @sender.send(smarty_request)
31
32
 
32
- raise response.error if response.error
33
+ raise response.error if response.error
33
34
 
34
- results = @serializer.deserialize(response.payload)
35
- results = [] if results == nil
36
- assign_results_to_lookups(batch, results)
37
- end
35
+ results = @serializer.deserialize(response.payload)
36
+ results = [] if results == nil
37
+ assign_results_to_lookups(batch, results)
38
+ end
38
39
 
39
- def assign_results_to_lookups(batch, results)
40
- results.each do |raw_result|
41
- result = Result.new(raw_result)
42
- batch[result.input_index].result = result
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
- def remap_keys(obj)
47
- converted_obj = []
48
- obj.each do |lookup|
49
- converted_lookup = {}
47
+ def remap_keys(obj)
48
+ converted_obj = []
49
+ obj.each do |lookup|
50
+ converted_lookup = {}
50
51
 
51
- add_field(converted_lookup, 'city', lookup.city)
52
- add_field(converted_lookup, 'state', lookup.state)
53
- add_field(converted_lookup, 'zipcode', lookup.zipcode)
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
- converted_obj.push(converted_lookup)
56
- end
56
+ converted_obj.push(converted_lookup)
57
+ end
57
58
 
58
- converted_obj
59
- end
59
+ converted_obj
60
+ end
60
61
 
61
- def add_field(converted_lookup, key, value)
62
- converted_lookup[key] = value unless value.nil? or value.empty?
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
- def initialize(city=nil, state=nil, zipcode=nil, input_id=nil)
11
- @result = nil
12
- @input_id = input_id
13
- @city = city
14
- @state = state
15
- @zipcode = zipcode
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 USZipcode
5
- # See "https://smartystreets.com/docs/cloud/us-zipcode-api#root"
6
- class Result
7
- attr_reader :reason, :input_index, :cities, :zipcodes, :status
8
-
9
- def initialize(obj)
10
- @status = obj['status']
11
- @reason = obj['reason']
12
- @input_index = obj['input_index']
13
- @cities = obj.fetch('city_states', [])
14
- @zipcodes = obj.fetch('zipcodes', [])
15
-
16
- @cities = convert_cities
17
- @zipcodes = convert_zipcodes
18
- end
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
- def valid?
21
- @status.nil? and @reason.nil?
22
- end
21
+ def valid?
22
+ @status.nil? and @reason.nil?
23
+ end
23
24
 
24
- def convert_cities
25
- converted_cities = []
25
+ def convert_cities
26
+ converted_cities = []
26
27
 
27
- @cities.each do |city|
28
- converted_cities.push(City.new(city))
28
+ @cities.each do |city|
29
+ converted_cities.push(City.new(city))
30
+ end
31
+
32
+ converted_cities
29
33
  end
30
34
 
31
- converted_cities
32
- end
35
+ def convert_zipcodes
36
+ converted_zipcodes = []
33
37
 
34
- def convert_zipcodes
35
- converted_zipcodes = []
38
+ @zipcodes.each do |zipcode|
39
+ converted_zipcodes.push(ZipCode.new(zipcode))
40
+ end
36
41
 
37
- @zipcodes.each do |zipcode|
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 USZipcode
4
- # See "https://smartystreets.com/docs/cloud/us-zipcode-api#zipcodes"
5
- class ZipCode
6
- attr_reader :longitude, :county_name, :zipcode, :zipcode_type, :county_fips,
7
- :latitude, :precision, :default_city, :alternate_counties,
8
- :state_abbreviation, :state
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
- def initialize(obj)
11
- @zipcode = obj['zipcode']
12
- @zipcode_type = obj['zipcode_type']
13
- @default_city = obj['default_city']
14
- @county_fips = obj['county_fips']
15
- @county_name = obj['county_name']
16
- @latitude = obj['latitude']
17
- @longitude = obj['longitude']
18
- @precision = obj['precision']
19
- @state = obj['state']
20
- @state_abbreviation = obj['state_abbreviation']
21
- alternate_counties = obj.fetch('alternate_counties', [])
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
- @alternate_counties = []
24
+ @alternate_counties = []
24
25
 
25
- alternate_counties.each do |county|
26
- @alternate_counties.push(USZipcode::AlternateCounty.new(county))
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
+