smartystreets_ruby_sdk 0.0.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +0 -1
  3. data/{LICENSE.md → LICENSE.txt} +1 -1
  4. data/Makefile +17 -31
  5. data/README.md +6 -9
  6. data/Rakefile +2 -5
  7. data/examples/us_street_multiple_address_example.rb +15 -40
  8. data/examples/us_street_single_address_example.rb +8 -32
  9. data/examples/us_zipcode_multiple_lookup_example.rb +9 -21
  10. data/examples/us_zipcode_single_lookup_example.rb +6 -18
  11. data/lib/smartystreets_ruby_sdk/batch.rb +38 -45
  12. data/lib/smartystreets_ruby_sdk/core_client_builder.rb +56 -0
  13. data/lib/smartystreets_ruby_sdk/custom_header_sender.rb +8 -10
  14. data/lib/smartystreets_ruby_sdk/errors.rb +11 -21
  15. data/lib/smartystreets_ruby_sdk/exceptions.rb +16 -27
  16. data/lib/smartystreets_ruby_sdk/json_able.rb +11 -13
  17. data/lib/smartystreets_ruby_sdk/match_type.rb +5 -0
  18. data/lib/smartystreets_ruby_sdk/native_sender.rb +43 -65
  19. data/lib/smartystreets_ruby_sdk/native_serializer.rb +7 -9
  20. data/lib/smartystreets_ruby_sdk/request.rb +8 -11
  21. data/lib/smartystreets_ruby_sdk/response.rb +7 -9
  22. data/lib/smartystreets_ruby_sdk/retry_sender.rb +26 -32
  23. data/lib/smartystreets_ruby_sdk/shared_credentials.rb +9 -11
  24. data/lib/smartystreets_ruby_sdk/signing_sender.rb +9 -11
  25. data/lib/smartystreets_ruby_sdk/sleeper.rb +3 -5
  26. data/lib/smartystreets_ruby_sdk/static_credentials.rb +9 -11
  27. data/lib/smartystreets_ruby_sdk/status_code_sender.rb +29 -33
  28. data/lib/smartystreets_ruby_sdk/url_prefix_sender.rb +9 -11
  29. data/lib/smartystreets_ruby_sdk/us_street/analysis.rb +16 -21
  30. data/lib/smartystreets_ruby_sdk/us_street/candidate.rb +19 -23
  31. data/lib/smartystreets_ruby_sdk/us_street/client.rb +47 -60
  32. data/lib/smartystreets_ruby_sdk/us_street/client_builder.rb +15 -0
  33. data/lib/smartystreets_ruby_sdk/us_street/components.rb +27 -32
  34. data/lib/smartystreets_ruby_sdk/us_street/lookup.rb +20 -27
  35. data/lib/smartystreets_ruby_sdk/us_street/metadata.rb +23 -27
  36. data/lib/smartystreets_ruby_sdk/us_street.rb +3 -5
  37. data/lib/smartystreets_ruby_sdk/us_zipcode/city.rb +8 -14
  38. data/lib/smartystreets_ruby_sdk/us_zipcode/client.rb +36 -51
  39. data/lib/smartystreets_ruby_sdk/us_zipcode/client_builder.rb +15 -0
  40. data/lib/smartystreets_ruby_sdk/us_zipcode/lookup.rb +9 -16
  41. data/lib/smartystreets_ruby_sdk/us_zipcode/result.rb +30 -34
  42. data/lib/smartystreets_ruby_sdk/us_zipcode/zip_code.rb +14 -32
  43. data/lib/smartystreets_ruby_sdk/us_zipcode.rb +3 -5
  44. data/lib/smartystreets_ruby_sdk/version.rb +2 -2
  45. data/lib/smartystreets_ruby_sdk.rb +1 -30
  46. data/smartystreets_ruby_sdk.gemspec +12 -3
  47. metadata +15 -61
  48. data/.github/workflows/gem-publish.yml +0 -58
  49. data/CHANGELOG.md +0 -5
  50. data/Dockerfile +0 -10
  51. data/docker-compose.yml +0 -12
  52. data/examples/international_autocomplete_example.rb +0 -47
  53. data/examples/international_example.rb +0 -53
  54. data/examples/us_autocomplete_pro_example.rb +0 -56
  55. data/examples/us_extract_example.rb +0 -63
  56. data/examples/us_reverse_geo_example.rb +0 -47
  57. data/lib/smartystreets_ruby_sdk/client_builder.rb +0 -188
  58. data/lib/smartystreets_ruby_sdk/international_autocomplete/client.rb +0 -61
  59. data/lib/smartystreets_ruby_sdk/international_autocomplete/lookup.rb +0 -21
  60. data/lib/smartystreets_ruby_sdk/international_autocomplete/suggestion.rb +0 -16
  61. data/lib/smartystreets_ruby_sdk/international_street/analysis.rb +0 -17
  62. data/lib/smartystreets_ruby_sdk/international_street/candidate.rb +0 -23
  63. data/lib/smartystreets_ruby_sdk/international_street/changes.rb +0 -15
  64. data/lib/smartystreets_ruby_sdk/international_street/client.rb +0 -63
  65. data/lib/smartystreets_ruby_sdk/international_street/components.rb +0 -58
  66. data/lib/smartystreets_ruby_sdk/international_street/language_mode.rb +0 -9
  67. data/lib/smartystreets_ruby_sdk/international_street/lookup.rb +0 -82
  68. data/lib/smartystreets_ruby_sdk/international_street/metadata.rb +0 -17
  69. data/lib/smartystreets_ruby_sdk/international_street/rootlevel.rb +0 -25
  70. data/lib/smartystreets_ruby_sdk/international_street.rb +0 -12
  71. data/lib/smartystreets_ruby_sdk/license_sender.rb +0 -15
  72. data/lib/smartystreets_ruby_sdk/logger.rb +0 -7
  73. data/lib/smartystreets_ruby_sdk/proxy.rb +0 -16
  74. data/lib/smartystreets_ruby_sdk/us_autocomplete/client.rb +0 -72
  75. data/lib/smartystreets_ruby_sdk/us_autocomplete/geolocation_type.rb +0 -9
  76. data/lib/smartystreets_ruby_sdk/us_autocomplete/lookup.rb +0 -38
  77. data/lib/smartystreets_ruby_sdk/us_autocomplete/suggestion.rb +0 -16
  78. data/lib/smartystreets_ruby_sdk/us_autocomplete.rb +0 -9
  79. data/lib/smartystreets_ruby_sdk/us_autocomplete_pro/client.rb +0 -78
  80. data/lib/smartystreets_ruby_sdk/us_autocomplete_pro/geolocation_type.rb +0 -8
  81. data/lib/smartystreets_ruby_sdk/us_autocomplete_pro/lookup.rb +0 -63
  82. data/lib/smartystreets_ruby_sdk/us_autocomplete_pro/suggestion.rb +0 -18
  83. data/lib/smartystreets_ruby_sdk/us_autocomplete_pro.rb +0 -10
  84. data/lib/smartystreets_ruby_sdk/us_extract/address.rb +0 -24
  85. data/lib/smartystreets_ruby_sdk/us_extract/client.rb +0 -49
  86. data/lib/smartystreets_ruby_sdk/us_extract/lookup.rb +0 -22
  87. data/lib/smartystreets_ruby_sdk/us_extract/metadata.rb +0 -17
  88. data/lib/smartystreets_ruby_sdk/us_extract/result.rb +0 -21
  89. data/lib/smartystreets_ruby_sdk/us_extract.rb +0 -10
  90. data/lib/smartystreets_ruby_sdk/us_reverse_geo/address.rb +0 -16
  91. data/lib/smartystreets_ruby_sdk/us_reverse_geo/client.rb +0 -38
  92. data/lib/smartystreets_ruby_sdk/us_reverse_geo/coordinate.rb +0 -25
  93. data/lib/smartystreets_ruby_sdk/us_reverse_geo/lookup.rb +0 -21
  94. data/lib/smartystreets_ruby_sdk/us_reverse_geo/result.rb +0 -20
  95. data/lib/smartystreets_ruby_sdk/us_reverse_geo/us_reverse_geo_response.rb +0 -17
  96. data/lib/smartystreets_ruby_sdk/us_reverse_geo.rb +0 -12
  97. data/lib/smartystreets_ruby_sdk/us_street/match_type.rb +0 -10
  98. data/lib/smartystreets_ruby_sdk/us_zipcode/alternate_county.rb +0 -15
  99. data/ruby-sdk-demo.json +0 -354
