smartystreets_ruby_sdk 6.4.1 → 10.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.
- checksums.yaml +4 -4
- data/.claude/settings.json +18 -0
- data/.github/workflows/ci.yml +10 -0
- data/.github/workflows/publish.yml +29 -0
- data/.github/workflows/test.yml +21 -0
- data/CLAUDE.md +73 -0
- data/Makefile +11 -5
- data/README.md +2 -0
- data/examples/international_autocomplete_example.rb +10 -7
- data/examples/international_example.rb +7 -6
- data/examples/international_postal_code_example.rb +5 -4
- data/examples/us_autocomplete_example.rb +69 -0
- data/examples/us_autocomplete_pro_example.rb +10 -12
- data/examples/us_enrichment_business_example.rb +72 -0
- data/examples/us_enrichment_business_name_search_example.rb +76 -0
- data/examples/us_enrichment_etag_example.rb +130 -0
- data/examples/us_enrichment_example.rb +130 -44
- data/examples/us_extract_example.rb +7 -6
- data/examples/us_reverse_geo_example.rb +10 -6
- data/examples/us_street_component_analysis_example.rb +2 -1
- data/examples/us_street_iana_timezone_example.rb +54 -0
- data/examples/us_street_match_strategy_example.rb +85 -0
- data/examples/us_street_multiple_address_example.rb +7 -6
- data/examples/us_street_single_address_example.rb +7 -6
- data/examples/us_zipcode_multiple_lookup_example.rb +7 -6
- data/examples/us_zipcode_single_lookup_example.rb +7 -6
- data/lib/smartystreets_ruby_sdk/basic_auth_credentials.rb +14 -0
- data/lib/smartystreets_ruby_sdk/client_builder.rb +36 -5
- data/lib/smartystreets_ruby_sdk/custom_header_sender.rb +16 -2
- data/lib/smartystreets_ruby_sdk/errors.rb +16 -11
- data/lib/smartystreets_ruby_sdk/exceptions.rb +12 -0
- data/lib/smartystreets_ruby_sdk/international_autocomplete/client.rb +2 -0
- data/lib/smartystreets_ruby_sdk/international_autocomplete/lookup.rb +4 -2
- data/lib/smartystreets_ruby_sdk/international_street/client.rb +10 -1
- data/lib/smartystreets_ruby_sdk/international_street/components.rb +8 -3
- data/lib/smartystreets_ruby_sdk/international_street/language_mode.rb +20 -3
- data/lib/smartystreets_ruby_sdk/international_street/lookup.rb +5 -12
- data/lib/smartystreets_ruby_sdk/international_street/rootlevel.rb +1 -5
- data/lib/smartystreets_ruby_sdk/native_sender.rb +3 -4
- data/lib/smartystreets_ruby_sdk/native_serializer.rb +1 -0
- data/lib/smartystreets_ruby_sdk/request.rb +2 -1
- data/lib/smartystreets_ruby_sdk/response.rb +13 -0
- data/lib/smartystreets_ruby_sdk/retry_sender.rb +32 -13
- data/lib/smartystreets_ruby_sdk/status_code_sender.rb +39 -22
- data/lib/smartystreets_ruby_sdk/us_autocomplete/client.rb +82 -0
- data/lib/smartystreets_ruby_sdk/us_autocomplete/geolocation_type.rb +8 -0
- data/lib/smartystreets_ruby_sdk/us_autocomplete/lookup.rb +73 -0
- data/lib/smartystreets_ruby_sdk/us_autocomplete/source_type.rb +8 -0
- data/lib/smartystreets_ruby_sdk/us_autocomplete/suggestion.rb +22 -0
- data/lib/smartystreets_ruby_sdk/us_autocomplete.rb +10 -0
- data/lib/smartystreets_ruby_sdk/us_autocomplete_pro/source_type.rb +8 -0
- data/lib/smartystreets_ruby_sdk/us_autocomplete_pro.rb +1 -0
- data/lib/smartystreets_ruby_sdk/us_enrichment/business/detail/attributes.rb +241 -0
- data/lib/smartystreets_ruby_sdk/us_enrichment/business/detail/response.rb +20 -0
- data/lib/smartystreets_ruby_sdk/us_enrichment/business/summary/business_entry.rb +16 -0
- data/lib/smartystreets_ruby_sdk/us_enrichment/business/summary/response.rb +24 -0
- data/lib/smartystreets_ruby_sdk/us_enrichment/client.rb +99 -30
- data/lib/smartystreets_ruby_sdk/us_enrichment/geo_reference/response.rb +2 -3
- data/lib/smartystreets_ruby_sdk/us_enrichment/lookup.rb +42 -9
- data/lib/smartystreets_ruby_sdk/us_enrichment/property/principal/response.rb +3 -4
- data/lib/smartystreets_ruby_sdk/us_enrichment/secondary/count/response.rb +2 -3
- data/lib/smartystreets_ruby_sdk/us_enrichment/secondary/response.rb +2 -3
- data/lib/smartystreets_ruby_sdk/us_enrichment.rb +6 -5
- data/lib/smartystreets_ruby_sdk/us_reverse_geo/source_type.rb +8 -0
- data/lib/smartystreets_ruby_sdk/us_reverse_geo/us_reverse_geo_response.rb +1 -1
- data/lib/smartystreets_ruby_sdk/us_reverse_geo.rb +1 -0
- data/lib/smartystreets_ruby_sdk/us_street/candidate.rb +2 -1
- data/lib/smartystreets_ruby_sdk/us_street/client.rb +10 -3
- data/lib/smartystreets_ruby_sdk/us_street/metadata.rb +5 -1
- data/lib/smartystreets_ruby_sdk/version.rb +1 -1
- data/lib/smartystreets_ruby_sdk.rb +2 -0
- metadata +27 -6
- data/.github/workflows/gem-publish.yml +0 -27
- data/lib/smartystreets_ruby_sdk/us_enrichment/risk/attributes.rb +0 -524
- data/lib/smartystreets_ruby_sdk/us_enrichment/risk/response.rb +0 -19
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6dfe1e04d687c3c2b33c116f12115c921092875761773196e70b05686642147d
|
|
4
|
+
data.tar.gz: c48c629d5c11195f679fe264b0fe4557e0fc78355e8f51b3ff62ebc463f27da8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1fdef4159968f9cdfd3a6e67afefc68ffdddbf527bc4331f424410274b27812c1cfce78c18ca81e8a3ccc817d4b0db267513a116c55e182d43e71e8ffee694c8
|
|
7
|
+
data.tar.gz: 5fc398cc1452df089d87f0f13869b6ead3ebe387a9698d47881a064b498b8a10b992381e5ec26d95626e0dfdceb56ec47833f15e91601a60f6bbb9de513c4a6c
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: Ruby Gem Publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- '**'
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
uses: ./.github/workflows/test.yml
|
|
11
|
+
|
|
12
|
+
publish:
|
|
13
|
+
needs: test
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v6
|
|
17
|
+
with:
|
|
18
|
+
fetch-depth: 0
|
|
19
|
+
|
|
20
|
+
- uses: ruby/setup-ruby@v1
|
|
21
|
+
with:
|
|
22
|
+
ruby-version: '3.3'
|
|
23
|
+
bundler-cache: false
|
|
24
|
+
|
|
25
|
+
- name: Publish
|
|
26
|
+
run: |
|
|
27
|
+
VERSION=${GITHUB_REF#refs/*/} make publish
|
|
28
|
+
env:
|
|
29
|
+
API_KEY: "${{ secrets.GEM_HOST_API_KEY }}"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
name: Ruby Tests (reusable)
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_call:
|
|
5
|
+
|
|
6
|
+
jobs:
|
|
7
|
+
test:
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
strategy:
|
|
10
|
+
matrix:
|
|
11
|
+
ruby-version: ['3.3', '3.4', '4.0']
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v6
|
|
14
|
+
- uses: ruby/setup-ruby@v1
|
|
15
|
+
with:
|
|
16
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
17
|
+
bundler-cache: false
|
|
18
|
+
- name: Install dependencies
|
|
19
|
+
run: make dependencies
|
|
20
|
+
- name: Test
|
|
21
|
+
run: make test
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Build and Test Commands
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Run all tests
|
|
9
|
+
rake test
|
|
10
|
+
# or
|
|
11
|
+
make test
|
|
12
|
+
|
|
13
|
+
# Run a single test file
|
|
14
|
+
ruby -Ilib:test test/smartystreets_ruby_sdk/test_batch.rb
|
|
15
|
+
|
|
16
|
+
# Install dependencies
|
|
17
|
+
gem install minitest
|
|
18
|
+
|
|
19
|
+
# Build the gem (used by CI, requires VERSION env var)
|
|
20
|
+
make package
|
|
21
|
+
|
|
22
|
+
# Run all example scripts (requires SMARTY_AUTH_ID and SMARTY_AUTH_TOKEN env vars)
|
|
23
|
+
make examples
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Architecture
|
|
27
|
+
|
|
28
|
+
This is the official SmartyStreets Ruby SDK for address verification APIs. It uses pure Ruby with Net::HTTP (no external runtime dependencies). Compatible with Ruby 3.3 and later.
|
|
29
|
+
|
|
30
|
+
### Core Design Patterns
|
|
31
|
+
|
|
32
|
+
**Builder Pattern**: `ClientBuilder` provides a fluent interface for configuring API clients:
|
|
33
|
+
```ruby
|
|
34
|
+
credentials = SmartyStreets::StaticCredentials.new(auth_id, auth_token)
|
|
35
|
+
client = SmartyStreets::ClientBuilder.new(credentials)
|
|
36
|
+
.retry_at_most(5)
|
|
37
|
+
.with_licenses(['us-rooftop-geocoding-cloud'])
|
|
38
|
+
.build_us_street_api_client
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**Chain of Responsibility**: HTTP requests flow through a middleware chain of "Sender" objects. Each sender wraps an inner sender (outermost to innermost):
|
|
42
|
+
```
|
|
43
|
+
URLPrefixSender → CustomQuerySender → LicenseSender → RetrySender → SigningSender → CustomHeaderSender → StatusCodeSender → NativeSender
|
|
44
|
+
```
|
|
45
|
+
`CustomHeaderSender` is only included when custom headers are configured; `RetrySender` only when max_retries > 0.
|
|
46
|
+
|
|
47
|
+
**Authentication**: Three credential types — `StaticCredentials` (auth-id/auth-token), `SharedCredentials` (website key/hostname), and `BasicAuthCredentials` (basic auth header). Credentials are passed to `ClientBuilder` and injected into the sender chain via `SigningSender`.
|
|
48
|
+
|
|
49
|
+
### Key Components
|
|
50
|
+
|
|
51
|
+
- **lib/smartystreets_ruby_sdk.rb**: Main entry point, requires all modules
|
|
52
|
+
- **client_builder.rb**: Constructs sender chains and API clients
|
|
53
|
+
- **Sender classes**: Middleware for URL prefixing, retries, authentication, status code handling
|
|
54
|
+
- **API modules** (us_street/, us_zipcode/, international_street/, etc.): Each contains:
|
|
55
|
+
- `client.rb`: API client with `send_lookup()` and `send_batch()` methods
|
|
56
|
+
- `lookup.rb`: Input model (JSONAble mixin for serialization)
|
|
57
|
+
- Response classes (candidate.rb, result.rb, etc.)
|
|
58
|
+
|
|
59
|
+
### Supported APIs
|
|
60
|
+
|
|
61
|
+
- US Street, US ZipCode, US Autocomplete, US Autocomplete Pro, US Extract, US Reverse Geo, US Enrichment
|
|
62
|
+
- International Street, International Autocomplete, International Postal Code
|
|
63
|
+
|
|
64
|
+
### Test Structure
|
|
65
|
+
|
|
66
|
+
Tests use Minitest with mock objects in `test/mocks/`. Test files mirror the lib structure under `test/smartystreets_ruby_sdk/`.
|
|
67
|
+
|
|
68
|
+
### Adding New API Support
|
|
69
|
+
|
|
70
|
+
1. Create new directory under `lib/smartystreets_ruby_sdk/` with client, lookup, and response classes
|
|
71
|
+
2. Add `build_[api]_client` method to `client_builder.rb`
|
|
72
|
+
3. Add requires to main `smartystreets_ruby_sdk.rb`
|
|
73
|
+
4. Create corresponding test files and example script
|
data/Makefile
CHANGED
|
@@ -12,7 +12,7 @@ test:
|
|
|
12
12
|
dependencies:
|
|
13
13
|
gem install minitest
|
|
14
14
|
|
|
15
|
-
package: clean dependencies
|
|
15
|
+
package: clean dependencies
|
|
16
16
|
sed -i "s/0\.0\.0/${VERSION}/g" "$(VERSION_FILE)" \
|
|
17
17
|
&& gem build *.gemspec \
|
|
18
18
|
&& git checkout "$(VERSION_FILE)"
|
|
@@ -33,11 +33,14 @@ international_postal_code_api:
|
|
|
33
33
|
international_street_api:
|
|
34
34
|
cd examples && ruby international_example.rb
|
|
35
35
|
|
|
36
|
+
us_autocomplete_api:
|
|
37
|
+
cd examples && ruby us_autocomplete_example.rb
|
|
38
|
+
|
|
36
39
|
us_autocomplete_pro_api:
|
|
37
40
|
cd examples && ruby us_autocomplete_pro_example.rb
|
|
38
41
|
|
|
39
42
|
us_enrichment_api:
|
|
40
|
-
cd examples && ruby us_enrichment_example.rb
|
|
43
|
+
cd examples && ruby us_enrichment_example.rb && ruby us_enrichment_business_example.rb && ruby us_enrichment_etag_example.rb && ruby us_enrichment_business_name_search_example.rb
|
|
41
44
|
|
|
42
45
|
us_extract_api:
|
|
43
46
|
cd examples && ruby us_extract_example.rb
|
|
@@ -46,11 +49,14 @@ us_reverse_geo_api:
|
|
|
46
49
|
cd examples && ruby us_reverse_geo_example.rb
|
|
47
50
|
|
|
48
51
|
us_street_api:
|
|
49
|
-
cd examples && ruby us_street_single_address_example.rb && ruby us_street_multiple_address_example.rb && ruby
|
|
52
|
+
cd examples && ruby us_street_single_address_example.rb && ruby us_street_multiple_address_example.rb && ruby us_street_component_analysis_example.rb && ruby us_street_iana_timezone_example.rb && ruby us_street_match_strategy_example.rb
|
|
53
|
+
|
|
54
|
+
us_street_match_strategy_api:
|
|
55
|
+
cd examples && ruby us_street_match_strategy_example.rb
|
|
50
56
|
|
|
51
57
|
us_zipcode_api:
|
|
52
58
|
cd examples && ruby us_zipcode_single_lookup_example.rb && ruby us_zipcode_multiple_lookup_example.rb
|
|
53
59
|
|
|
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
|
|
60
|
+
examples: international_autocomplete_api international_postal_code_api international_street_api us_autocomplete_pro_api us_autocomplete_api us_enrichment_api us_extract_api us_reverse_geo_api us_street_api us_zipcode_api
|
|
55
61
|
|
|
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
|
|
62
|
+
.PHONY: clean test dependencies package publish international_autocomplete_api international_postal_code_api international_street_api us_autocomplete_pro_api us_autocomplete_api us_enrichment_api us_extract_api us_reverse_geo_api us_street_api us_street_match_strategy_api us_zipcode_api examples
|
data/README.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
The official client libraries for accessing SmartyStreets APIs from Ruby
|
|
6
6
|
|
|
7
|
+
Compatible with Ruby 3.3 and later.
|
|
8
|
+
|
|
7
9
|
You may have noticed this page is curiously sparse. Don't panic, there's [documentation](https://smartystreets.com/docs/sdk/ruby) and [examples](examples).
|
|
8
10
|
|
|
9
11
|
[Apache 2.0 License](LICENSE.txt)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require '../lib/smartystreets_ruby_sdk/shared_credentials'
|
|
2
2
|
require '../lib/smartystreets_ruby_sdk/static_credentials'
|
|
3
|
+
require '../lib/smartystreets_ruby_sdk/basic_auth_credentials'
|
|
3
4
|
require '../lib/smartystreets_ruby_sdk/client_builder'
|
|
4
5
|
require '../lib/smartystreets_ruby_sdk/international_autocomplete/lookup'
|
|
5
6
|
require '../lib/smartystreets_ruby_sdk/international_autocomplete/client'
|
|
@@ -11,13 +12,13 @@ class InternationalAutocompleteExample
|
|
|
11
12
|
# key = 'Your SmartyStreets Auth Key here'
|
|
12
13
|
# referer = 'Your host name here'
|
|
13
14
|
# We recommend storing your secret keys in environment variables instead---it's safer!
|
|
14
|
-
key = ENV['SMARTY_AUTH_WEB']
|
|
15
|
-
referer = ENV['SMARTY_AUTH_REFERER']
|
|
16
|
-
credentials = SmartyStreets::SharedCredentials.new(key, referer)
|
|
15
|
+
# key = ENV['SMARTY_AUTH_WEB']
|
|
16
|
+
# referer = ENV['SMARTY_AUTH_REFERER']
|
|
17
|
+
# credentials = SmartyStreets::SharedCredentials.new(key, referer)
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
id = ENV['SMARTY_AUTH_ID']
|
|
20
|
+
token = ENV['SMARTY_AUTH_TOKEN']
|
|
21
|
+
credentials = SmartyStreets::BasicAuthCredentials.new(id, token)
|
|
21
22
|
|
|
22
23
|
client = SmartyStreets::ClientBuilder.new(credentials).build_international_autocomplete_api_client
|
|
23
24
|
|
|
@@ -27,13 +28,15 @@ class InternationalAutocompleteExample
|
|
|
27
28
|
lookup = Lookup.new('Louis')
|
|
28
29
|
lookup.country = "FRA"
|
|
29
30
|
lookup.locality = "Paris"
|
|
31
|
+
lookup.max_group_results = 5
|
|
32
|
+
lookup.geolocation = true
|
|
30
33
|
|
|
31
34
|
# lookup.add_custom_parameter('parameter', 'value')
|
|
32
35
|
|
|
33
36
|
suggestions = client.send(lookup) # The client will also return the suggestions directly
|
|
34
37
|
|
|
35
38
|
puts
|
|
36
|
-
puts '*** Result with some filters ***'
|
|
39
|
+
puts '*** Result with some filters (max_group_results=5, geolocation=on) ***'
|
|
37
40
|
puts
|
|
38
41
|
|
|
39
42
|
suggestions.each do |suggestion|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require '../lib/smartystreets_ruby_sdk/static_credentials'
|
|
2
2
|
require '../lib/smartystreets_ruby_sdk/shared_credentials'
|
|
3
|
+
require '../lib/smartystreets_ruby_sdk/basic_auth_credentials'
|
|
3
4
|
require '../lib/smartystreets_ruby_sdk/client_builder'
|
|
4
5
|
require '../lib/smartystreets_ruby_sdk/international_street/lookup'
|
|
5
6
|
|
|
@@ -10,13 +11,13 @@ class InternationalExample
|
|
|
10
11
|
# key = 'Your SmartyStreets Auth Key here'
|
|
11
12
|
# referer = 'Your host name here'
|
|
12
13
|
# We recommend storing your secret keys in environment variables instead---it's safer!
|
|
13
|
-
key = ENV['SMARTY_AUTH_WEB']
|
|
14
|
-
referer = ENV['SMARTY_AUTH_REFERER']
|
|
15
|
-
credentials = SmartyStreets::SharedCredentials.new(key, referer)
|
|
14
|
+
# key = ENV['SMARTY_AUTH_WEB']
|
|
15
|
+
# referer = ENV['SMARTY_AUTH_REFERER']
|
|
16
|
+
# credentials = SmartyStreets::SharedCredentials.new(key, referer)
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
id = ENV['SMARTY_AUTH_ID']
|
|
19
|
+
token = ENV['SMARTY_AUTH_TOKEN']
|
|
20
|
+
credentials = SmartyStreets::BasicAuthCredentials.new(id, token)
|
|
20
21
|
|
|
21
22
|
client = SmartyStreets::ClientBuilder.new(credentials).build_international_street_api_client
|
|
22
23
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require '../lib/smartystreets_ruby_sdk/static_credentials'
|
|
2
2
|
require '../lib/smartystreets_ruby_sdk/shared_credentials'
|
|
3
|
+
require '../lib/smartystreets_ruby_sdk/basic_auth_credentials'
|
|
3
4
|
require '../lib/smartystreets_ruby_sdk/client_builder'
|
|
4
5
|
require '../lib/smartystreets_ruby_sdk/international_postal_code/lookup'
|
|
5
6
|
|
|
@@ -12,11 +13,11 @@ class InternationalPostalCodeExample
|
|
|
12
13
|
# referer = ENV['SMARTY_AUTH_REFERER']
|
|
13
14
|
# credentials = SmartyStreets::SharedCredentials.new(key, referer)
|
|
14
15
|
|
|
15
|
-
id = ENV['
|
|
16
|
-
token = ENV['
|
|
17
|
-
credentials = SmartyStreets::
|
|
16
|
+
id = ENV['SMARTY_AUTH_ID']
|
|
17
|
+
token = ENV['SMARTY_AUTH_TOKEN']
|
|
18
|
+
credentials = SmartyStreets::BasicAuthCredentials.new(id, token)
|
|
18
19
|
|
|
19
|
-
client = SmartyStreets::ClientBuilder.new(credentials).
|
|
20
|
+
client = SmartyStreets::ClientBuilder.new(credentials).build_international_postal_code_api_client
|
|
20
21
|
|
|
21
22
|
# Documentation for input fields can be found at:
|
|
22
23
|
# https://smartystreets.com/docs/cloud/international-postal-code-api
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require '../lib/smartystreets_ruby_sdk/shared_credentials'
|
|
2
|
+
require '../lib/smartystreets_ruby_sdk/static_credentials'
|
|
3
|
+
require '../lib/smartystreets_ruby_sdk/basic_auth_credentials'
|
|
4
|
+
require '../lib/smartystreets_ruby_sdk/client_builder'
|
|
5
|
+
require '../lib/smartystreets_ruby_sdk/us_autocomplete/lookup'
|
|
6
|
+
require '../lib/smartystreets_ruby_sdk/us_autocomplete/source_type'
|
|
7
|
+
|
|
8
|
+
# This example is for US Autocomplete (V2). It has the same name as a previous product
|
|
9
|
+
# which has been deprecated since 2022, which we refer to as US Autocomplete Basic.
|
|
10
|
+
# If you are still using US Autocomplete Basic, this SDK will not work.
|
|
11
|
+
class USAutocompleteExample
|
|
12
|
+
Lookup = SmartyStreets::USAutocomplete::Lookup
|
|
13
|
+
SourceType = SmartyStreets::USAutocomplete::SourceType
|
|
14
|
+
|
|
15
|
+
def run
|
|
16
|
+
# key = 'Your SmartyStreets Auth Key here'
|
|
17
|
+
# referer = 'Your host name here'
|
|
18
|
+
# We recommend storing your secret keys in environment variables instead---it's safer!
|
|
19
|
+
# key = ENV['SMARTY_AUTH_WEB']
|
|
20
|
+
# referer = ENV['SMARTY_AUTH_REFERER']
|
|
21
|
+
# credentials = SmartyStreets::SharedCredentials.new(key, referer)
|
|
22
|
+
|
|
23
|
+
id = ENV['SMARTY_AUTH_ID']
|
|
24
|
+
token = ENV['SMARTY_AUTH_TOKEN']
|
|
25
|
+
credentials = SmartyStreets::BasicAuthCredentials.new(id, token)
|
|
26
|
+
|
|
27
|
+
client = SmartyStreets::ClientBuilder.new(credentials).build_us_autocomplete_api_client
|
|
28
|
+
|
|
29
|
+
# Documentation for input fields can be found at:
|
|
30
|
+
# https://www.smarty.com/docs/apis/us-autocomplete-v2/reference#http-request-input-fields
|
|
31
|
+
|
|
32
|
+
lookup = Lookup.new('1042 W Center')
|
|
33
|
+
lookup.add_city_filter('Denver,Aurora,CO')
|
|
34
|
+
lookup.add_city_filter('Orem,UT')
|
|
35
|
+
lookup.max_results = 5
|
|
36
|
+
lookup.prefer_ratio = 3
|
|
37
|
+
lookup.source = SourceType::ALL
|
|
38
|
+
|
|
39
|
+
# lookup.add_custom_parameter('parameter', 'value')
|
|
40
|
+
|
|
41
|
+
suggestions = client.send(lookup) # The client will also return the suggestions directly
|
|
42
|
+
|
|
43
|
+
puts
|
|
44
|
+
puts '*** Result with some filters ***'
|
|
45
|
+
puts
|
|
46
|
+
|
|
47
|
+
entry_id = nil
|
|
48
|
+
suggestions.each do |suggestion|
|
|
49
|
+
puts "#{suggestion.street_line} #{suggestion.city}, #{suggestion.state}"
|
|
50
|
+
entry_id = suggestion.entry_id if suggestion.entry_id && !suggestion.entry_id.empty?
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Expand the secondaries of a result that has an entry_id by passing it back as the selected address.
|
|
54
|
+
if entry_id && !entry_id.empty?
|
|
55
|
+
lookup.selected = entry_id
|
|
56
|
+
suggestions = client.send(lookup)
|
|
57
|
+
|
|
58
|
+
puts
|
|
59
|
+
puts '*** Secondaries ***'
|
|
60
|
+
puts
|
|
61
|
+
|
|
62
|
+
suggestions.each do |suggestion|
|
|
63
|
+
puts "#{suggestion.street_line} #{suggestion.city}, #{suggestion.state}"
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
USAutocompleteExample.new.run
|
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
require '../lib/smartystreets_ruby_sdk/shared_credentials'
|
|
2
2
|
require '../lib/smartystreets_ruby_sdk/static_credentials'
|
|
3
|
+
require '../lib/smartystreets_ruby_sdk/basic_auth_credentials'
|
|
3
4
|
require '../lib/smartystreets_ruby_sdk/client_builder'
|
|
4
5
|
require '../lib/smartystreets_ruby_sdk/us_autocomplete_pro/lookup'
|
|
6
|
+
require '../lib/smartystreets_ruby_sdk/us_autocomplete_pro/source_type'
|
|
5
7
|
|
|
6
8
|
class USAutocompleteProExample
|
|
7
9
|
Lookup = SmartyStreets::USAutocompletePro::Lookup
|
|
10
|
+
SourceType = SmartyStreets::USAutocompletePro::SourceType
|
|
8
11
|
|
|
9
12
|
def run
|
|
10
13
|
# key = 'Your SmartyStreets Auth Key here'
|
|
11
14
|
# referer = 'Your host name here'
|
|
12
15
|
# We recommend storing your secret keys in environment variables instead---it's safer!
|
|
13
|
-
key = ENV['SMARTY_AUTH_WEB']
|
|
14
|
-
referer = ENV['SMARTY_AUTH_REFERER']
|
|
15
|
-
credentials = SmartyStreets::SharedCredentials.new(key, referer)
|
|
16
|
+
# key = ENV['SMARTY_AUTH_WEB']
|
|
17
|
+
# referer = ENV['SMARTY_AUTH_REFERER']
|
|
18
|
+
# credentials = SmartyStreets::SharedCredentials.new(key, referer)
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
# auth_id = ENV['SMARTY_AUTH_ID']
|
|
22
|
-
# auth_token = ENV['SMARTY_AUTH_TOKEN']
|
|
23
|
-
#
|
|
24
|
-
# credentials = SmartyStreets::StaticCredentials.new(auth_id, auth_token)
|
|
20
|
+
id = ENV['SMARTY_AUTH_ID']
|
|
21
|
+
token = ENV['SMARTY_AUTH_TOKEN']
|
|
22
|
+
credentials = SmartyStreets::BasicAuthCredentials.new(id, token)
|
|
25
23
|
|
|
26
24
|
client = SmartyStreets::ClientBuilder.new(credentials).build_us_autocomplete_pro_api_client
|
|
27
25
|
|
|
@@ -33,7 +31,7 @@ class USAutocompleteProExample
|
|
|
33
31
|
lookup.add_city_filter('Orem,UT')
|
|
34
32
|
lookup.max_results = 5
|
|
35
33
|
lookup.prefer_ratio = 3
|
|
36
|
-
lookup.source =
|
|
34
|
+
lookup.source = SourceType::ALL
|
|
37
35
|
|
|
38
36
|
# lookup.add_custom_parameter('parameter', 'value')
|
|
39
37
|
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
require '../lib/smartystreets_ruby_sdk/static_credentials'
|
|
2
|
+
require '../lib/smartystreets_ruby_sdk/shared_credentials'
|
|
3
|
+
require '../lib/smartystreets_ruby_sdk/basic_auth_credentials'
|
|
4
|
+
require '../lib/smartystreets_ruby_sdk/client_builder'
|
|
5
|
+
require '../lib/smartystreets_ruby_sdk/us_enrichment/lookup'
|
|
6
|
+
|
|
7
|
+
class USEnrichmentBusinessExample
|
|
8
|
+
def run
|
|
9
|
+
id = ENV['SMARTY_AUTH_ID']
|
|
10
|
+
token = ENV['SMARTY_AUTH_TOKEN']
|
|
11
|
+
credentials = SmartyStreets::BasicAuthCredentials.new(id, token)
|
|
12
|
+
|
|
13
|
+
client = SmartyStreets::ClientBuilder.new(credentials).build_us_enrichment_api_client
|
|
14
|
+
|
|
15
|
+
smarty_key = "1962995076"
|
|
16
|
+
|
|
17
|
+
begin
|
|
18
|
+
summary_results = client.send_business_lookup(smarty_key)
|
|
19
|
+
rescue SmartyStreets::SmartyError => err
|
|
20
|
+
puts err
|
|
21
|
+
return
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
if summary_results.nil? || summary_results.empty?
|
|
25
|
+
puts "No response returned for SmartyKey #{smarty_key}"
|
|
26
|
+
return
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
summary = summary_results[0]
|
|
30
|
+
if summary.businesses.nil? || summary.businesses.empty?
|
|
31
|
+
puts "SmartyKey #{smarty_key} has no business tenants"
|
|
32
|
+
return
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
puts "Summary results for SmartyKey: #{smarty_key}"
|
|
36
|
+
summary.businesses.each do |biz|
|
|
37
|
+
puts " - #{biz.company_name} (ID: #{biz.business_id})"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
first = summary.businesses[0]
|
|
41
|
+
puts
|
|
42
|
+
puts "Fetching details for business: #{first.company_name} (ID: #{first.business_id})"
|
|
43
|
+
|
|
44
|
+
begin
|
|
45
|
+
detail_result = client.send_business_detail_lookup(first.business_id)
|
|
46
|
+
rescue SmartyStreets::SmartyError => err
|
|
47
|
+
puts err
|
|
48
|
+
return
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
if detail_result.nil?
|
|
52
|
+
puts "No detail result returned"
|
|
53
|
+
return
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
puts
|
|
57
|
+
puts "Detail result:"
|
|
58
|
+
puts " smarty_key: #{detail_result.smarty_key}"
|
|
59
|
+
puts " data_set_name: #{detail_result.data_set_name}"
|
|
60
|
+
puts " business_id: #{detail_result.business_id}"
|
|
61
|
+
attrs = detail_result.attributes
|
|
62
|
+
return if attrs.nil?
|
|
63
|
+
attrs.instance_variables.each do |var|
|
|
64
|
+
value = attrs.instance_variable_get(var)
|
|
65
|
+
next if value.nil?
|
|
66
|
+
puts " #{var.to_s.delete('@')}: #{value}"
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
example = USEnrichmentBusinessExample.new
|
|
72
|
+
example.run
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
require '../lib/smartystreets_ruby_sdk/static_credentials'
|
|
2
|
+
require '../lib/smartystreets_ruby_sdk/shared_credentials'
|
|
3
|
+
require '../lib/smartystreets_ruby_sdk/basic_auth_credentials'
|
|
4
|
+
require '../lib/smartystreets_ruby_sdk/client_builder'
|
|
5
|
+
require '../lib/smartystreets_ruby_sdk/us_enrichment/lookup'
|
|
6
|
+
|
|
7
|
+
class USEnrichmentBusinessNameSearchExample
|
|
8
|
+
def run
|
|
9
|
+
id = ENV['SMARTY_AUTH_ID']
|
|
10
|
+
token = ENV['SMARTY_AUTH_TOKEN']
|
|
11
|
+
credentials = SmartyStreets::BasicAuthCredentials.new(id, token)
|
|
12
|
+
|
|
13
|
+
client = SmartyStreets::ClientBuilder.new(credentials).build_us_enrichment_api_client
|
|
14
|
+
|
|
15
|
+
business_name = "delta air"
|
|
16
|
+
|
|
17
|
+
lookup = SmartyStreets::USEnrichment::Lookup.new
|
|
18
|
+
lookup.business_name = business_name
|
|
19
|
+
lookup.city = "atlanta"
|
|
20
|
+
|
|
21
|
+
begin
|
|
22
|
+
summary_results = client.send_business_lookup(lookup)
|
|
23
|
+
rescue SmartyStreets::SmartyError => err
|
|
24
|
+
puts err
|
|
25
|
+
return
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
if summary_results.nil? || summary_results.empty?
|
|
29
|
+
puts "No response returned for business-name search"
|
|
30
|
+
return
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
summary = summary_results[0]
|
|
34
|
+
if summary.businesses.nil? || summary.businesses.empty?
|
|
35
|
+
puts "No businesses found for this business name search"
|
|
36
|
+
return
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
puts "Summary results for BusinessName: #{business_name}"
|
|
40
|
+
summary.businesses.each do |biz|
|
|
41
|
+
puts " - #{biz.company_name} (ID: #{biz.business_id})"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
first = summary.businesses[0]
|
|
45
|
+
puts
|
|
46
|
+
puts "Fetching details for business: #{first.company_name} (ID: #{first.business_id})"
|
|
47
|
+
|
|
48
|
+
begin
|
|
49
|
+
detail_result = client.send_business_detail_lookup(first.business_id)
|
|
50
|
+
rescue SmartyStreets::SmartyError => err
|
|
51
|
+
puts err
|
|
52
|
+
return
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
if detail_result.nil?
|
|
56
|
+
puts "No detail result returned"
|
|
57
|
+
return
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
puts
|
|
61
|
+
puts "Detail result:"
|
|
62
|
+
puts " smarty_key: #{detail_result.smarty_key}"
|
|
63
|
+
puts " data_set_name: #{detail_result.data_set_name}"
|
|
64
|
+
puts " business_id: #{detail_result.business_id}"
|
|
65
|
+
attrs = detail_result.attributes
|
|
66
|
+
return if attrs.nil?
|
|
67
|
+
attrs.instance_variables.each do |var|
|
|
68
|
+
value = attrs.instance_variable_get(var)
|
|
69
|
+
next if value.nil?
|
|
70
|
+
puts " #{var.to_s.delete('@')}: #{value}"
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
example = USEnrichmentBusinessNameSearchExample.new
|
|
76
|
+
example.run
|