desk 1.0.9 → 1.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/desk/configuration.rb +13 -0
- data/lib/desk/connection.rb +3 -0
- data/lib/desk/version.rb +1 -1
- data/spec/desk_spec.rb +24 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42e1712d947838feea34f602ca87d2f773dba88c
|
4
|
+
data.tar.gz: 96e5918ca38eb81dd57f23ead92a21f590d99921
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cf9add4e495307e8d2e69fad7dfd8cd83ad074d9ca4cc47f4bd1abc975e2d81e9792f47b7b1d6986193110126e1ffafd6d1c584f75b066d9c259ac25f5acdfd
|
7
|
+
data.tar.gz: f690dd4a4c8ea7ecf4e4599db7f7491b47d6f4fe0499474e32830f59758e2be205b1b8b03d7981e6caa9ec15a5f403ba5f9e9170e5a085fd2b131cbdc4488000
|
data/lib/desk/configuration.rb
CHANGED
@@ -24,6 +24,7 @@ module Desk
|
|
24
24
|
:support_email,
|
25
25
|
:use_max_requests,
|
26
26
|
:user_agent,
|
27
|
+
:timeout,
|
27
28
|
:version].freeze
|
28
29
|
|
29
30
|
# An array of valid request/response formats
|
@@ -92,6 +93,9 @@ module Desk
|
|
92
93
|
# By default, don't set a support email address
|
93
94
|
DEFAULT_SUPPORT_EMAIL = nil
|
94
95
|
|
96
|
+
# By default, don't set a default timeout
|
97
|
+
DEFAULT_TIMEOUT = nil
|
98
|
+
|
95
99
|
attr_reader :DEFAULT_ADAPTER
|
96
100
|
# @private
|
97
101
|
attr_accessor *VALID_OPTIONS_KEYS
|
@@ -239,6 +243,14 @@ module Desk
|
|
239
243
|
Thread.current[:version] = val
|
240
244
|
end
|
241
245
|
|
246
|
+
def timeout
|
247
|
+
Thread.current[:timeout] ||= DEFAULT_TIMEOUT
|
248
|
+
end
|
249
|
+
|
250
|
+
def timeout=(val)
|
251
|
+
Thread.current[:timeout] = val
|
252
|
+
end
|
253
|
+
|
242
254
|
# Reset all configuration options to defaults
|
243
255
|
def reset
|
244
256
|
self.adapter = DEFAULT_ADAPTER
|
@@ -259,6 +271,7 @@ module Desk
|
|
259
271
|
self.use_max_requests = DEFAULT_USE_MAX_REQUESTS
|
260
272
|
self.user_agent = DEFAULT_USER_AGENT
|
261
273
|
self.version = DEFAULT_VERSION
|
274
|
+
self.timeout = DEFAULT_TIMEOUT
|
262
275
|
self
|
263
276
|
end
|
264
277
|
end
|
data/lib/desk/connection.rb
CHANGED
@@ -15,8 +15,11 @@ module Desk
|
|
15
15
|
:proxy => proxy,
|
16
16
|
:ssl => {:verify => false, :version => 'SSLv23'},
|
17
17
|
:url => api_endpoint,
|
18
|
+
:request => {},
|
18
19
|
}
|
19
20
|
|
21
|
+
options[:request][:timeout] = timeout if timeout
|
22
|
+
|
20
23
|
Faraday.new(options) do |builder|
|
21
24
|
builder.use Faraday::Request::MultipartWithFile
|
22
25
|
if authenticated?
|
data/lib/desk/version.rb
CHANGED
data/spec/desk_spec.rb
CHANGED
@@ -108,6 +108,19 @@ describe Desk do
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
+
describe ".timeout" do
|
112
|
+
it "should return the default timeout" do
|
113
|
+
Desk.timeout.should == Desk::Configuration::DEFAULT_TIMEOUT
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe ".timeout=" do
|
118
|
+
it "should set the timeout" do
|
119
|
+
Desk.timeout = 30
|
120
|
+
Desk.timeout.should == 30
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
111
124
|
describe ".version=" do
|
112
125
|
before do
|
113
126
|
Desk.version = "v4"
|
@@ -134,7 +147,7 @@ describe Desk do
|
|
134
147
|
Desk.format.should == 'xml'
|
135
148
|
end
|
136
149
|
end
|
137
|
-
|
150
|
+
|
138
151
|
describe ".max_requests" do
|
139
152
|
it "should return the default max requests" do
|
140
153
|
Desk.max_requests.should == Desk::Configuration::DEFAULT_MAX_REQUESTS
|
@@ -186,30 +199,30 @@ describe Desk do
|
|
186
199
|
end
|
187
200
|
end
|
188
201
|
end
|
189
|
-
|
202
|
+
|
190
203
|
describe ".counter" do
|
191
204
|
before do
|
192
205
|
Desk.counter = 0
|
193
206
|
stub_get("cases").
|
194
207
|
to_return(:body => fixture("cases"), :headers => {:content_type => "application/json; charset=utf-8"})
|
195
208
|
end
|
196
|
-
|
209
|
+
|
197
210
|
it "should be 0 in the beginning" do
|
198
211
|
Desk.counter.should == 0
|
199
212
|
end
|
200
|
-
|
213
|
+
|
201
214
|
it "should count the requests" do
|
202
215
|
5.times {
|
203
216
|
Desk.cases
|
204
217
|
}
|
205
218
|
Desk.counter.should == 5
|
206
219
|
end
|
207
|
-
|
220
|
+
|
208
221
|
context "max requests enabled" do
|
209
222
|
before do
|
210
223
|
Desk.use_max_requests = true
|
211
224
|
end
|
212
|
-
|
225
|
+
|
213
226
|
it "should only allow 60 requests" do
|
214
227
|
expect {
|
215
228
|
70.times {
|
@@ -217,7 +230,7 @@ describe Desk do
|
|
217
230
|
}
|
218
231
|
}.to raise_error
|
219
232
|
end
|
220
|
-
|
233
|
+
|
221
234
|
it "should only allow defined requests" do
|
222
235
|
Desk.max_requests = 50
|
223
236
|
expect {
|
@@ -226,14 +239,14 @@ describe Desk do
|
|
226
239
|
}
|
227
240
|
}.to raise_error
|
228
241
|
end
|
229
|
-
|
242
|
+
|
230
243
|
def make_request
|
231
244
|
Desk.cases
|
232
245
|
rescue Desk::TooManyRequests
|
233
246
|
sleep(5)
|
234
247
|
make_request
|
235
248
|
end
|
236
|
-
|
249
|
+
|
237
250
|
xit "should allow more requests after minute has passed" do
|
238
251
|
70.times {
|
239
252
|
make_request
|
@@ -242,12 +255,12 @@ describe Desk do
|
|
242
255
|
end
|
243
256
|
end
|
244
257
|
end
|
245
|
-
|
258
|
+
|
246
259
|
describe ".minute" do
|
247
260
|
before do
|
248
261
|
Desk.minute = Time.now.min
|
249
262
|
end
|
250
|
-
|
263
|
+
|
251
264
|
it "should be the current minute" do
|
252
265
|
Desk.minute.should == Time.now.min
|
253
266
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: desk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Warren
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|