cobot_client 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cobot_client/api_client.rb +36 -29
- data/lib/cobot_client/version.rb +1 -1
- data/spec/cobot_client/api_client_spec.rb +15 -0
- 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: 6065b773f6bf01f885cbf320e358894fdb5022ec
|
4
|
+
data.tar.gz: 2a522841f501b3604930674f6e3d69aa95f2ceca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c550f7fdb4895e31ad25d37e7201aaca0a1bebe9724dd0ac0783ea47ed50d436f40bd2e48c538101b94e6271f0deb5d0b902f3b0aeb39b2124c3f4757400dd37
|
7
|
+
data.tar.gz: ba50673265ee4f7e7f9555b06e7364b705b6aa272c406b1dd544d9899c55b3cd6f5e2f8c56054914d7bfbdb765156c84a72cbdcb943c1485a4edf3cc3e290047
|
@@ -6,8 +6,9 @@ module CobotClient
|
|
6
6
|
include UrlHelper
|
7
7
|
|
8
8
|
class << self
|
9
|
-
attr_accessor :user_agent
|
9
|
+
attr_accessor :user_agent, :retry_time
|
10
10
|
end
|
11
|
+
self.retry_time = 1
|
11
12
|
|
12
13
|
def initialize(access_token)
|
13
14
|
@access_token = access_token
|
@@ -30,35 +31,13 @@ module CobotClient
|
|
30
31
|
end
|
31
32
|
|
32
33
|
# args: either a full URL or subdomain, path, plus a body as hash
|
33
|
-
def
|
34
|
-
|
35
|
-
rewrap_errors do
|
36
|
-
response = RestClient.put(
|
37
|
-
build_url(url || subdomain, path),
|
38
|
-
body.to_json,
|
39
|
-
headers.merge(content_type_header))
|
40
|
-
JSON.parse response.body, symbolize_names: true unless response.code == 204
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# args: either a full URL or subdomain, path
|
45
|
-
def delete(*args)
|
46
|
-
url, subdomain, path, _ = parse_args(*args)
|
47
|
-
rewrap_errors do
|
48
|
-
RestClient.delete(build_url(url || subdomain, path), headers)
|
49
|
-
end
|
34
|
+
def post(*args)
|
35
|
+
request :post, *args
|
50
36
|
end
|
51
37
|
|
52
38
|
# args: either a full URL or subdomain, path, plus a body as hash
|
53
|
-
def
|
54
|
-
|
55
|
-
rewrap_errors do
|
56
|
-
response = RestClient.post(
|
57
|
-
build_url(url || subdomain, path),
|
58
|
-
body.to_json,
|
59
|
-
headers.merge(content_type_header))
|
60
|
-
JSON.parse response.body, symbolize_names: true unless response.code == 204
|
61
|
-
end
|
39
|
+
def put(*args)
|
40
|
+
request :put, *args
|
62
41
|
end
|
63
42
|
|
64
43
|
# args: either a full URL or subdomain, path, plus an optional params hash
|
@@ -72,12 +51,40 @@ module CobotClient
|
|
72
51
|
end, symbolize_names: true)
|
73
52
|
end
|
74
53
|
|
54
|
+
# args: either a full URL or subdomain, path
|
55
|
+
def delete(*args)
|
56
|
+
url, subdomain, path, _ = parse_args(*args)
|
57
|
+
rewrap_errors do
|
58
|
+
RestClient.delete(build_url(url || subdomain, path), headers)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
75
62
|
private
|
76
63
|
|
64
|
+
def request(method, *args)
|
65
|
+
url, subdomain, path, body = parse_args(*args)
|
66
|
+
rewrap_errors do
|
67
|
+
response = RestClient.public_send(method,
|
68
|
+
build_url(url || subdomain, path),
|
69
|
+
body.to_json,
|
70
|
+
headers.merge(content_type_header))
|
71
|
+
JSON.parse response.body, symbolize_names: true unless response.code == 204
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
77
75
|
def rewrap_errors
|
76
|
+
retries = 0
|
78
77
|
yield
|
79
|
-
|
80
|
-
|
78
|
+
rescue RestClient::BadGateway => e
|
79
|
+
if retries < 3
|
80
|
+
sleep self.class.retry_time
|
81
|
+
retries += 1
|
82
|
+
retry
|
83
|
+
else
|
84
|
+
raise e
|
85
|
+
end
|
86
|
+
rescue RestClient::Exception => e
|
87
|
+
fail CobotClient::Exceptions::EXCEPTIONS_MAP[e.class].new(e.response)
|
81
88
|
end
|
82
89
|
|
83
90
|
def parse_args(*args)
|
data/lib/cobot_client/version.rb
CHANGED
@@ -6,6 +6,7 @@ describe CobotClient::ApiClient do
|
|
6
6
|
|
7
7
|
before(:each) do
|
8
8
|
CobotClient::ApiClient.user_agent = 'test agent'
|
9
|
+
CobotClient::ApiClient.retry_time = 0
|
9
10
|
end
|
10
11
|
|
11
12
|
context 'listing resources' do
|
@@ -107,6 +108,20 @@ describe CobotClient::ApiClient do
|
|
107
108
|
|
108
109
|
expect(api_client.put('co-up', '/invoices', {})).to be_nil
|
109
110
|
end
|
111
|
+
|
112
|
+
it 'retries a 502 error' do
|
113
|
+
@times = 0
|
114
|
+
allow(RestClient).to receive(:put) do
|
115
|
+
if @times < 3
|
116
|
+
@times += 1
|
117
|
+
fail RestClient::BadGateway
|
118
|
+
else
|
119
|
+
double(code: 200, body: {success: true}.to_json)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
expect(api_client.put('co-up', '/invoices', {})).to eql(success: true)
|
124
|
+
end
|
110
125
|
end
|
111
126
|
|
112
127
|
context '#post' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cobot_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Lang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|