smartystreets_ruby_sdk 6.2.0 → 6.3.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.
- checksums.yaml +4 -4
- data/Makefile +5 -2
- data/examples/international_postal_code_example.rb +59 -0
- data/lib/smartystreets_ruby_sdk/client_builder.rb +7 -0
- data/lib/smartystreets_ruby_sdk/international_postal_code/candidate.rb +35 -0
- data/lib/smartystreets_ruby_sdk/international_postal_code/client.rb +60 -0
- data/lib/smartystreets_ruby_sdk/international_postal_code/lookup.rb +21 -0
- data/lib/smartystreets_ruby_sdk/international_postal_code.rb +5 -0
- data/lib/smartystreets_ruby_sdk/version.rb +1 -1
- data/lib/smartystreets_ruby_sdk.rb +1 -0
- metadata +7 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2a717adaa26421afae4a9537b752f1d0fa6765481a733bdfe49fbfe4019066d1
|
|
4
|
+
data.tar.gz: a0fdc35eb728b744b311f02ee3267cb74e1278dc03f5c453672324027cd4b589
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4ae46059f92d3de97bc82adefee2a45aad62e34d17fba1b4d5d6b138aa85943275becdcb15832feafc1b7706649c81190ad1ffa2c3d5f9fb6aee45d3a44b8fc5
|
|
7
|
+
data.tar.gz: 13dd12de3c3ac0defae3a13e13fe8cf817b3c48bbdb489e22bdd33ca29ffffceffd3546a566e923c1009b0067e8abda532a5c66d75dd59c120654b94bebccaa7
|
data/Makefile
CHANGED
|
@@ -27,6 +27,9 @@ publish: package
|
|
|
27
27
|
international_autocomplete_api:
|
|
28
28
|
cd examples && ruby international_autocomplete_example.rb
|
|
29
29
|
|
|
30
|
+
international_postal_code_api:
|
|
31
|
+
cd examples && ruby international_postal_code_example.rb
|
|
32
|
+
|
|
30
33
|
international_street_api:
|
|
31
34
|
cd examples && ruby international_example.rb
|
|
32
35
|
|
|
@@ -48,6 +51,6 @@ us_street_api:
|
|
|
48
51
|
us_zipcode_api:
|
|
49
52
|
cd examples && ruby us_zipcode_single_lookup_example.rb && ruby us_zipcode_multiple_lookup_example.rb
|
|
50
53
|
|
|
51
|
-
examples: international_autocomplete_api international_street_api us_autocomplete_pro_api us_enrichment_api us_extract_api us_reverse_geo_api us_street_api us_zipcode_api
|
|
54
|
+
examples: international_autocomplete_api international_postal_code_api international_street_api us_autocomplete_pro_api us_enrichment_api us_extract_api us_reverse_geo_api us_street_api us_zipcode_api
|
|
52
55
|
|
|
53
|
-
.PHONY: clean test dependencies package publish international_autocomplete_api international_street_api us_autocomplete_pro_api us_enrichment_api us_extract_api us_reverse_geo_api us_street_api us_zipcode_api examples
|
|
56
|
+
.PHONY: clean test dependencies package publish international_autocomplete_api international_postal_code_api international_street_api us_autocomplete_pro_api us_enrichment_api us_extract_api us_reverse_geo_api us_street_api us_zipcode_api examples
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require '../lib/smartystreets_ruby_sdk/static_credentials'
|
|
2
|
+
require '../lib/smartystreets_ruby_sdk/shared_credentials'
|
|
3
|
+
require '../lib/smartystreets_ruby_sdk/client_builder'
|
|
4
|
+
require '../lib/smartystreets_ruby_sdk/international_postal_code/lookup'
|
|
5
|
+
|
|
6
|
+
class InternationalPostalCodeExample
|
|
7
|
+
Lookup = SmartyStreets::InternationalPostalCode::Lookup
|
|
8
|
+
|
|
9
|
+
def run
|
|
10
|
+
# We recommend storing your secret keys in environment variables instead---it's safer!
|
|
11
|
+
# key = ENV['SMARTY_AUTH_WEB']
|
|
12
|
+
# referer = ENV['SMARTY_AUTH_REFERER']
|
|
13
|
+
# credentials = SmartyStreets::SharedCredentials.new(key, referer)
|
|
14
|
+
|
|
15
|
+
id = ENV['SMARTY_AUTH_ID_DEV']
|
|
16
|
+
token = ENV['SMARTY_AUTH_TOKEN_DEV']
|
|
17
|
+
credentials = SmartyStreets::StaticCredentials.new(id, token)
|
|
18
|
+
|
|
19
|
+
client = SmartyStreets::ClientBuilder.new(credentials).with_base_url("https://international-postal-code.api.rivendell.smartyops.net/lookup").build_international_postal_code_api_client
|
|
20
|
+
|
|
21
|
+
# Documentation for input fields can be found at:
|
|
22
|
+
# https://smartystreets.com/docs/cloud/international-postal-code-api
|
|
23
|
+
|
|
24
|
+
lookup = Lookup.new
|
|
25
|
+
lookup.input_id = 'ID-8675309'
|
|
26
|
+
lookup.locality = 'Sao Paulo'
|
|
27
|
+
lookup.administrative_area = 'SP'
|
|
28
|
+
lookup.country = 'Brazil'
|
|
29
|
+
lookup.postal_code = '02516'
|
|
30
|
+
|
|
31
|
+
results = client.send_lookup(lookup)
|
|
32
|
+
|
|
33
|
+
puts 'Results:'
|
|
34
|
+
puts
|
|
35
|
+
results.each_with_index do |candidate, c|
|
|
36
|
+
puts "Candidate: #{c}"
|
|
37
|
+
display(candidate.input_id)
|
|
38
|
+
display(candidate.country_iso_3)
|
|
39
|
+
display(candidate.locality)
|
|
40
|
+
display(candidate.dependent_locality)
|
|
41
|
+
display(candidate.double_dependent_locality)
|
|
42
|
+
display(candidate.sub_administrative_area)
|
|
43
|
+
display(candidate.administrative_area)
|
|
44
|
+
display(candidate.super_administrative_area)
|
|
45
|
+
display(candidate.postal_code)
|
|
46
|
+
puts
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def display(value)
|
|
51
|
+
if value && value.length > 0
|
|
52
|
+
puts " #{value}"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
InternationalPostalCodeExample.new.run
|
|
58
|
+
|
|
59
|
+
|
|
@@ -18,6 +18,7 @@ require_relative 'international_autocomplete/client'
|
|
|
18
18
|
require_relative 'us_reverse_geo/client'
|
|
19
19
|
require_relative 'us_autocomplete_pro/client'
|
|
20
20
|
require_relative 'us_enrichment/client'
|
|
21
|
+
require_relative 'international_postal_code/client'
|
|
21
22
|
|
|
22
23
|
module SmartyStreets
|
|
23
24
|
# The ClientBuilder class helps you build a client object for one of the supported SmartyStreets APIs.
|
|
@@ -32,6 +33,7 @@ module SmartyStreets
|
|
|
32
33
|
US_ZIP_CODE_API_URL = 'https://us-zipcode.api.smarty.com/lookup'.freeze
|
|
33
34
|
US_REVERSE_GEO_API_URL = 'https://us-reverse-geo.api.smarty.com/lookup'.freeze
|
|
34
35
|
US_ENRICHMENT_API_URL = 'https://us-enrichment.api.smarty.com/lookup'.freeze
|
|
36
|
+
INTERNATIONAL_POSTAL_CODE_API_URL = 'https://international-postal-code.api.smarty.com/lookup'.freeze
|
|
35
37
|
|
|
36
38
|
def initialize(signer)
|
|
37
39
|
@signer = signer
|
|
@@ -189,6 +191,11 @@ module SmartyStreets
|
|
|
189
191
|
USEnrichment::Client.new(build_sender, @serializer)
|
|
190
192
|
end
|
|
191
193
|
|
|
194
|
+
def build_international_postal_code_api_client
|
|
195
|
+
ensure_url_prefix_not_null(INTERNATIONAL_POSTAL_CODE_API_URL)
|
|
196
|
+
InternationalPostalCode::Client.new(build_sender, @serializer)
|
|
197
|
+
end
|
|
198
|
+
|
|
192
199
|
# </editor-fold>
|
|
193
200
|
|
|
194
201
|
def build_sender
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module SmartyStreets
|
|
2
|
+
module InternationalPostalCode
|
|
3
|
+
# Represents a single candidate returned by the International Postal Code API.
|
|
4
|
+
# See https://smartystreets.com/docs/cloud/international-postal-code-api
|
|
5
|
+
class Candidate
|
|
6
|
+
attr_reader :input_id,
|
|
7
|
+
:administrative_area,
|
|
8
|
+
:sub_administrative_area,
|
|
9
|
+
:super_administrative_area,
|
|
10
|
+
:country_iso_3,
|
|
11
|
+
:locality,
|
|
12
|
+
:dependent_locality,
|
|
13
|
+
:dependent_locality_name,
|
|
14
|
+
:double_dependent_locality,
|
|
15
|
+
:postal_code,
|
|
16
|
+
:postal_code_extra
|
|
17
|
+
|
|
18
|
+
def initialize(obj)
|
|
19
|
+
@input_id = obj['input_id']
|
|
20
|
+
@administrative_area = obj['administrative_area']
|
|
21
|
+
@sub_administrative_area = obj['sub_administrative_area']
|
|
22
|
+
@super_administrative_area = obj['super_administrative_area']
|
|
23
|
+
@country_iso_3 = obj['country_iso_3']
|
|
24
|
+
@locality = obj['locality']
|
|
25
|
+
@dependent_locality = obj['dependent_locality']
|
|
26
|
+
@dependent_locality_name = obj['dependent_locality_name']
|
|
27
|
+
@double_dependent_locality = obj['double_dependent_locality']
|
|
28
|
+
@postal_code = obj['postal_code']
|
|
29
|
+
@postal_code_extra = obj['postal_code_extra']
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require_relative '../request'
|
|
2
|
+
require_relative '../exceptions'
|
|
3
|
+
require_relative 'candidate'
|
|
4
|
+
|
|
5
|
+
module SmartyStreets
|
|
6
|
+
module InternationalPostalCode
|
|
7
|
+
# It is recommended to instantiate this class using ClientBuilder.build_international_postal_code_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 International Postal Code API and stores the result in the Lookup's results field.
|
|
15
|
+
def send_lookup(lookup)
|
|
16
|
+
raise SmartyStreets::SmartyError, 'Send() must be passed a Lookup.' if lookup.nil?
|
|
17
|
+
|
|
18
|
+
request = build_request(lookup)
|
|
19
|
+
|
|
20
|
+
response = @sender.send(request)
|
|
21
|
+
|
|
22
|
+
raise response.error if response.error
|
|
23
|
+
|
|
24
|
+
candidate_hashes = @serializer.deserialize(response.payload) || []
|
|
25
|
+
candidates = convert_candidates(candidate_hashes)
|
|
26
|
+
lookup.results = candidates
|
|
27
|
+
candidates
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def build_request(lookup)
|
|
31
|
+
request = SmartyStreets::Request.new
|
|
32
|
+
|
|
33
|
+
add_parameter(request, 'input_id', lookup.input_id)
|
|
34
|
+
add_parameter(request, 'country', lookup.country)
|
|
35
|
+
add_parameter(request, 'locality', lookup.locality)
|
|
36
|
+
add_parameter(request, 'administrative_area', lookup.administrative_area)
|
|
37
|
+
add_parameter(request, 'postal_code', lookup.postal_code)
|
|
38
|
+
|
|
39
|
+
request
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def convert_candidates(candidate_hashes)
|
|
43
|
+
converted = []
|
|
44
|
+
return converted if candidate_hashes.nil?
|
|
45
|
+
|
|
46
|
+
candidate_hashes.each do |obj|
|
|
47
|
+
converted.push(InternationalPostalCode::Candidate.new(obj))
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
converted
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def add_parameter(request, key, value)
|
|
54
|
+
request.parameters[key] = value unless value.nil? or value.empty?
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module SmartyStreets
|
|
2
|
+
module InternationalPostalCode
|
|
3
|
+
# Holds the input data for a postal code lookup and the results returned by the API.
|
|
4
|
+
# See https://smartystreets.com/docs/cloud/international-postal-code-api
|
|
5
|
+
class Lookup
|
|
6
|
+
|
|
7
|
+
attr_accessor :input_id, :country, :locality, :administrative_area, :postal_code, :results
|
|
8
|
+
|
|
9
|
+
def initialize
|
|
10
|
+
@input_id = nil
|
|
11
|
+
@country = nil
|
|
12
|
+
@locality = nil
|
|
13
|
+
@administrative_area = nil
|
|
14
|
+
@postal_code = nil
|
|
15
|
+
@results = []
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
|
|
@@ -25,6 +25,7 @@ require 'smartystreets_ruby_sdk/us_zipcode'
|
|
|
25
25
|
require 'smartystreets_ruby_sdk/us_autocomplete_pro'
|
|
26
26
|
require 'smartystreets_ruby_sdk/international_street'
|
|
27
27
|
require 'smartystreets_ruby_sdk/international_autocomplete'
|
|
28
|
+
require 'smartystreets_ruby_sdk/international_postal_code'
|
|
28
29
|
require 'smartystreets_ruby_sdk/us_reverse_geo'
|
|
29
30
|
|
|
30
31
|
module SmartyStreets
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: smartystreets_ruby_sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 6.
|
|
4
|
+
version: 6.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- SmartyStreets SDK Team
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-11-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -93,6 +93,7 @@ files:
|
|
|
93
93
|
- docker-compose.yml
|
|
94
94
|
- examples/international_autocomplete_example.rb
|
|
95
95
|
- examples/international_example.rb
|
|
96
|
+
- examples/international_postal_code_example.rb
|
|
96
97
|
- examples/us_autocomplete_pro_example.rb
|
|
97
98
|
- examples/us_enrichment_example.rb
|
|
98
99
|
- examples/us_extract_example.rb
|
|
@@ -113,6 +114,10 @@ files:
|
|
|
113
114
|
- lib/smartystreets_ruby_sdk/international_autocomplete/client.rb
|
|
114
115
|
- lib/smartystreets_ruby_sdk/international_autocomplete/lookup.rb
|
|
115
116
|
- lib/smartystreets_ruby_sdk/international_autocomplete/suggestion.rb
|
|
117
|
+
- lib/smartystreets_ruby_sdk/international_postal_code.rb
|
|
118
|
+
- lib/smartystreets_ruby_sdk/international_postal_code/candidate.rb
|
|
119
|
+
- lib/smartystreets_ruby_sdk/international_postal_code/client.rb
|
|
120
|
+
- lib/smartystreets_ruby_sdk/international_postal_code/lookup.rb
|
|
116
121
|
- lib/smartystreets_ruby_sdk/international_street.rb
|
|
117
122
|
- lib/smartystreets_ruby_sdk/international_street/analysis.rb
|
|
118
123
|
- lib/smartystreets_ruby_sdk/international_street/candidate.rb
|