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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: a5a4cbefe11b18791ae311d7f78bf3c74a9ae0ff05857d36e775f1341128fb75
4
- data.tar.gz: 0bd00361cee6dd7428cf8c0edd375cc7fa9a308c679340197c838827addd0413
2
+ SHA1:
3
+ metadata.gz: 06e2310024c72482dc0038e5cdd34585b1785c3f
4
+ data.tar.gz: 40495a70b76067b52485cbb8212fb61056bac537
5
5
  SHA512:
6
- metadata.gz: bc4f3a3e49f8a8cf856857cbe08526c0f2ef3205b60669c83fa3f4fc486f5d50d01491a28adcc507aab11904fb139d4ca77bf608f80e7ce3ace743169462e5f3
7
- data.tar.gz: 4277f3287956cd54754fd2a33c291b7615f8a6651100adfcb5c3bf47dbb693372bbcc75e41f03857a7483a8500d7ada2b18c875c0df45db554edd2869df9fe18
6
+ metadata.gz: 14ed487aeeba73664aa271b85672e28058dec66d3fac29972e2030e16c4b1237db046733c7d87f2f60f8887d8b665fabd0f5c6c66accbd5be577ad03d92af461
7
+ data.tar.gz: bfe3fadf0b7a177b529453754efde3a641f6b4c50cb58612aeac4b4d75a8421367d00bb953c62ab721da286dc0200896d3967289dbcb6f28ef2b93ad118f909d
data/.gitignore CHANGED
@@ -1,4 +1,3 @@
1
1
  *.lock
2
2
  .idea
3
3
  coverage
4
- *.gem
@@ -187,7 +187,7 @@
187
187
  same "printed page" as the copyright notice for easier
188
188
  identification within third-party archives.
189
189
 
190
- Copyright Smarty
190
+ Copyright SmartyStreets
191
191
 
192
192
  Licensed under the Apache License, Version 2.0 (the "License");
193
193
  you may not use this file except in compliance with the License.
data/Makefile CHANGED
@@ -1,33 +1,19 @@
1
1
  #!/usr/bin/make -f
2
2
 
3
- VERSION := $(shell tagit -p --dry-run)
4
- VERSION_FILE := lib/smartystreets_ruby_sdk/version.rb
5
-
6
- clean:
7
- rm -f *.gem
8
- git checkout "$(VERSION_FILE)"
9
-
10
- test:
11
- rake test
12
-
13
- dependencies:
14
- gem install minitest
15
-
16
- package: clean dependencies test
17
- sed -i "s/0\.0\.0/$(VERSION)/g" "$(VERSION_FILE)" \
18
- && gem build *.gemspec \
19
- && git checkout "$(VERSION_FILE)"
20
-
21
- publish: package
22
- chmod 0600 /root/.gem/credentials
23
- gem push *.gem
24
-
25
- #####################################################################
26
-
27
- workspace:
28
- docker-compose run sdk /bin/sh
29
-
30
- release:
31
- docker-compose run sdk make publish && tagit -p && git push origin --tags
32
-
33
- .PHONY: clean test dependencies package publish workspace release
3
+ SOURCE_VERSION := 1.0
4
+
5
+ publish: version
6
+ git push origin --tags
7
+ gem build smartystreets_ruby_sdk.gemspec
8
+ gem push smartystreets_ruby_sdk-$(shell git describe).gem
9
+ git checkout lib/smartystreets_ruby_sdk/version.rb
10
+
11
+ version: tag
12
+ @sed -i -r "s/0\.0\.0/$(shell git describe)/g" lib/smartystreets_ruby_sdk/version.rb
13
+
14
+ tag:
15
+ $(eval PREFIX := $(SOURCE_VERSION).)
16
+ $(eval CURRENT := $(shell git describe 2>/dev/null))
17
+ $(eval EXPECTED := $(PREFIX)$(shell git tag -l "$(PREFIX)*" | wc -l | xargs expr -1 +))
18
+ $(eval INCREMENTED := $(PREFIX)$(shell git tag -l "$(PREFIX)*" | wc -l | xargs expr 0 +))
19
+ @if [ "$(CURRENT)" != "$(EXPECTED)" ]; then git tag -a "$(INCREMENTED)" -m "" 2>/dev/null || true; fi
data/README.md CHANGED
@@ -1,5 +1,3 @@
1
- # SMARTY DISCLAIMER: Subject to the terms of the associated license agreement, this software is freely available for your use. This software is FREE, AS IN PUPPIES, and is a gift. Enjoy your new responsibility. This means that while we may consider enhancement requests, we may or may not choose to entertain requests at our sole and absolute discretion.
2
-
3
1
  # SmartyStreets Ruby SDK