@@ -2,77 +2,64 @@ require_relative '../batch'
2
2
  require_relative '../request'
3
3
  require_relative 'candidate'
4
4
 
5
- module SmartyStreets
6
- module USStreet
7
- # It is recommended to instantiate this class using ClientBuilder.build_us_street_api_client
8
- class Client
9
- def initialize(sender, serializer)
10
- @sender = sender
11
- @serializer = serializer
12
- end
13
-
14
- # Sends a Lookup object to the US Street API and stores the result in the Lookup's result field.
15
- def send_lookup(lookup)
16
- batch = SmartyStreets::Batch.new
17
- batch.add(lookup)
18
- send_batch(batch)
19
- end
5
+ module USStreet
6
+ class Client
7
+ def initialize(sender, serializer)
8
+ @sender = sender
9
+ @serializer = serializer
10
+ end
20
11
 
21
- # Sends a Batch object containing no more than 100 Lookup objects to the US Street API and stores the
22
- # results in the result field of the Lookup object.
23
- def send_batch(batch)
24
- smarty_request = Request.new
12
+ def send_lookup(lookup)
13
+ batch = Batch.new
14
+ batch.add(lookup)
15
+ send_batch(batch)
16
+ end
25
17
 
26
- return if batch.empty?
18
+ def send_batch(batch)
19
+ smarty_request = Request.new
27
20
 
