smartystreets_ruby_sdk 3.0.0 → 3.1.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.
data/Makefile CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/make -f
2
2
 
3
- SOURCE_VERSION := 3.0
3
+ SOURCE_VERSION := 3.1
4
4
 
5
5
  tests:
6
6
  ruby -Ilib -e 'ARGV.each { |f| require f }' ./test/smartystreets_ruby_sdk/test*.rb ./test/smartystreets_ruby_sdk/us_street/test*.rb ./test/smartystreets_ruby_sdk/us_zipcode/test*.rb
data/README.md CHANGED
@@ -6,6 +6,12 @@ You may have noticed this page is curiously sparse. Don't panic, there's [docume
6
6
 
7
7
  [Apache 2.0 License](LICENSE.txt)
8
8
 
9
+ ---
10
+
11
+ [![asciicast](https://asciinema.org/a/122129.png)](https://asciinema.org/a/122129)
12
+
13
+ ---
14
+
9
15
  ## Installation
10
16
 
11
17
  Add this line to your application's Gemfile:
@@ -20,8 +26,7 @@ And then execute:
20
26
 
21
27
  Or install it yourself as:
22
28
 
23
- $ gem install smartystreets_ruby_sdk
24
-
29
+ $ gem install smartystreets_ruby_sdk
25
30
 
26
31
 
27
32
 
@@ -27,8 +27,9 @@ class ClientBuilder
27
27
  @serializer = NativeSerializer.new
28
28
  @http_sender = nil
29
29
  @max_retries = 5
30
- @max_timeout = 10000
30
+ @max_timeout = 10_000
31
31
  @url_prefix = nil
32
+ @proxy = nil
32
33
  end
33
34
 
34
35
  # Sets the maximum number of times to retry sending the request to the API. (Default is 5)
@@ -73,6 +74,15 @@ class ClientBuilder
73
74
  self
74
75
  end
75
76
 
77
+ # Assigns a proxy through which all requests will be sent.
78
+ # proxy is a Proxy object from this module.
79
+ #
80
+ # Returns self to accommodate method chaining.
81
+ def with_proxy(proxy)
82
+ @proxy = proxy
83
+ self
84
+ end
85
+
76
86
  def build_international_street_api_client
77
87
  ensure_url_prefix_not_null(INTERNATIONAL_STREET_API_URL)
78
88
  InternationalStreet::Client.new(build_sender, @serializer)
@@ -101,7 +111,7 @@ class ClientBuilder
101
111
  def build_sender
102
112
  return @http_sender unless @http_sender.nil?
103
113
 
104
- sender = NativeSender.new(@max_timeout)
114
+ sender = NativeSender.new(@max_timeout, @proxy)
105
115
 
106
116
  sender = StatusCodeSender.new(sender)
107
117
 
@@ -3,16 +3,16 @@ require_relative 'version'
3
3
  require_relative 'response'
4
4
 
5
5
  class NativeSender
6
- def initialize(max_timeout=10000)
6
+ def initialize(max_timeout = 10_000, proxy = nil)
7
7
  @max_timeout = max_timeout
8
+ @proxy = proxy
8
9
  end
9
10
 
10
11
  def send(smarty_request)
11
12
  request = self.class.build_request(smarty_request)
12
- uri = request.uri
13
13
 
14
14
  begin
15
- http = Net::HTTP.new(uri.hostname, uri.port)
15
+ http = build_http(request)
16
16
  http.use_ssl = true
17
17
  http.ssl_version = :TLSv1_2
18
18
  http.read_timeout = @max_timeout
@@ -20,7 +20,7 @@ class NativeSender
20
20
  response = http.request(request)
21
21
 
22
22
  http.finish if http.started?
23
- rescue Exception => err
23
+ rescue StandardError => err
24
24
  return Response.new(nil, nil, err)
25
25
  end
26
26
 
@@ -29,11 +29,13 @@ class NativeSender
29
29
 
30
30
  def self.build_request(smarty_request)
31
31
  query = create_query(smarty_request)
32
+
32
33
  if smarty_request.payload.nil?
33
34
  request = Net::HTTP::Get.new(URI.parse("#{smarty_request.url_prefix}?#{query}"))
34
35
  else
35
36
  request = Net::HTTP::Post.new(URI.parse("#{smarty_request.url_prefix}?#{query}"))
36
37
  end
38
+
37
39
  request.content_type = 'application/json'
38
40
  request.body = smarty_request.payload
39
41
  request['User-Agent'] = "smartystreets (sdk:ruby@#{SmartystreetsRubySdk::VERSION})"
@@ -46,6 +48,19 @@ class NativeSender
46
48
  Response.new(native_response.body, native_response.code)
47
49
  end
48
50
 
51
+ def build_http(request)
52
+ uri = request.uri
53
+
54
+ if @proxy.nil?
55
+ http = Net::HTTP.new(uri.hostname, uri.port)
56
+ else
57
+ http = Net::HTTP.new(uri.hostname, uri.port, @proxy.host,
58
+ @proxy.port, @proxy.username, @proxy.password)
59
+ end
60
+
61
+ http
62
+ end
63
+
49
64
  def self.create_query(smarty_request)
50
65
  query_string = ''
51
66
 
@@ -0,0 +1,16 @@
1
+ module SmartystreetsRubySdk
2
+ # Contains information about the proxy through which all requests will be sent.
3
+ #
4
+ # host should not include a scheme
5
+ class Proxy
6
+
7
+ attr_accessor :port, :host, :username, :password
8
+
9
+ def initialize(host, port, username = nil, password = nil)
10
+ @host = host
11
+ @port = port
12
+ @username = username
13
+ @password = password
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module SmartystreetsRubySdk
2
- VERSION = '3.0.0' # DO NOT EDIT (this is updated by a build job when a new release is published)
2
+ VERSION = '3.1.0' # DO NOT EDIT (this is updated by a build job when a new release is published)
3
3
  end
@@ -0,0 +1,366 @@
1
+ {
2
+ "version": 1,
3
+ "width": 100,
4
+ "height": 45,
5
+ "duration": 25.40302,
6
+ "command": null,
7
+ "title": null,
8
+ "env": {
9
+ "TERM": "xterm-256color",
10
+ "SHELL": "/bin/bash"
11
+ },
12
+ "stdout": [
13
+ [
14
+ 0.000875,
15
+ "\u001b[?1034hbash-3.2$ "
16
+ ],
17
+ [
18
+ 1.0,
19
+ "g"
20
+ ],
21
+ [
22
+ 0.096613,
23
+ "e"
24
+ ],
25
+ [
26
+ 0.199543,
27
+ "m"
28
+ ],
29
+ [
30
+ 0.120305,
31
+ " "
32
+ ],
33
+ [
34
+ 0.360287,
35
+ "i"
36
+ ],
37
+ [
38
+ 0.167696,
39
+ "n"
40
+ ],
41
+ [
42
+ 0.119548,
43
+ "s"
44
+ ],
45
+ [
46
+ 0.143402,
47
+ "t"
48
+ ],
49
+ [
50
+ 0.096943,
51
+ "a"
52
+ ],
53
+ [
54
+ 0.159451,
55
+ "l"
56
+ ],
57
+ [
58
+ 0.152755,
59
+ "l"
60
+ ],
61
+ [
62
+ 0.472194,
63
+ " "
64
+ ],
65
+ [
66
+ 0.415625,
67
+ "s"
68
+ ],
69
+ [
70
+ 0.128058,
71
+ "m"
72
+ ],
73
+ [
74
+ 0.136152,
75
+ "a"
76
+ ],
77
+ [
78
+ 0.263332,
79
+ "r"
80
+ ],
81
+ [
82
+ 0.224605,
83
+ "t"
84
+ ],
85
+ [
86
+ 0.44166,
87
+ "y"
88
+ ],
89
+ [
90
+ 0.254094,
91
+ "s"
92
+ ],
93
+ [
94
+ 0.127964,
95
+ "t"
96
+ ],
97
+ [
98
+ 0.112037,
99
+ "r"
100
+ ],
101
+ [
102
+ 0.256337,
103
+ "e"
104
+ ],
105
+ [
106
+ 0.135907,
107
+ "e"
108
+ ],
109
+ [
110
+ 0.271188,
111
+ "t"
112
+ ],
113
+ [
114
+ 0.096752,
115
+ "s"
116
+ ],
117
+ [
118
+ 0.543902,
119
+ "_"
120
+ ],
121
+ [
122
+ 0.303509,
123
+ "r"
124
+ ],
125
+ [
126
+ 0.208053,
127
+ "u"
128
+ ],
129
+ [
130
+ 0.248442,
131
+ "b"
132
+ ],
133
+ [
134
+ 0.263945,
135
+ "y"
136
+ ],
137
+ [
138
+ 0.472192,
139
+ "_"
140
+ ],
141
+ [
142
+ 0.583879,
143
+ "s"
144
+ ],
145
+ [
146
+ 0.136072,
147
+ "d"
148
+ ],
149
+ [
150
+ 0.335389,
151
+ "k"
152
+ ],
153
+ [
154
+ 0.711499,
155
+ "\r\n"
156
+ ],
157
+ [
158
+ 0.622611,
159
+ "Successfully installed smartystreets_ruby_sdk-3.0.0\r\n"
160
+ ],
161
+ [
162
+ 0.112475,
163
+ "Parsing documentation for smartystreets_ruby_sdk-3.0.0\r\n"
164
+ ],
165
+ [
166
+ 0.233239,
167
+ "Installing ri documentation for smartystreets_ruby_sdk-3.0.0\r\n"
168
+ ],
169
+ [
170
+ 0.076259,
171
+ "Done installing documentation for smartystreets_ruby_sdk after 0 seconds\r\n1 gem installed\r\n"
172
+ ],
173
+ [
174
+ 0.011916,
175
+ "bash-3.2$ "
176
+ ],
177
+ [
178
+ 1.0,
179
+ "\r\n"
180
+ ],
181
+ [
182
+ 4e-05,
183
+ "bash-3.2$ "
184
+ ],
185
+ [
186
+ 0.144236,
187
+ "\r\n"
188
+ ],
189
+ [
190
+ 3.9e-05,
191
+ "bash-3.2$ "
192
+ ],
193
+ [
194
+ 0.305081,
195
+ "c"
196
+ ],
197
+ [
198
+ 0.103617,
199
+ "a"
200
+ ],
201
+ [
202
+ 0.287387,
203
+ "t"
204
+ ],
205
+ [
206
+ 0.960198,
207
+ " "
208
+ ],
209
+ [
210
+ 1.0,
211
+ "e"
212
+ ],
213
+ [
214
+ 0.503401,
215
+ "x"
216
+ ],
217
+ [
218
+ 0.144016,
219
+ "a"
220
+ ],
221
+ [
222
+ 0.320538,
223
+ "m"
224
+ ],
225
+ [
226
+ 0.136119,
227
+ "p"
228
+ ],
229
+ [
230
+ 0.327256,
231
+ "l"
232
+ ],
233
+ [
234
+ 0.400419,
235
+ "e"
236
+ ],
237
+ [
238
+ 0.592251,
239
+ "."
240
+ ],
241
+ [
242
+ 0.535542,
243
+ "r"
244
+ ],
245
+ [
246
+ 0.320377,
247
+ "b"
248
+ ],
249
+ [
250
+ 0.230569,
251
+ "\r\n"
252
+ ],
253
+ [
254
+ 0.00306,
255
+ "require 'smartystreets_ruby_sdk/client_builder'\r\nrequire 'smartystreets_ruby_sdk/static_credentials'\r\nrequire 'smartystreets_ruby_sdk/us_street'\r\n\r\n\r\nclass Example\r\n def run\r\n # This keypair will have been deleted by the time you are watching this video... \r\n auth_id = 'c4df4ec8-2be0-8ccc-8762-d899ce38d1db'\r\n auth_token = 'KXb5V3XlB537Fx3XIgaa'\r\n credentials = StaticCredentials.new(auth_id, auth_token)\r\n\r\n puts 'Step 0. Wire up the client with your keypair.'\r\n client = ClientBuilder.new(credentials).build_us_street_api_client\r\n\r\n puts 'Step 1. Make a lookup. (BTW, you can also send entire batches of lookups...)'\r\n lookup = USStreet::Lookup.new\r\n lookup.street = '1 Rosedale'\r\n lookup.lastline = 'Baltimore MD'\r\n lookup.candidates = 10\r\n\r\n puts 'Step 2. Send the lookup.'\r\n client.send_lookup(lookup)\r\n\r\n puts 'Step 3. Show the resulting candidate addresses:'\r\n lookup.result.each_with_index do |candidate, c|\r\n puts \"- #{c}: #{candidate.delivery_line_1}, #{candidat"
256
+ ],
257
+ [
258
+ 3e-05,
259
+ "e.last_line}\\n\"\r\n end\r\n end\r\nend\r\n\r\nExample.new.run"
260
+ ],
261
+ [
262
+ 0.000304,
263
+ "bash-3.2$ "
264
+ ],
265
+ [
266
+ 1.0,
267
+ "\r\n"
268
+ ],
269
+ [
270
+ 2.5e-05,
271
+ "bash-3.2$ "
272
+ ],
273
+ [
274
+ 0.14381,
275
+ "\r\n"
276
+ ],
277
+ [
278
+ 6.9e-05,
279
+ "bash-3.2$ "
280
+ ],
281
+ [
282
+ 0.14446,
283
+ "\r\n"
284
+ ],
285
+ [
286
+ 3.7e-05,
287
+ "bash-3.2$ "
288
+ ],
289
+ [
290
+ 1.0,
291
+ "r"
292
+ ],
293
+ [
294
+ 0.144148,
295
+ "u"
296
+ ],
297
+ [
298
+ 0.183292,
299
+ "b"
300
+ ],
301
+ [
302
+ 0.160194,
303
+ "y"
304
+ ],
305
+ [
306
+ 0.143947,
307
+ " "
308
+ ],
309
+ [
310
+ 0.223659,
311
+ "e"
312
+ ],
313
+ [
314
+ 0.465012,
315
+ "x"
316
+ ],
317
+ [
318
+ 0.135554,
319
+ "a"
320
+ ],
321
+ [
322
+ 0.21534,
323
+ "m"
324
+ ],
325
+ [
326
+ 0.112946,
327
+ "p"
328
+ ],
329
+ [
330
+ 0.217044,
331
+ "l"
332
+ ],
333
+ [
334
+ 0.614323,
335
+ "e"
336
+ ],
337
+ [
338
+ 0.648622,
339
+ "."
340
+ ],
341
+ [
342
+ 0.399935,
343
+ "r"
344
+ ],
345
+ [
346
+ 0.271424,
347
+ "b"
348
+ ],
349
+ [
350
+ 0.687326,
351
+ "\r\n"
352
+ ],
353
+ [
354
+ 0.072413,
355
+ "Step 0. Wire up the client with your keypair.\r\nStep 1. Make a lookup. (BTW, you can also send entire batches of lookups...)\r\nStep 2. Send the lookup.\r\n"
356
+ ],
357
+ [
358
+ 0.248917,
359
+ "Step 3. Show the resulting candidate addresses:\r\n- 0: 1 N Rosedale St, Baltimore MD 21229-3737\r\n- 1: 1 S Rosedale St, Baltimore MD 21229-3739\r\n"
360
+ ],
361
+ [
362
+ 0.007523,
363
+ "bash-3.2$ "
364
+ ]
365
+ ]
366
+ }
metadata CHANGED
@@ -1,75 +1,84 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartystreets_ruby_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - SmartyStreets SDK Team
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2017-04-28 00:00:00.000000000 Z
12
+ date: 2017-06-02 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - "~>"
19
+ - - ~>
18
20
  - !ruby/object:Gem::Version
19
21
  version: '1.13'
20
22
  type: :development
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - "~>"
27
+ - - ~>
25
28
  - !ruby/object:Gem::Version
26
29
  version: '1.13'
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: rake
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - "~>"
35
+ - - ~>
32
36
  - !ruby/object:Gem::Version
33
37
  version: '10.0'
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - "~>"
43
+ - - ~>
39
44
  - !ruby/object:Gem::Version
40
45
  version: '10.0'
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: minitest
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
- - - "~>"
51
+ - - ~>
46
52
  - !ruby/object:Gem::Version
47
53
  version: '5.8'
48
- - - ">="
54
+ - - ! '>='
49
55
  - !ruby/object:Gem::Version
50
56
  version: 5.8.3
51
57
  type: :development
52
58
  prerelease: false
53
59
  version_requirements: !ruby/object:Gem::Requirement
60
+ none: false
54
61
  requirements:
55
- - - "~>"
62
+ - - ~>
56
63
  - !ruby/object:Gem::Version
57
64
  version: '5.8'
58
- - - ">="
65
+ - - ! '>='
59
66
  - !ruby/object:Gem::Version
60
67
  version: 5.8.3
61
68
  - !ruby/object:Gem::Dependency
62
69
  name: simplecov
63
70
  requirement: !ruby/object:Gem::Requirement
71
+ none: false
64
72
  requirements:
65
- - - "~>"
73
+ - - ~>
66
74
  - !ruby/object:Gem::Version
67
75
  version: 0.12.0
68
76
  type: :development
69
77
  prerelease: false
70
78
  version_requirements: !ruby/object:Gem::Requirement
79
+ none: false
71
80
  requirements:
72
- - - "~>"
81
+ - - ~>
73
82
  - !ruby/object:Gem::Version
74
83
  version: 0.12.0
75
84
  description:
@@ -79,7 +88,7 @@ executables: []
79
88
  extensions: []
80
89
  extra_rdoc_files: []
81
90
  files:
82
- - ".gitignore"
91
+ - .gitignore
83
92
  - Gemfile
84
93
  - LICENSE.txt
85
94
  - Makefile
@@ -113,6 +122,7 @@ files:
113
122
  - lib/smartystreets_ruby_sdk/logger.rb
114
123
  - lib/smartystreets_ruby_sdk/native_sender.rb
115
124
  - lib/smartystreets_ruby_sdk/native_serializer.rb
125
+ - lib/smartystreets_ruby_sdk/proxy.rb
116
126
  - lib/smartystreets_ruby_sdk/request.rb
117
127
  - lib/smartystreets_ruby_sdk/response.rb
118
128
  - lib/smartystreets_ruby_sdk/retry_sender.rb
@@ -149,29 +159,31 @@ files:
149
159
  - lib/smartystreets_ruby_sdk/us_zipcode/result.rb
150
160
  - lib/smartystreets_ruby_sdk/us_zipcode/zip_code.rb
151
161
  - lib/smartystreets_ruby_sdk/version.rb
162
+ - ruby-sdk-demo.json
152
163
  - smartystreets_ruby_sdk.gemspec
153
164
  homepage: https://github.com/smartystreets/smartystreets-ruby-sdk
154
165
  licenses:
155
166
  - Apache-2.0
156
- metadata: {}
157
167
  post_install_message:
158
168
  rdoc_options: []
159
169
  require_paths:
160
170
  - lib
161
171
  required_ruby_version: !ruby/object:Gem::Requirement
172
+ none: false
162
173
  requirements:
163
- - - ">="
174
+ - - ! '>='
164
175
  - !ruby/object:Gem::Version
165
176
  version: '0'
166
177
  required_rubygems_version: !ruby/object:Gem::Requirement
178
+ none: false
167
179
  requirements:
168
- - - ">="
180
+ - - ! '>='
169
181
  - !ruby/object:Gem::Version
170
182
  version: '0'
171
183
  requirements: []
172
184
  rubyforge_project:
173
- rubygems_version: 2.5.1
185
+ rubygems_version: 1.8.23
174
186
  signing_key:
175
- specification_version: 4
187
+ specification_version: 3
176
188
  summary: An official library for the SmartyStreets APIs
177
189
  test_files: []
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 64962ee9e3575877e78359805f3a0aad0bb6ab33
4
- data.tar.gz: a7fe26f68f4dc756ae3955aca126fba7c4c3f0c4
5
- SHA512:
6
- metadata.gz: 5aeb2e1c9161f295dd43400ae198147e357628740c6432c1ee25f28e51d4d89fcf79c4533f89d720bdfc4ec0d1a1cc1cee5d1e6c122fac49c22d67f66bcf18bf
7
- data.tar.gz: dc7caf151400097419930d2b8009b6fa7e8b94eef69000c3d0f5287cc4a5266c36f7d78993f6e44efd20205defaf81257d92e31ee01788d0f12c755201637cbb