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.
- checksums.yaml +5 -5
- data/.gitignore +0 -1
- data/{LICENSE.md → LICENSE.txt} +1 -1
- data/Makefile +17 -31
- data/README.md +6 -9
- data/Rakefile +2 -5
- data/examples/us_street_multiple_address_example.rb +15 -40
- data/examples/us_street_single_address_example.rb +8 -32
- data/examples/us_zipcode_multiple_lookup_example.rb +9 -21
- data/examples/us_zipcode_single_lookup_example.rb +6 -18
- data/lib/smartystreets_ruby_sdk/batch.rb +38 -45
- data/lib/smartystreets_ruby_sdk/core_client_builder.rb +56 -0
- data/lib/smartystreets_ruby_sdk/custom_header_sender.rb +8 -10
- data/lib/smartystreets_ruby_sdk/errors.rb +11 -21
- data/lib/smartystreets_ruby_sdk/exceptions.rb +16 -27
- data/lib/smartystreets_ruby_sdk/json_able.rb +11 -13
- data/lib/smartystreets_ruby_sdk/match_type.rb +5 -0
- data/lib/smartystreets_ruby_sdk/native_sender.rb +43 -65
- data/lib/smartystreets_ruby_sdk/native_serializer.rb +7 -9
- data/lib/smartystreets_ruby_sdk/request.rb +8 -11
- data/lib/smartystreets_ruby_sdk/response.rb +7 -9
- data/lib/smartystreets_ruby_sdk/retry_sender.rb +26 -32
- data/lib/smartystreets_ruby_sdk/shared_credentials.rb +9 -11
- data/lib/smartystreets_ruby_sdk/signing_sender.rb +9 -11
- data/lib/smartystreets_ruby_sdk/sleeper.rb +3 -5
- data/lib/smartystreets_ruby_sdk/static_credentials.rb +9 -11
- data/lib/smartystreets_ruby_sdk/status_code_sender.rb +29 -33
- data/lib/smartystreets_ruby_sdk/url_prefix_sender.rb +9 -11
- data/lib/smartystreets_ruby_sdk/us_street/analysis.rb +16 -21
- data/lib/smartystreets_ruby_sdk/us_street/candidate.rb +19 -23
- data/lib/smartystreets_ruby_sdk/us_street/client.rb +47 -60
- data/lib/smartystreets_ruby_sdk/us_street/client_builder.rb +15 -0
- data/lib/smartystreets_ruby_sdk/us_street/components.rb +27 -32
- data/lib/smartystreets_ruby_sdk/us_street/lookup.rb +20 -27
- data/lib/smartystreets_ruby_sdk/us_street/metadata.rb +23 -27
- data/lib/smartystreets_ruby_sdk/us_street.rb +3 -5
- data/lib/smartystreets_ruby_sdk/us_zipcode/city.rb +8 -14
- data/lib/smartystreets_ruby_sdk/us_zipcode/client.rb +36 -51
- data/lib/smartystreets_ruby_sdk/us_zipcode/client_builder.rb +15 -0
- data/lib/smartystreets_ruby_sdk/us_zipcode/lookup.rb +9 -16
- data/lib/smartystreets_ruby_sdk/us_zipcode/result.rb +30 -34
- data/lib/smartystreets_ruby_sdk/us_zipcode/zip_code.rb +14 -32
- data/lib/smartystreets_ruby_sdk/us_zipcode.rb +3 -5
- data/lib/smartystreets_ruby_sdk/version.rb +2 -2
- data/lib/smartystreets_ruby_sdk.rb +1 -30
- data/smartystreets_ruby_sdk.gemspec +12 -3
- metadata +15 -61
- data/.github/workflows/gem-publish.yml +0 -58
- data/CHANGELOG.md +0 -5
- data/Dockerfile +0 -10
- data/docker-compose.yml +0 -12
- data/examples/international_autocomplete_example.rb +0 -47
- data/examples/international_example.rb +0 -53
- data/examples/us_autocomplete_pro_example.rb +0 -56
- data/examples/us_extract_example.rb +0 -63
- data/examples/us_reverse_geo_example.rb +0 -47
- data/lib/smartystreets_ruby_sdk/client_builder.rb +0 -188
- data/lib/smartystreets_ruby_sdk/international_autocomplete/client.rb +0 -61
- data/lib/smartystreets_ruby_sdk/international_autocomplete/lookup.rb +0 -21
- data/lib/smartystreets_ruby_sdk/international_autocomplete/suggestion.rb +0 -16
- data/lib/smartystreets_ruby_sdk/international_street/analysis.rb +0 -17
- data/lib/smartystreets_ruby_sdk/international_street/candidate.rb +0 -23
- data/lib/smartystreets_ruby_sdk/international_street/changes.rb +0 -15
- data/lib/smartystreets_ruby_sdk/international_street/client.rb +0 -63
- data/lib/smartystreets_ruby_sdk/international_street/components.rb +0 -58
- data/lib/smartystreets_ruby_sdk/international_street/language_mode.rb +0 -9
- data/lib/smartystreets_ruby_sdk/international_street/lookup.rb +0 -82
- data/lib/smartystreets_ruby_sdk/international_street/metadata.rb +0 -17
- data/lib/smartystreets_ruby_sdk/international_street/rootlevel.rb +0 -25
- data/lib/smartystreets_ruby_sdk/international_street.rb +0 -12
- data/lib/smartystreets_ruby_sdk/license_sender.rb +0 -15
- data/lib/smartystreets_ruby_sdk/logger.rb +0 -7
- data/lib/smartystreets_ruby_sdk/proxy.rb +0 -16
- data/lib/smartystreets_ruby_sdk/us_autocomplete/client.rb +0 -72
- data/lib/smartystreets_ruby_sdk/us_autocomplete/geolocation_type.rb +0 -9
- data/lib/smartystreets_ruby_sdk/us_autocomplete/lookup.rb +0 -38
- data/lib/smartystreets_ruby_sdk/us_autocomplete/suggestion.rb +0 -16
- data/lib/smartystreets_ruby_sdk/us_autocomplete.rb +0 -9
- data/lib/smartystreets_ruby_sdk/us_autocomplete_pro/client.rb +0 -78
- data/lib/smartystreets_ruby_sdk/us_autocomplete_pro/geolocation_type.rb +0 -8
- data/lib/smartystreets_ruby_sdk/us_autocomplete_pro/lookup.rb +0 -63
- data/lib/smartystreets_ruby_sdk/us_autocomplete_pro/suggestion.rb +0 -18
- data/lib/smartystreets_ruby_sdk/us_autocomplete_pro.rb +0 -10
- data/lib/smartystreets_ruby_sdk/us_extract/address.rb +0 -24
- data/lib/smartystreets_ruby_sdk/us_extract/client.rb +0 -49
- data/lib/smartystreets_ruby_sdk/us_extract/lookup.rb +0 -22
- data/lib/smartystreets_ruby_sdk/us_extract/metadata.rb +0 -17
- data/lib/smartystreets_ruby_sdk/us_extract/result.rb +0 -21
- data/lib/smartystreets_ruby_sdk/us_extract.rb +0 -10
- data/lib/smartystreets_ruby_sdk/us_reverse_geo/address.rb +0 -16
- data/lib/smartystreets_ruby_sdk/us_reverse_geo/client.rb +0 -38
- data/lib/smartystreets_ruby_sdk/us_reverse_geo/coordinate.rb +0 -25
- data/lib/smartystreets_ruby_sdk/us_reverse_geo/lookup.rb +0 -21
- data/lib/smartystreets_ruby_sdk/us_reverse_geo/result.rb +0 -20
- data/lib/smartystreets_ruby_sdk/us_reverse_geo/us_reverse_geo_response.rb +0 -17
- data/lib/smartystreets_ruby_sdk/us_reverse_geo.rb +0 -12
- data/lib/smartystreets_ruby_sdk/us_street/match_type.rb +0 -10
- data/lib/smartystreets_ruby_sdk/us_zipcode/alternate_county.rb +0 -15
- 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
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
12
|
+
def send_lookup(lookup)
|
13
|
+
batch = Batch.new
|
14
|
+
batch.add(lookup)
|
15
|
+
send_batch(batch)
|
16
|
+
end
|
25
17
|
|
26
|
-
|
18
|
+
def send_batch(batch)
|
19
|
+
smarty_request = Request.new
|
27
20
|
|
28
|
-
|
21
|
+
return if batch.size == 0
|
29
22
|
|
30
|
-
|
31
|
-
|
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
|
-
|
26
|
+
response = @sender.send(smarty_request)
|
37
27
|
|
38
|
-
|
28
|
+
raise response.error if response.error
|
39
29
|
|
40
|
-
|
41
|
-
|
30
|
+
candidates = @serializer.deserialize(response.payload)
|
31
|
+
candidates = [] if candidates == nil
|
42
32
|
|
43
|
-
|
44
|
-
|
33
|
+
assign_candidates_to_lookups(batch, candidates)
|
34
|
+
end
|
45
35
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
53
|
+
converted_obj.push(converted_lookup)
|
54
|
+
}
|
55
|
+
converted_obj
|
56
|
+
end
|
69
57
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
10
|
-
|
11
|
-
end
|
12
|
-
end
|
9
|
+
module USStreet
|
10
|
+
end
|
@@ -1,16 +1,10 @@
|
|
1
|
-
|
2
|
-
|
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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
12
|
+
def send_lookup(lookup)
|
13
|
+
batch = Batch.new
|
14
|
+
batch.add(lookup)
|
15
|
+
send_batch(batch)
|
16
|
+
end
|
25
17
|
|
26
|
-
|
18
|
+
def send_batch(batch)
|
19
|
+
smarty_request = Request.new
|
27
20
|
|
28
|
-
|
21
|
+
return if batch.size == 0
|
29
22
|
|
30
|
-
|
31
|
-
|
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
|
-
|
26
|
+
response = @sender.send(smarty_request)
|
37
27
|
|
38
|
-
|
28
|
+
raise response.error if response.error
|
39
29
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
30
|
+
results = @serializer.deserialize(response.payload)
|
31
|
+
results = [] if results == nil
|
32
|
+
assign_results_to_lookups(batch, results)
|
33
|
+
end
|
44
34
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
62
|
-
|
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
|
-
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
27
|
-
|
19
|
+
def is_valid?
|
20
|
+
@status == nil and @reason == nil
|
21
|
+
end
|
28
22
|
|
29
|
-
|
30
|
-
|
31
|
-
end
|
23
|
+
def convert_cities
|
24
|
+
converted_cities = []
|
32
25
|
|
33
|
-
|
26
|
+
@cities.each do |city|
|
27
|
+
converted_cities.push(City.new(city))
|
34
28
|
end
|
35
29
|
|
36
|
-
|
37
|
-
|
30
|
+
converted_cities
|
31
|
+
end
|
38
32
|
|
39
|
-
|
40
|
-
|
41
|
-
end
|
33
|
+
def convert_zipcodes
|
34
|
+
converted_zipcodes = []
|
42
35
|
|
43
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|