cobot_client 0.7.0 → 0.8.0
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 +17 -5
- data/lib/cobot_client/version.rb +1 -1
- data/spec/cobot_client/api_client_spec.rb +56 -12
- 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: 5ef6565b60d68b573425d7e0cc139b6a050aedeb
|
4
|
+
data.tar.gz: 3e08fc83c9d58b3e08efc4b3b943fa4d6f20acec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 311d59891c2b4cd2b30c828d5e4c264cfbd22e97f235f23d4cda3c4646f48507d849b158e0234857c071b30b7b49a4215121c1031500e0e45cb0ef6d5f82b489
|
7
|
+
data.tar.gz: 99efdb44a13c364905e7953bf496233f6986544649556505ae07dd330b9b15cd72304a0df36af7471ea695e1c387bf3fd85b9a5a4955bd680f9897323a314dc8
|
@@ -29,8 +29,11 @@ module CobotClient
|
|
29
29
|
delete subdomain, "/bookings/#{id}"
|
30
30
|
end
|
31
31
|
|
32
|
-
def put(subdomain, path,
|
33
|
-
JSON.parse RestClient.put(
|
32
|
+
def put(subdomain, path, body)
|
33
|
+
JSON.parse RestClient.put(
|
34
|
+
cobot_url(subdomain, "/api#{path}"),
|
35
|
+
body.to_json,
|
36
|
+
headers.merge(content_type_header)).body,
|
34
37
|
symbolize_names: true
|
35
38
|
end
|
36
39
|
|
@@ -38,18 +41,27 @@ module CobotClient
|
|
38
41
|
RestClient.delete(cobot_url(subdomain, "/api#{path}"), headers)
|
39
42
|
end
|
40
43
|
|
41
|
-
def post(subdomain, path,
|
42
|
-
JSON.parse RestClient.post(
|
44
|
+
def post(subdomain, path, body)
|
45
|
+
JSON.parse RestClient.post(
|
46
|
+
cobot_url(subdomain, "/api#{path}"),
|
47
|
+
body.to_json,
|
48
|
+
headers.merge(content_type_header)).body,
|
43
49
|
symbolize_names: true
|
44
50
|
end
|
45
51
|
|
46
52
|
def get(subdomain, path, params = {})
|
47
53
|
JSON.parse(
|
48
|
-
RestClient.get(
|
54
|
+
RestClient.get(
|
55
|
+
cobot_url(subdomain, "/api#{path}", params: params),
|
56
|
+
headers).body,
|
49
57
|
symbolize_names: true
|
50
58
|
)
|
51
59
|
end
|
52
60
|
|
61
|
+
def content_type_header
|
62
|
+
{'Content-Type' => 'application/json'}
|
63
|
+
end
|
64
|
+
|
53
65
|
def headers
|
54
66
|
{
|
55
67
|
'Authorization' => "Bearer #{@access_token}",
|
data/lib/cobot_client/version.rb
CHANGED
@@ -4,6 +4,10 @@ describe CobotClient::ApiClient do
|
|
4
4
|
let(:api_client) { CobotClient::ApiClient.new('token-123') }
|
5
5
|
let(:default_response) { double(:default_response, body: '{}') }
|
6
6
|
|
7
|
+
before(:each) do
|
8
|
+
CobotClient::ApiClient.user_agent = 'test agent'
|
9
|
+
end
|
10
|
+
|
7
11
|
context 'listing resources' do
|
8
12
|
it 'calls rest client' do
|
9
13
|
RestClient.should_receive(:get).with('https://co-up.cobot.me/api/resources',
|
@@ -23,8 +27,9 @@ describe CobotClient::ApiClient do
|
|
23
27
|
|
24
28
|
context 'creating a booking' do
|
25
29
|
it 'calls rest client' do
|
26
|
-
RestClient.should_receive(:post).with(
|
27
|
-
|
30
|
+
RestClient.should_receive(:post).with(
|
31
|
+
'https://co-up.cobot.me/api/resources/res-1/bookings',
|
32
|
+
{title: 'meeting'}.to_json,
|
28
33
|
hash_including('Authorization' => 'Bearer token-123')) { default_response }
|
29
34
|
|
30
35
|
api_client.create_booking 'co-up', 'res-1', title: 'meeting'
|
@@ -42,7 +47,7 @@ describe CobotClient::ApiClient do
|
|
42
47
|
context 'updating a booking' do
|
43
48
|
it 'calls rest client' do
|
44
49
|
RestClient.should_receive(:put).with('https://co-up.cobot.me/api/bookings/booking-1',
|
45
|
-
{title: 'meeting'},
|
50
|
+
{title: 'meeting'}.to_json,
|
46
51
|
hash_including('Authorization' => 'Bearer token-123')) { default_response }
|
47
52
|
|
48
53
|
api_client.update_booking 'co-up', 'booking-1', title: 'meeting'
|
@@ -66,21 +71,50 @@ describe CobotClient::ApiClient do
|
|
66
71
|
end
|
67
72
|
end
|
68
73
|
|
69
|
-
context '#
|
74
|
+
context '#put' do
|
70
75
|
it 'calls rest client' do
|
71
|
-
RestClient.should_receive(:
|
72
|
-
|
76
|
+
RestClient.should_receive(:put).with(
|
77
|
+
'https://co-up.cobot.me/api/invoices',
|
78
|
+
{id: '1'}.to_json,
|
79
|
+
'Content-Type' => 'application/json',
|
80
|
+
'User-Agent' => 'test agent',
|
81
|
+
'Authorization' => 'Bearer token-123') { default_response }
|
82
|
+
|
83
|
+
api_client.put 'co-up', '/invoices', {id: '1'}
|
84
|
+
end
|
73
85
|
|
74
|
-
|
86
|
+
it 'returns the response json' do
|
87
|
+
RestClient.stub(:put) { double(:response, body: [{number: 1}].to_json) }
|
88
|
+
|
89
|
+
expect(api_client.put('co-up', '/invoices', {})).to eql([{number: 1}])
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context '#post' do
|
94
|
+
it 'calls rest client' do
|
95
|
+
RestClient.should_receive(:post).with(
|
96
|
+
'https://co-up.cobot.me/api/invoices',
|
97
|
+
{id: '1'}.to_json,
|
98
|
+
'Content-Type' => 'application/json',
|
99
|
+
'User-Agent' => 'test agent',
|
100
|
+
'Authorization' => 'Bearer token-123') { default_response }
|
101
|
+
|
102
|
+
api_client.post 'co-up', '/invoices', {id: '1'}
|
75
103
|
end
|
76
104
|
|
77
|
-
it '
|
78
|
-
|
105
|
+
it 'returns the response json' do
|
106
|
+
RestClient.stub(:post) { double(:response, body: [{number: 1}].to_json) }
|
107
|
+
|
108
|
+
expect(api_client.post('co-up', '/invoices', {})).to eql([{number: 1}])
|
109
|
+
end
|
110
|
+
end
|
79
111
|
|
80
|
-
|
81
|
-
|
112
|
+
context '#get' do
|
113
|
+
it 'calls rest client' do
|
114
|
+
RestClient.should_receive(:get).with('https://co-up.cobot.me/api/invoices?from=2013-10-6&to=2013-10-12',
|
115
|
+
'User-Agent' => 'test agent', 'Authorization' => 'Bearer token-123') { default_response }
|
82
116
|
|
83
|
-
api_client.get 'co-up', '/invoices'
|
117
|
+
api_client.get 'co-up', '/invoices', {from: '2013-10-6', to: '2013-10-12'}
|
84
118
|
end
|
85
119
|
|
86
120
|
it 'returns the response json' do
|
@@ -89,4 +123,14 @@ describe CobotClient::ApiClient do
|
|
89
123
|
expect(api_client.get('co-up', '/invoices')).to eql([{number: 1}])
|
90
124
|
end
|
91
125
|
end
|
126
|
+
|
127
|
+
context '#delete' do
|
128
|
+
it 'calls rest client' do
|
129
|
+
RestClient.should_receive(:delete).with(
|
130
|
+
'https://co-up.cobot.me/api/invoices/1',
|
131
|
+
'User-Agent' => 'test agent', 'Authorization' => 'Bearer token-123') { default_response }
|
132
|
+
|
133
|
+
api_client.delete 'co-up', '/invoices/1'
|
134
|
+
end
|
135
|
+
end
|
92
136
|
end
|
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: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Lang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|