28
- converted_lookups = remap_keys(batch.all_lookups)
21
+ return if batch.size == 0
29
22
 
30
- if batch.size > 1
31
- smarty_request.payload = @serializer.serialize(converted_lookups)
32
- else
33
- smarty_request.parameters = converted_lookups[0]
34
- end
23
+ converted_lookups = remap_keys(batch.all_lookups)
24
+ smarty_request.payload = @serializer.serialize(converted_lookups)
35
25
 
36
- response = @sender.send(smarty_request)
26
+ response = @sender.send(smarty_request)
37
27
 
38
- raise response.error if response.error
28
+ raise response.error if response.error
39
29
 
40
- candidates = @serializer.deserialize(response.payload)
41
- candidates = [] if candidates.nil?
30
+ candidates = @serializer.deserialize(response.payload)
31
+ candidates = [] if candidates == nil
42
32
 
43
- assign_candidates_to_lookups(batch, candidates)
44
- end
33
+ assign_candidates_to_lookups(batch, candidates)
34
+ end
45
35
 
46
- def remap_keys(obj)
47
- converted_obj = []
48
- obj.each do |lookup|
49
- converted_lookup = {}
50
- lookup.candidates = 5 if lookup.match == "enhanced" && lookup.candidates == 0
36
+ def remap_keys(obj)
37
+ converted_obj = []
38
+ obj.each { |lookup|
39
+ converted_lookup = {}
51
40
 
52
- converted_lookup['input_id'] = lookup.input_id
53
- converted_lookup['street'] = lookup.street
54
- converted_lookup['street2'] = lookup.street2
55
- converted_lookup['secondary'] = lookup.secondary
56
- converted_lookup['city'] = lookup.city
57
- converted_lookup['state'] = lookup.state
58
- converted_lookup['zipcode'] = lookup.zipcode
59
- converted_lookup['lastline'] = lookup.lastline
60
- converted_lookup['addressee'] = lookup.addressee
61
- converted_lookup['urbanization'] = lookup.urbanization
62
- converted_lookup['match'] = lookup.match
63
- converted_lookup['candidates'] = lookup.candidates
41
+ converted_lookup['street'] = lookup.street
42
+ converted_lookup['street2'] = lookup.street2
43
+ converted_lookup['secondary'] = lookup.secondary
44
+ converted_lookup['city'] = lookup.city
45
+ converted_lookup['state'] = lookup.state
46
+ converted_lookup['zipcode'] = lookup.zipcode
47
+ converted_lookup['lastline'] = lookup.lastline
48
+ converted_lookup['addressee'] = lookup.addressee
49
+ converted_lookup['urbanization'] = lookup.urbanization
50
+ converted_lookup['match'] = lookup.match
51
+ converted_lookup['candidates'] = lookup.candidates
64
52
 
65
- converted_obj.push(converted_lookup)
66
- end
67
- converted_obj
68
- end
53
+ converted_obj.push(converted_lookup)
54
+ }
55
+ converted_obj
56
+ end
69
57
 