4
2
 
5
3
  The official client libraries for accessing SmartyStreets APIs from Ruby
@@ -8,12 +6,6 @@ You may have noticed this page is curiously sparse. Don't panic, there's [docume
8
6
 
9
7
  [Apache 2.0 License](LICENSE.txt)
10
8
 
11
- ---
12
-
13
- [![asciicast](https://asciinema.org/a/124457.png)](https://asciinema.org/a/124457)
14
-
15
- ---
16
-
17
9
  ## Installation
18
10
 
19
11
  Add this line to your application's Gemfile:
@@ -28,4 +20,9 @@ And then execute:
28
20
 
29
21
  Or install it yourself as:
30
22
 
31
- $ gem install smartystreets_ruby_sdk
23
+ $ gem install smartystreets_ruby_sdk
24
+
25
+
26
+
27
+
28
+
data/Rakefile CHANGED
@@ -1,5 +1,2 @@
1
- require 'rake/testtask'
2
-
3
- Rake::TestTask.new do |t|
4
- t.pattern = 'test/**/test_*.rb'
5
- end
1
+ require 'bundler/gem_tasks'
2
+ task :default => :spec
@@ -1,77 +1,52 @@
1
1
  require 'smartystreets_ruby_sdk/static_credentials'
2
- require 'smartystreets_ruby_sdk/client_builder'
3
- require 'smartystreets_ruby_sdk/batch'
2
+ require 'smartystreets_ruby_sdk/us_street/client_builder'
4
3
  require 'smartystreets_ruby_sdk/us_street/lookup'
5
4
 
6
5
  class USStreetMultipleAddressExample
7
- Lookup = SmartyStreets::USStreet::Lookup
8
-
9
6
  def run
10
- # auth_id = 'Your SmartyStreets Auth ID here'
11
- # auth_token = 'Your SmartyStreets Auth Token here'
12
-
13
- # We recommend storing your secret keys in environment variables instead---it's safer!
14
- auth_id = ENV['SMARTY_AUTH_ID']
7
+ auth_id = ENV['SMARTY_AUTH_ID'] # We recommend storing your keys in environment variables
15
8
  auth_token = ENV['SMARTY_AUTH_TOKEN']
9
+ credentials = StaticCredentials.new(auth_id, auth_token)
16
10
 
17
- credentials = SmartyStreets::StaticCredentials.new(auth_id, auth_token)
18
-
19
- # The appropriate license values to be used for your subscriptions
20
- # can be found on the Subscriptions page of the account dashboard.
21
- # https://www.smartystreets.com/docs/cloud/licensing
22
- client = SmartyStreets::ClientBuilder.new(credentials).with_licenses(['us-core-cloud'])
23
- .build_us_street_api_client
24
- batch = SmartyStreets::Batch.new
25
-
26
- # Documentation for input fields can be found at:
27
- # https://smartystreets.com/docs/cloud/us-street-api
11
+ client = USStreet::ClientBuilder.new(credentials).build
12
+ batch = Batch.new
28
13
 
29
- batch.add(Lookup.new)
30
- batch[0].input_id = '8675309' # Optional ID from your system
31
- batch[0].addressee = 'John Doe'
14
+ batch.add(USStreet::Lookup.new)
32
15
  batch[0].street = '1600 amphitheatre parkway'
33
- batch[0].street2 = 'second star to the right'
34
- batch[0].secondary = 'APT 2'
35
- batch[0].urbanization = '' # Only applies to Puerto Rico addresses
36
- batch[0].lastline = 'Mountain view, California'
37
- batch[0].zipcode = '21229'
38
- batch[0].candidates = 3
39
- batch[0].match = Lookup.INVALID # "invalid" is the most permissive match,
40
- # this will always return at least one result even if the address is invalid.
41
- # Refer to the documentation for additional Match Strategy options.
16
+ batch[0].city = 'Mountain view'
17
+ batch[0].state = 'california'
42
18
 
43
- batch.add(Lookup.new('1 Rosedale, Baltimore, Maryland')) # Freeform addresses work too.
19
+ batch.add(USStreet::Lookup.new('1 Rosedale, Baltimore, Maryland')) # Freeform addresses work too.
44
20
  batch[1].candidates = 10 # Allows up to ten possible matches to be returned (default is 1).
45
21
 
46
- batch.add(Lookup.new('123 Bogus Street, Pretend Lake, Oklahoma'))
22
+ batch.add(USStreet::Lookup.new('123 Bogus Street, Pretend Lake, Oklahoma'))
47
23
 
48
- batch.add(Lookup.new)
24
+ batch.add(USStreet::Lookup.new)
49
25
  batch[3].street = '1 Infinite Loop'
50
26
  batch[3].zipcode = '95014' # You can just input the street and ZIP if you want.
51
27
 
52
28
  begin
53
29
  client.send_batch(batch)
54
- rescue SmartyStreets::SmartyError => err
55
- puts err
30
+ rescue SmartyException => err
31
+ print(err)
56
32
  return
57
33
  end
58
34
 
59
35
  batch.each_with_index do |lookup, i|
60
36
  candidates = lookup.result
61
37
 
62
- if candidates.empty?
38
+ if candidates.length == 0
63
39
  puts "Address #{i} is invalid.\n\n"
64
40
  next
65
41
  end
66
42
 
67
- puts "Address #{i} has at least one candidate.\n If the match parameter is set to STRICT, the address is valid.\n Otherwise, check the Analysis output fields to see if the address is valid."
43
+ puts "Address #{i} is valid. (There is at least one candidate)"
68
44
 
69
45
  candidates.each do |candidate|
70
46
  components = candidate.components
71
47
  metadata = candidate.metadata
72
48
 
73
49
  puts "\nCandidate #{candidate.candidate_index} : "
74
- puts "Input ID: #{candidate.input_id}"
75
50
  puts "Delivery line 1: #{candidate.delivery_line_1}"
76
51
  puts "Last line: #{candidate.last_line}"
77
52
  puts "ZIP Code: #{components.zipcode}-#{components.plus4_code}"
@@ -1,61 +1,37 @@
1
1
  require 'smartystreets_ruby_sdk/static_credentials'
2
- require 'smartystreets_ruby_sdk/client_builder'
2
+ require 'smartystreets_ruby_sdk/us_street/client_builder'
3
3
  require 'smartystreets_ruby_sdk/us_street/lookup'
4
4
 
5
5
  class USStreetSingleAddressExample
6
6
  def run
7
- # auth_id = 'Your SmartyStreets Auth ID here'
8
- # auth_token = 'Your SmartyStreets Auth Token here'
9
-
10
- # We recommend storing your secret keys in environment variables instead---it's safer!
11
- auth_id = ENV['SMARTY_AUTH_ID']
7
+ auth_id = ENV['SMARTY_AUTH_ID'] # We recommend storing your keys in environment variables
12
8
  auth_token = ENV['SMARTY_AUTH_TOKEN']
9
+ credentials = StaticCredentials.new(auth_id, auth_token)
13
10
 
14
- credentials = SmartyStreets::StaticCredentials.new(auth_id, auth_token)
15
-
16
- # The appropriate license values to be used for your subscriptions
17
- # can be found on the Subscriptions page of the account dashboard.
18
- # https://www.smartystreets.com/docs/cloud/licensing
19
- client = SmartyStreets::ClientBuilder.new(credentials).with_licenses(['us-core-cloud'])
20
- # with_proxy('localhost', 8080, 'proxyUser', 'proxyPassword'). # Uncomment this line to try it with a proxy
21
- build_us_street_api_client
22
-
23
- # Documentation for input fields can be found at:
24
- # https://smartystreets.com/docs/cloud/us-street-api
11
+ client = USStreet::ClientBuilder.new(credentials).build
25
12
 
26
- lookup = SmartyStreets::USStreet::Lookup.new
27
- lookup.input_id = '24601' # Optional ID from your system
28
- lookup.addressee = 'John Doe'
13
+ lookup = USStreet::Lookup.new
29
14
  lookup.street = '1600 Amphitheatre Pkwy'
30
- lookup.street2 = 'closet under the stairs'
31
- lookup.secondary = 'APT 2'
32
- lookup.urbanization = '' # Only applies to Puerto Rico addresses
33
15
  lookup.city = 'Mountain View'
34
16
  lookup.state = 'CA'
35
- lookup.zipcode = '21229'
36
- lookup.candidates = 3
37
- lookup.match = Lookup.INVALID # "invalid" is the most permissive match,
38
- # this will always return at least one result even if the address is invalid.
39
- # Refer to the documentation for additional Match Strategy options.
40
17
 
41
18
  begin
42
19
  client.send_lookup(lookup)
43
- rescue SmartyStreets::SmartyError => err
20
+ rescue SmartyException => err
44
21
  puts err
45
22
  return
46
23
  end
47
24
 
48
25
  result = lookup.result
49
26
 
50
- if result.empty?
27
+ if result == nil
51
28
  puts 'No candidates. This means the address is not valid.'
52
29
  return
53
30
  end
54
31
 
55
32
  first_candidate = result[0]
56
33
 
57
- puts "There is at least one candidate.\n If the match parameter is set to STRICT, the address is valid.\n Otherwise, check the Analysis output fields to see if the address is valid.\n"
58
- puts "Input ID: #{first_candidate.input_id}"
34
+ puts "Address is valid. (There is at least one candidate)\n"
59
35
  puts "ZIP Code: #{first_candidate.components.zipcode}"
60
36
  puts "County: #{first_candidate.metadata.county_name}"
61
37
  puts "Latitude: #{first_candidate.metadata.latitude}"
@@ -1,41 +1,29 @@
1
1
  require 'smartystreets_ruby_sdk/static_credentials'
2
- require 'smartystreets_ruby_sdk/client_builder'
3
- require 'smartystreets_ruby_sdk/batch'
2
+ require 'smartystreets_ruby_sdk/us_zipcode/client_builder'
4
3
  require 'smartystreets_ruby_sdk/us_zipcode/lookup'
5
4
 
6
5
  class USZipcodeMultipleLookupExample
7
- Lookup = SmartyStreets::USZipcode::Lookup
8
-
9
6
  def run
10
- # auth_id = 'Your SmartyStreets Auth ID here'
11
- # auth_token = 'Your SmartyStreets Auth Token here'
12
-
13
- # We recommend storing your secret keys in environment variables instead---it's safer!
14
- auth_id = ENV['SMARTY_AUTH_ID']
7
+ auth_id = ENV['SMARTY_AUTH_ID'] # We recommend storing your keys in environment variables
15
8
  auth_token = ENV['SMARTY_AUTH_TOKEN']
9
+ credentials = StaticCredentials.new(auth_id, auth_token)
16
10
 
17
- credentials = SmartyStreets::StaticCredentials.new(auth_id, auth_token)
18
-
19
- client = SmartyStreets::ClientBuilder.new(credentials).build_us_zipcode_api_client
20
- batch = SmartyStreets::Batch.new
21
-
22
- # Documentation for input fields can be found at:
23
- # https://smartystreets.com/docs/cloud/us-zipcode-api
11
+ client = USZipcode::ClientBuilder.new(credentials).build
12
+ batch = Batch.new
24
13
 
25
- batch.add(Lookup.new)
26
- batch[0].input_id = '01189998819991197253' # Optional ID from your system
14
+ batch.add(USZipcode::Lookup.new)
27
15
  batch[0].zipcode = '12345' # A Lookup may have a ZIP Code, city and state, or city, state, and ZIP Code
28
16
 
29
- batch.add(Lookup.new)
17
+ batch.add(USZipcode::Lookup.new)
30
18
  batch[1].city = 'Phoenix'
31
19
  batch[1].state = 'Arizona'
32
20
 
33
- batch.add(Lookup.new('cupertino', 'CA', '95014')) # You can also set these with arguments
21
+ batch.add(USZipcode::Lookup.new('cupertino', 'CA', '95014')) # You can also set these with arguments
34
22
 
35
23
 
36
24
  begin
37
25
  client.send_batch(batch)
38
- rescue SmartyError => err
26
+ rescue SmartyException => err
39
27
  puts err
40
28
  return
41
29
  end
@@ -1,32 +1,22 @@
1
1
  require 'smartystreets_ruby_sdk/static_credentials'
2
- require 'smartystreets_ruby_sdk/client_builder'
2
+ require 'smartystreets_ruby_sdk/us_zipcode/client_builder'
3
3
  require 'smartystreets_ruby_sdk/us_zipcode/lookup'
4
4
 
5
5
  class UsZipcodeSingleLookupExample
6
6
  def run
7
- # auth_id = 'Your SmartyStreets Auth ID here'
8
- # auth_token = 'Your SmartyStreets Auth Token here'
9
-
10
- # We recommend storing your secret keys in environment variables instead---it's safer!
11
- auth_id = ENV['SMARTY_AUTH_ID']
7
+ auth_id = ENV['SMARTY_AUTH_ID'] # We recommend storing your keys in environment variables
12
8
  auth_token = ENV['SMARTY_AUTH_TOKEN']
9
+ credentials = StaticCredentials.new(auth_id, auth_token)
13
10
 
14
- credentials = SmartyStreets::StaticCredentials.new(auth_id, auth_token)
15
-
16
- client = SmartyStreets::ClientBuilder.new(credentials).build_us_zipcode_api_client
11
+ client = USZipcode::ClientBuilder.new(credentials).build
17
12
 
18
- # Documentation for input fields can be found at:
19
- # https://smartystreets.com/docs/cloud/us-zipcode-api
20
-
21
- lookup = SmartyStreets::USZipcode::Lookup.new
22
- lookup.input_id = 'dfc33cb6-829e-4fea-aa1b-b6d6580f0817' # Optional ID from your system
13
+ lookup = USZipcode::Lookup.new
23
14
  lookup.city = 'Mountain View'
24
15
  lookup.state = 'California'
25
- lookup.zipcode = '94043'
26
16
 
27
17
  begin
28
18
  client.send_lookup(lookup)
29
- rescue SmartyStreets::SmartyError => err
19
+ rescue SmartyException => err
30
20
  puts err
31
21
  return
32
22
  end
@@ -35,8 +25,6 @@ class UsZipcodeSingleLookupExample
35
25
  zipcodes = result.zipcodes
36
26
  cities = result.cities
37
27
 
38
- puts "Input ID: #{result.input_id}"
39
-
40
28
  cities.each do |city|
41
29
  puts "\nCity: #{city.city}"
42
30
  puts "State: #{city.state}"
@@ -1,59 +1,52 @@
1
- module SmartyStreets
2
- # The Batch class is used to send up to 100 lookups at once
3
- class Batch
4
- include Enumerable
5
- MAX_BATCH_SIZE = 100
1
+ class Batch
2
+ include Enumerable
3
+ MAX_BATCH_SIZE = 100
6
4
 
7
- attr_reader :all_lookups, :named_lookups
5
+ attr_reader :all_lookups, :named_lookups
8
6
 
9
- def initialize
10
- @named_lookups = {}
11
- @all_lookups = []
12
- end
13
-
14
- def add(lookup)
15
- return false if full?
16
-
17
- @all_lookups.push(lookup)
7
+ def initialize
8
+ @named_lookups = {}
9
+ @all_lookups = []
10
+ end
18
11
 
19
- return true if lookup.input_id.nil?
12
+ def add(lookup)
13
+ return false if is_full
20
14
 
21
- @named_lookups[lookup.input_id] = lookup
22
- true
23
- end
15
+ @all_lookups.push(lookup)
24
16
 
25
- def clear
26
- @named_lookups.clear
27
- @all_lookups.clear
28
- end
17
+ return true if lookup.input_id == nil
29
18
 
30
- def full?
31
- size >= MAX_BATCH_SIZE
32
- end
19
+ @named_lookups[lookup.input_id] = lookup
20
+ true
21
+ end
33
22
 
34
- def empty?
35
- size.zero?
36
- end
23
+ def clear
24
+ @named_lookups.clear
25
+ @all_lookups.clear
26
+ end
37
27
 
38
- def size
39
- @all_lookups.length
40
- end
28
+ def is_full
29
+ size >= MAX_BATCH_SIZE
30
+ end
41
31
 
42
- def get_by_input_id(input_id)
43
- @named_lookups[input_id]
44
- end
32
+ def size
33
+ @all_lookups.length
34
+ end
45
35
 
46
- def get_by_index(index)
47
- @all_lookups[index]
48
- end
36
+ def get_by_input_id(input_id)
37
+ @named_lookups[input_id]
38
+ end
49
39
 
50
- def each(&block)
51
- @all_lookups.each(&block)
52
- end
40
+ def get_by_index(index)
41
+ @all_lookups[index]
42
+ end
53
43
 
54
- def [](index)
55
- @all_lookups[index]
56
- end
44
+ def each(&block)
45
+ @all_lookups.each(&block)
46
+ end
57
47
 
48
+ def [](index)
49
+ @all_lookups[index]
58
50
  end
59
- end
51
+
52
+ end
@@ -0,0 +1,56 @@
1
+ require_relative 'native_serializer'
2
+ require_relative 'native_sender'
3
+ require_relative 'status_code_sender'
4
+ require_relative 'signing_sender'
5
+ require_relative 'retry_sender'
6
+ require_relative 'url_prefix_sender'
7
+ require_relative 'sleeper'
8
+
9
+ class CoreClientBuilder
10
+ def initialize(signer)
11
+ @signer = signer
12
+ @serializer = NativeSerializer.new
13
+ @http_sender = nil
14
+ @max_retries = 5
15
+ @max_timeout = 10000
16
+ @url_prefix = ''
17
+ end
18
+
19
+ def retry_at_most(max_retries)
20
+ @max_retries = max_retries
21
+ self
22
+ end
23
+
24
+ def with_max_timeout(max_timeout)
25
+ @max_timeout = max_timeout
26
+ self
27
+ end
28
+
29
+ def with_serializer(serializer)
30
+ @serializer = serializer
31
+ self
32
+ end
33
+
34
+ def with_url(url_prefix)
35
+ @url_prefix = url_prefix
36
+ self
37
+ end
38
+
39
+ def build
40
+ # Implemented in child classes
41
+ end
42
+
43
+ def build_sender
44
+ return @http_sender if @http_sender != nil
45
+
46
+ sender = NativeSender.new(@max_timeout)
47
+
48
+ sender = StatusCodeSender.new(sender)
49
+
50
+ sender = SigningSender.new(@signer, sender) if @signer != nil
51
+
52
+ sender = RetrySender.new(@max_retries, sender, Sleeper.new) if @max_retries > 0
53
+
54
+ URLPrefixSender.new(@url_prefix, sender)
55
+ end
56
+ end
@@ -1,13 +1,11 @@
1
- module SmartyStreets
2
- class CustomHeaderSender
3
- def initialize(inner, headers)
4
- @inner = inner
5
- @headers = headers
6
- end
1
+ class CustomHeaderSender
2
+ def initialize(inner, headers)
3
+ @inner = inner
4
+ @headers = headers
5
+ end
7
6
 
8
- def send(request)
9
- request.headers = @headers
10
- @inner.send(request)
11
- end
7
+ def send(request)
8
+ request.headers = @headers
9
+ @inner.send(request)
12
10
  end
13
11
  end
@@ -1,27 +1,17 @@
1
- module SmartyStreets
2
- BAD_CREDENTIALS = 'Unauthorized: The credentials were provided incorrectly or did not match any existing,
3
- active credentials.'.freeze
1
+ BAD_CREDENTIALS = 'Unauthorized: The credentials were provided incorrectly or did not match any existing,
2
+ active credentials.'
4
3
 
5
- PAYMENT_REQUIRED = 'Payment Required: There is no active subscription
6
- for the account associated with the credentials submitted with the request.'.freeze
4
+ PAYMENT_REQUIRED = 'Payment Required: There is no active subscription
5
+ for the account associated with the credentials submitted with the request.'
7
6
 
8
- FORBIDDEN = 'Because the international service is currently in a limited release phase, only approved accounts' \
9
- ' may access the service.'.freeze
7
+ REQUEST_ENTITY_TOO_LARGE = 'Request Entity Too Large: The request body has exceeded the maximum size.'
10
8
 
11
- REQUEST_ENTITY_TOO_LARGE = 'Request Entity Too Large: The request body has exceeded the maximum size.'.freeze
9
+ BAD_REQUEST = 'Bad Request (Malformed Payload): A GET request lacked a street field or the request body of a
10
+ POST request contained malformed JSON.'
12
11
 
13
- BAD_REQUEST = 'Bad Request (Malformed Payload): A GET request lacked a street field or the request body of a
14
- POST request contained malformed JSON, possibly because a value was submitted as a number rather than as a string.'.freeze
12
+ TOO_MANY_REQUESTS = 'When using public "website key" authentication,
13
+ we restrict the number of requests coming from a given source over too short of a time.'
15
14
 
16
- UNPROCESSABLE_ENTITY = 'GET request lacked required fields.'.freeze
15
+ INTERNAL_SERVER_ERROR = 'Internal Server Error.'
17
16
 
18
- TOO_MANY_REQUESTS = 'When using public "website key" authentication,
19
- we restrict the number of requests coming from a given source over too short of a time.'.freeze
20
-
21
- INTERNAL_SERVER_ERROR = 'Internal Server Error.'.freeze
22
-
23
- SERVICE_UNAVAILABLE = 'Service Unavailable. Try again later.'.freeze
24
-
25
- GATEWAY_TIMEOUT = 'The upstream data provider did not respond in a timely fashion and the request failed. ' \
26
- 'A serious, yet rare occurrence indeed.'.freeze
27
- end
17
+ SERVICE_UNAVAILABLE = 'Service Unavailable. Try again later.'
@@ -1,39 +1,28 @@
1
- module SmartyStreets
2
-
3
- class SmartyError < StandardError
4
- end
1
+ class SmartyException < Exception
2
+ end
5
3
 
6
- class BadCredentialsError < SmartyError
7
- end
4
+ class BadCredentialsError < SmartyException
5
+ end
8
6
 
9
- class ForbiddenError < SmartyError
10
- end
7
+ class PaymentRequiredError < SmartyException
8
+ end
11
9
 
12
- class PaymentRequiredError < SmartyError
13
- end
14
10
 
15
- class RequestEntityTooLargeError < SmartyError
16
- end
11
+ class RequestEntityTooLargeError < SmartyException
12
+ end
17
13
 
18
- class BadRequestError < SmartyError
19
- end
20
14
 
21
- class UnprocessableEntityError < SmartyError
22
- end
15
+ class BadRequestError < SmartyException
16
+ end
23
17
 
24
- class TooManyRequestsError < SmartyError
25
- end
26
18
 
27
- class InternalServerError < SmartyError
28
- end
19
+ class TooManyRequestsError < SmartyException
20
+ end
29
21
 
30
- class ServiceUnavailableError < SmartyError
31
- end
32
22
 
33
- class GatewayTimeoutError < SmartyError
34
- end
23
+ class InternalServerError < SmartyException
24
+ end
35
25
 
36
- class BatchFullError < SmartyError
37
- end
38
26
 
39
- end
27
+ class ServiceUnavailableError < SmartyException
28
+ end