smartystreets_ruby_sdk 6.1.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 954bacc17a899a815959f93e7c44494e7514305cfb64cf96df12816c8397ab12
4
- data.tar.gz: 05e7e0e7544e5eddbc31de48e7d1f94a1187dbd9399aa2e957d20b6da93276cb
3
+ metadata.gz: 2a717adaa26421afae4a9537b752f1d0fa6765481a733bdfe49fbfe4019066d1
4
+ data.tar.gz: a0fdc35eb728b744b311f02ee3267cb74e1278dc03f5c453672324027cd4b589
5
5
  SHA512:
6
- metadata.gz: 61e551343736810efdb5d1d0f35811523551280bda4b633a0b6607f3c66b43485e35b1d4b5b652d8d28a7603eb4e78df8cc622c9587ea673b87b4be92945e6af
7
- data.tar.gz: 9e30ec67d9f24d9d2f5c667ef493e0433d1838a3a73131cf1223a3347fb9a141d88eb075a7e55514b6ca34498acdca2bad12ec18ab09991ce6d639d52a9cabd7
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
 
@@ -43,11 +46,11 @@ us_reverse_geo_api:
43
46
  cd examples && ruby us_reverse_geo_example.rb
44
47
 
45
48
  us_street_api:
46
- cd examples && ruby us_street_single_address_example.rb && ruby us_street_multiple_address_example.rb
49
+ cd examples && ruby us_street_single_address_example.rb && ruby us_street_multiple_address_example.rb && ruby us_street_component_analysis.rb && ruby us_street_component_analysis_example.rb
47
50
 
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
+
@@ -0,0 +1,54 @@
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/us_street/lookup'
5
+ require '../lib/smartystreets_ruby_sdk/us_street/match_type'
6
+
7
+ class USStreetComponentAnalysisExample
8
+ def run
9
+ # For client-side requests (browser/mobile), use this code:
10
+ # key = ENV['SMARTY_AUTH_WEB']
11
+ # referer = ENV['SMARTY_AUTH_REFERER']
12
+ # credentials = SmartyStreets::SharedCredentials.new(key, referer)
13
+
14
+ # For server-to-server requests, use this code:
15
+ id = ENV['SMARTY_AUTH_ID']
16
+ token = ENV['SMARTY_AUTH_TOKEN']
17
+ credentials = SmartyStreets::StaticCredentials.new(id, token)
18
+
19
+ client = SmartyStreets::ClientBuilder.new(credentials)
20
+ .with_feature_component_analysis() # To add component analysis feature you need to specify when you create the client.
21
+ .build_us_street_api_client
22
+
23
+ lookup = SmartyStreets::USStreet::Lookup.new
24
+ lookup.street = "1 Rosedale"
25
+ lookup.secondary = "APT 2"
26
+ lookup.city = "Baltimore"
27
+ lookup.state = "MD"
28
+ lookup.zipcode = "21229"
29
+ lookup.match = SmartyStreets::USStreet::MatchType::ENHANCED # Enhanced matching is required to return component analysis results.
30
+
31
+ begin
32
+ client.send_lookup(lookup)
33
+ rescue SmartyStreets::SmartyError => err
34
+ puts err
35
+ return
36
+ end
37
+
38
+ result = lookup.result
39
+
40
+ if result.empty?
41
+ return
42
+ end
43
+
44
+ first_candidate = result[0]
45
+
46
+ # Here is an example of how to access the result of component analysis.
47
+ puts "Primary Number: "
48
+ puts "\tStatus: #{first_candidate.analysis.components.secondary_number.status}"
49
+ puts "\tChange: #{first_candidate.analysis.components.secondary_number.change}"
50
+ end
51
+ end
52
+
53
+ example = USStreetComponentAnalysisExample.new
54
+ example.run
@@ -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
+
@@ -0,0 +1,5 @@
1
+ require 'smartystreets_ruby_sdk/international_postal_code/lookup'
2
+ require 'smartystreets_ruby_sdk/international_postal_code/candidate'
3
+ require 'smartystreets_ruby_sdk/international_postal_code/client'
4
+
5
+
@@ -1,9 +1,11 @@
1
+ require_relative 'component_analysis'
2
+
1
3
  module SmartyStreets
2
4
  module USStreet
3
5
  # See "https://smartystreets.com/docs/cloud/us-street-api#analysis"
4
6
  class Analysis
5
7
  attr_reader :lacs_link_code, :active, :footnotes, :lacs_link_indicator, :dpv_match_code, :is_suite_link_match,