70
- def assign_candidates_to_lookups(batch, candidates)
71
- candidates.each do |raw_candidate|
72
- candidate = Candidate.new(raw_candidate)
73
- batch[candidate.input_index].result.push(candidate)
74
- end
75
- end
58
+ def assign_candidates_to_lookups(batch, candidates)
59
+ candidates.each { |raw_candidate|
60
+ candidate = Candidate.new(raw_candidate)
61
+ batch[candidate.input_index].result.push(candidate)
62
+ }
76
63
  end
77
64
  end
78
- end
65
+ end
@@ -0,0 +1,15 @@
1
+ require_relative '../core_client_builder'
2
+ require_relative 'client'
3
+
4
+ module USStreet
5
+ class ClientBuilder < CoreClientBuilder
6
+ def initialize(signer)
7
+ super(signer)
8
+ @url_prefix = 'https://us-street.api.smartystreets.com/street-address'
9
+ end
10
+
11
+ def build
12
+ Client.new(build_sender, @serializer)
13
+ end
14
+ end
15
+ end
@@ -1,35 +1,30 @@
1
- module SmartyStreets
2
- module USStreet
3
- # This class contains the matched address broken down into its fundamental pieces.
4
- #
5
- # See "https://smartystreets.com/docs/cloud/us-street-api#components"
6
- class Components
7
- attr_reader :street_postdirection, :delivery_point_check_digit, :secondary_designator, :secondary_number, :zipcode,
8
- :pmb_number, :state_abbreviation, :extra_secondary_designator, :urbanization, :street_name, :city_name,
9
- :default_city_name, :street_suffix, :primary_number, :plus4_code, :street_predirection, :pmb_designator,
10
- :extra_secondary_number, :delivery_point
1
+ module USStreet
2
+ class Components
3
+ attr_reader :street_postdirection, :delivery_point_check_digit, :secondary_designator, :secondary_number, :zipcode,
4
+ :pmb_number, :state_abbreviation, :extra_secondary_designator, :urbanization, :street_name, :city_name,
5
+ :default_city_name, :street_suffix, :primary_number, :plus4_code, :street_predirection, :pmb_designator,
6
+ :extra_secondary_number, :delivery_point
11
7
 