6
- :is_ews_match, :dpv_footnotes, :cmra, :vacant, :no_stat, :enhanced_match
8
+ :is_ews_match, :dpv_footnotes, :cmra, :vacant, :no_stat, :enhanced_match, :components
7
9
 
8
10
  def initialize(obj)
9
11
  @dpv_match_code = obj['dpv_match_code']
@@ -18,6 +20,7 @@ module SmartyStreets
18
20
  @lacs_link_indicator = obj['lacslink_indicator']
19
21
  @is_suite_link_match = obj['suitelink_match']
20
22
  @enhanced_match = obj['enhanced_match']
23
+ @components = ComponentAnalysis.new(obj.fetch('components', {}))
21
24
  end
22
25
  end
23
26
  end
@@ -0,0 +1,36 @@
1
+ module SmartyStreets
2
+ module USStreet
3
+ class MatchInfo
4
+ attr_reader :status, :change
5
+
6
+ def initialize(obj = {})
7
+ @status = obj['status']
8
+ @change = obj['change'] || []
9
+ end
10
+ end
11
+
12
+ class ComponentAnalysis
13
+ attr_reader :primary_number, :street_predirection, :street_name, :street_postdirection,
14
+ :street_suffix, :secondary_number, :secondary_designator, :extra_secondary_number,
15
+ :extra_secondary_designator, :city_name, :state_abbreviation, :zipcode,
16
+ :plus4_code, :urbanization
17
+
18
+ def initialize(obj = {})
19
+ @primary_number = MatchInfo.new(obj.fetch('primary_number', {}))
20
+ @street_predirection = MatchInfo.new(obj.fetch('street_predirection', {}))
21
+ @street_name = MatchInfo.new(obj.fetch('street_name', {}))
22
+ @street_postdirection = MatchInfo.new(obj.fetch('street_postdirection', {}))
23
+ @street_suffix = MatchInfo.new(obj.fetch('street_suffix', {}))
24
+ @secondary_number = MatchInfo.new(obj.fetch('secondary_number', {}))
25
+ @secondary_designator = MatchInfo.new(obj.fetch('secondary_designator', {}))
26
+ @extra_secondary_number = MatchInfo.new(obj.fetch('extra_secondary_number', {}))
27
+ @extra_secondary_designator = MatchInfo.new(obj.fetch('extra_secondary_designator', {}))
28
+ @city_name = MatchInfo.new(obj.fetch('city_name', {}))
29
+ @state_abbreviation = MatchInfo.new(obj.fetch('state_abbreviation', {}))
30
+ @zipcode = MatchInfo.new(obj.fetch('zipcode', {}))
31
+ @plus4_code = MatchInfo.new(obj.fetch('plus4_code', {}))
32
+ @urbanization = MatchInfo.new(obj.fetch('urbanization', {}))
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module SmartyStreets
2
- VERSION = '6.1.2' # DO NOT EDIT (this is updated by a build job when a new release is published)
2
+ VERSION = '6.3.0' # DO NOT EDIT (this is updated by a build job when a new release is published)
3
3
  end
@@ -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.1.2
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-10-21 00:00:00.000000000 Z
11
+ date: 2025-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -93,10 +93,12 @@ 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
99
100
  - examples/us_reverse_geo_example.rb
101
+ - examples/us_street_component_analysis_example.rb
100
102
  - examples/us_street_multiple_address_example.rb
101
103
  - examples/us_street_single_address_example.rb
102
104
  - examples/us_zipcode_multiple_lookup_example.rb
@@ -112,6 +114,10 @@ files:
112
114
  - lib/smartystreets_ruby_sdk/international_autocomplete/client.rb
113
115
  - lib/smartystreets_ruby_sdk/international_autocomplete/lookup.rb
114
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
115
121
  - lib/smartystreets_ruby_sdk/international_street.rb
116
122
  - lib/smartystreets_ruby_sdk/international_street/analysis.rb
117
123
  - lib/smartystreets_ruby_sdk/international_street/candidate.rb
@@ -182,6 +188,7 @@ files:
182
188
  - lib/smartystreets_ruby_sdk/us_street/analysis.rb
183
189
  - lib/smartystreets_ruby_sdk/us_street/candidate.rb
184
190
  - lib/smartystreets_ruby_sdk/us_street/client.rb
191
+ - lib/smartystreets_ruby_sdk/us_street/component_analysis.rb
185
192
  - lib/smartystreets_ruby_sdk/us_street/components.rb
186
193
  - lib/smartystreets_ruby_sdk/us_street/lookup.rb
187
194
  - lib/smartystreets_ruby_sdk/us_street/match_type.rb