12
- def initialize(obj)
13
- @urbanization = obj['urbanization']
14
- @primary_number = obj['primary_number']
15
- @street_name = obj['street_name']
16
- @street_predirection = obj['street_predirection']
17
- @street_postdirection = obj['street_postdirection']
18
- @street_suffix = obj['street_suffix']
19
- @secondary_number = obj['secondary_number']
20
- @secondary_designator = obj['secondary_designator']
21
- @extra_secondary_number = obj['extra_secondary_number']
22
- @extra_secondary_designator = obj['extra_secondary_designator']
23
- @pmb_designator = obj['pmb_designator']
24
- @pmb_number = obj['pmb_number']
25
- @city_name = obj['city_name']
26
- @default_city_name = obj['default_city_name']
27
- @state_abbreviation = obj['state_abbreviation']
28
- @zipcode = obj['zipcode']
29
- @plus4_code = obj['plus4_code']
30
- @delivery_point = obj['delivery_point']
31
- @delivery_point_check_digit = obj['delivery_point_check_digit']
32
- end
8
+ def initialize(obj)
9
+ @urbanization = obj['urbanization']
10
+ @primary_number = obj['primary_number']
11
+ @street_name = obj['street_name']
12
+ @street_predirection = obj['street_predirection']
13
+ @street_postdirection = obj['street_postdirection']
14
+ @street_suffix = obj['street_suffix']
15
+ @secondary_number = obj['secondary_number']
16
+ @secondary_designator = obj['secondary_designator']
17
+ @extra_secondary_number = obj['extra_secondary_number']
18
+ @extra_secondary_designator = obj['extra_secondary_designator']
19
+ @pmb_designator = obj['pmb_designator']
20
+ @pmb_number = obj['pmb_number']
21
+ @city_name = obj['city_name']
22
+ @default_city_name = obj['default_city_name']
23
+ @state_abbreviation = obj['state_abbreviation']
24
+ @zipcode = obj['zipcode']
25
+ @plus4_code = obj['plus4_code']
26
+ @delivery_point = obj['delivery_point']
27
+ @delivery_point_check_digit = obj['delivery_point_check_digit']
33
28
  end
34
29
  end
35
- end
30
+ end
@@ -1,32 +1,25 @@
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
13
2
 
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=0, 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
3
+ module USStreet
4
+ class Lookup < JSONAble
5
+ attr_accessor :input_id, :street, :street2, :secondary, :city, :state, :zipcode, :lastline, :addressee, :urbanization,
6
+ :match, :candidates, :result
7
+
8
+ def initialize(street=nil, street2=nil, secondary=nil, city=nil, state=nil, zipcode=nil, lastline=nil,
9
+ addressee=nil, urbanization=nil, match=nil, candidates=1, input_id=nil)
10
+ @input_id = input_id
11
+ @street = street
12
+ @street2 = street2
13
+ @secondary = secondary
14
+ @city = city
15
+ @state = state
16
+ @zipcode = zipcode
17
+ @lastline = lastline
18
+ @addressee = addressee
19
+ @urbanization = urbanization
20
+ @match = match
21
+ @candidates = candidates
22
+ @result = []
30
23
  end
31
24
  end
32
25
  end
@@ -1,30 +1,26 @@
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, :is_an_ews_match
1
+ module USStreet
2
+ class Metadata
3
+ attr_reader :elot_sort, :longitude, :elot_sequence, :county_fips, :building_default_indicator, :rdi,
4
+ :congressional_district, :latitude, :precision, :time_zone, :zip_type, :county_name, :utc_offset,
5
+ :record_type, :carrier_route, :obeys_dst
8
6
 
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
- @is_an_ews_match = obj['ews_match']
27
- end
7
+ def initialize(obj)
8
+ @record_type = obj['record_type']
9
+ @zip_type = obj['zip_type']
10
+ @county_fips = obj['county_fips']
11
+ @county_name = obj['county_name']
12
+ @carrier_route = obj['carrier_route']
13
+ @congressional_district = obj['congressional_district']
14
+ @building_default_indicator = obj['building_default_indicator']
15
+ @rdi = obj['rdi']
16
+ @elot_sequence = obj['elot_sequence']
17
+ @elot_sort = obj['elot_sort']
18
+ @latitude = obj['latitude']
19
+ @longitude = obj['longitude']
20
+ @precision = obj['precision']
21
+ @time_zone = obj['time_zone']
22
+ @utc_offset = obj['utc_offset']
23
+ @obeys_dst = obj['dst']
28
24
  end
29
25
  end
30
- end
26
+ end
@@ -1,12 +1,10 @@
1
1
  require_relative './us_street/analysis'
2
2
  require_relative './us_street/candidate'
3
3
  require_relative './us_street/client'
4
+ require_relative './us_street/client_builder'
4
5
  require_relative './us_street/components'
5
6
  require_relative './us_street/lookup'
6
7
  require_relative './us_street/metadata'
7
- require_relative './us_street/match_type'
8
8
 
9
- module SmartyStreets
10
- module USStreet
11
- end
12
- end
9
+ module USStreet
10
+ end
@@ -1,16 +1,10 @@
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
1
+ class City
2
+ attr_reader :mailable_city, :state_abbreviation, :state, :city
7
3
 
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
14
- end
4
+ def initialize(obj)
5
+ @city = obj['city']
6
+ @mailable_city = obj['mailable_city']
7
+ @state_abbreviation = obj['state_abbreviation']
8
+ @state = obj['state']
15
9
  end
16
- end
10
+ end
@@ -2,71 +2,56 @@ require_relative 'result'
2
2
  require_relative '../batch'
3
3
  require_relative '../request'
4
4
 
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
13
-
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
5
+ module USZipcode
6
+ class Client
7
+ def initialize(sender, serializer)
8
+ @sender = sender
9
+ @serializer = serializer
10
+ end
20
11
 
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
12
+ def send_lookup(lookup)
13
+ batch = Batch.new
14
+ batch.add(lookup)
15
+ send_batch(batch)
16
+ end
25
17
 
26
- return if batch.empty?
18
+ def send_batch(batch)
19
+ smarty_request = Request.new
27
20
 
28
- converted_lookups = remap_keys(batch.all_lookups)
21
+ return if batch.size == 0
29
22
 
30
- if batch.size > 1
31
- smarty_request.payload = @serializer.serialize(converted_lookups)
32
- else
33
- smarty_request.parameters = converted_lookups[0]
34
- end
23
+ converted_lookups = remap_keys(batch.all_lookups)
24
+ smarty_request.payload = @serializer.serialize(converted_lookups)
35
25
 
36
- response = @sender.send(smarty_request)
26
+ response = @sender.send(smarty_request)
37
27
 
38
- raise response.error if response.error
28
+ raise response.error if response.error
39
29
 
40
- results = @serializer.deserialize(response.payload)
41
- results = [] if results.nil?
42
- assign_results_to_lookups(batch, results)
43
- end
30
+ results = @serializer.deserialize(response.payload)
31
+ results = [] if results == nil
32
+ assign_results_to_lookups(batch, results)
33
+ end
44
34
 
45
- def assign_results_to_lookups(batch, results)
46
- results.each do |raw_result|
47
- result = Result.new(raw_result)
48
- batch[result.input_index].result = result
49
- end
35
+ def assign_results_to_lookups(batch, results)
36
+ results.each do |raw_result|
37
+ result = Result.new(raw_result)
38
+ batch[result.input_index].result = result
50
39
  end
40
+ end
51
41
 
52
- def remap_keys(obj)
53
- converted_obj = []
54
- obj.each do |lookup|
55
- converted_lookup = {}
56
-
57
- add_field(converted_lookup, 'city', lookup.city)
58
- add_field(converted_lookup, 'state', lookup.state)
59
- add_field(converted_lookup, 'zipcode', lookup.zipcode)
42
+ def remap_keys(obj)
43
+ converted_obj = []
44
+ obj.each do |lookup|
45
+ converted_lookup = {}
60
46
 
61
- converted_obj.push(converted_lookup)
62
- end
47
+ converted_lookup['city'] = lookup.city
48
+ converted_lookup['state'] = lookup.state
49
+ converted_lookup['zipcode'] = lookup.zipcode
63
50
 
64
- converted_obj
51
+ converted_obj.push(converted_lookup)
65
52
  end
66
53
 
67
- def add_field(converted_lookup, key, value)
68
- converted_lookup[key] = value unless value.nil? or value.empty?
69
- end
54
+ converted_obj
70
55
  end
71
56
  end
72
57
  end
@@ -0,0 +1,15 @@
1
+ require_relative '../core_client_builder'
2
+ require_relative 'client'
3
+
4
+ module USZipcode
5
+ class ClientBuilder < CoreClientBuilder
6
+ def initialize(signer)
7
+ super(signer)
8
+ @url_prefix = 'https://us-zipcode.api.smartystreets.com/lookup'
9
+ end
10
+
11
+ def build
12
+ Client.new(build_sender, @serializer)
13
+ end
14
+ end
15
+ end
@@ -1,21 +1,14 @@
1
1
  require_relative '../json_able'
2
+ module USZipcode
3
+ class Lookup < JSONAble
4
+ attr_accessor :result, :state, :zipcode, :input_id, :city
2
5
 
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
6
+ def initialize(city=nil, state=nil, zipcode=nil, input_id=nil)
7
+ @result = nil
8
+ @input_id = input_id
9
+ @city = city
10
+ @state = state
11
+ @zipcode = zipcode
19
12
  end
20
13
  end
21
14
  end
@@ -1,47 +1,43 @@
1
1
  require_relative 'city'
2
2
  require_relative 'zip_code'
3
3
 
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_id, :input_index, :cities, :zipcodes, :status
9
-
10
- def initialize(obj)
11
- @status = obj['status']
12
- @reason = obj['reason']
13
- @input_id = obj['input_id']
14
- @input_index = obj['input_index']
15
- @cities = obj.fetch('city_states', [])
16
- @zipcodes = obj.fetch('zipcodes', [])
17
-
18
- @cities = convert_cities
19
- @zipcodes = convert_zipcodes
20
- end
21
-
22
- def valid?
23
- @status.nil? and @reason.nil?
24
- end
4
+ module USZipcode
5
+ class Result
6
+ attr_reader :reason, :input_index, :cities, :zipcodes, :status
7
+
8
+ def initialize(obj)
9
+ @status = obj['status']
10
+ @reason = obj['reason']
11
+ @input_index = obj['input_index']
12
+ @cities = obj.fetch('city_states', [])
13
+ @zipcodes = obj.fetch('zipcodes', [])
14
+
15
+ @cities = convert_cities
16
+ @zipcodes = convert_zipcodes
17
+ end
25
18
 
26
- def convert_cities
27
- converted_cities = []
19
+ def is_valid?
20
+ @status == nil and @reason == nil
21
+ end
28
22
 
29
- @cities.each do |city|
30
- converted_cities.push(City.new(city))
31
- end
23
+ def convert_cities
24
+ converted_cities = []
32
25
 
33
- converted_cities
26
+ @cities.each do |city|
27
+ converted_cities.push(City.new(city))
34
28
  end
35
29
 
36
- def convert_zipcodes
37
- converted_zipcodes = []
30
+ converted_cities
31
+ end
38
32
 
39
- @zipcodes.each do |zipcode|
40
- converted_zipcodes.push(ZipCode.new(zipcode))
41
- end
33
+ def convert_zipcodes
34
+ converted_zipcodes = []
42
35
 
43
- converted_zipcodes
36
+ @zipcodes.each do |zipcode|
37
+ converted_zipcodes.push(ZipCode.new(zipcode))
44
38
  end
39
+
40
+ converted_zipcodes
45
41
  end
46
42
  end
47
- end
43
+ end
@@ -1,33 +1,15 @@
1
- require_relative 'alternate_county'
2
-
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
10
-
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', [])
23
-
24
- @alternate_counties = []
25
-
26
- alternate_counties.each do |county|
27
- @alternate_counties.push(USZipcode::AlternateCounty.new(county))
28
- end
29
- end
30
- end
1
+ class ZipCode
2
+ attr_reader :longitude, :county_name, :zipcode, :zipcode_type, :county_fips, :latitude, :precision, :default_city, :alternate_counties
3
+
4
+ def initialize(obj)
5
+ @zipcode = obj['zipcode']
6
+ @zipcode_type = obj['zipcode_type']
7
+ @default_city = obj['default_city']
8
+ @county_fips = obj['county_fips']
9
+ @county_name = obj['county_name']
10
+ @latitude = obj['latitude']
11
+ @longitude = obj['longitude']
12
+ @precision = obj['precision']
13
+ @alternate_counties = obj.fetch('alternate_counties', [])
31
14
  end
32
- end
33
-
15
+ end