cobot_client 0.6.7 → 0.7.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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31d7c3f30c6c94506857a0a005f65976a494818a
|
4
|
+
data.tar.gz: 5625e0d5d2a99c7b747de56399ab92c6e23d2cba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d713d3b32b0b7fbc8edae0f8b314793056bae5cae9dd19e3dda82d1513e9b2ae717dda8bc83581557c37fde63d68e2e362c03189afbeedc89454287a3ad3120
|
7
|
+
data.tar.gz: 75138f1446fd3fb6f732f0838145897d021e3129179cfc785bb78e8462413261e2da5fd4c00d9b376796301b99fdf9c75042c1a27015d35bb094f37d04fa254b
|
@@ -5,6 +5,10 @@ module CobotClient
|
|
5
5
|
class ApiClient
|
6
6
|
include UrlHelper
|
7
7
|
|
8
|
+
class << self
|
9
|
+
attr_accessor :user_agent
|
10
|
+
end
|
11
|
+
|
8
12
|
def initialize(access_token)
|
9
13
|
@access_token = access_token
|
10
14
|
end
|
@@ -26,28 +30,31 @@ module CobotClient
|
|
26
30
|
end
|
27
31
|
|
28
32
|
def put(subdomain, path, params)
|
29
|
-
JSON.parse RestClient.put(cobot_url(subdomain, "/api#{path}"), params,
|
33
|
+
JSON.parse RestClient.put(cobot_url(subdomain, "/api#{path}"), params, headers).body,
|
30
34
|
symbolize_names: true
|
31
35
|
end
|
32
36
|
|
33
37
|
def delete(subdomain, path)
|
34
|
-
RestClient.delete(cobot_url(subdomain, "/api#{path}"),
|
38
|
+
RestClient.delete(cobot_url(subdomain, "/api#{path}"), headers)
|
35
39
|
end
|
36
40
|
|
37
41
|
def post(subdomain, path, params)
|
38
|
-
JSON.parse RestClient.post(cobot_url(subdomain, "/api#{path}"), params,
|
42
|
+
JSON.parse RestClient.post(cobot_url(subdomain, "/api#{path}"), params, headers).body,
|
39
43
|
symbolize_names: true
|
40
44
|
end
|
41
45
|
|
42
46
|
def get(subdomain, path, params = {})
|
43
47
|
JSON.parse(
|
44
|
-
RestClient.get(cobot_url(subdomain, "/api#{path}", params: params),
|
48
|
+
RestClient.get(cobot_url(subdomain, "/api#{path}", params: params), headers).body,
|
45
49
|
symbolize_names: true
|
46
50
|
)
|
47
51
|
end
|
48
52
|
|
49
|
-
def
|
50
|
-
{
|
53
|
+
def headers
|
54
|
+
{
|
55
|
+
'Authorization' => "Bearer #{@access_token}",
|
56
|
+
'User-Agent' => self.class.user_agent || "Cobot Client #{CobotClient::VERSION}"
|
57
|
+
}
|
51
58
|
end
|
52
59
|
end
|
53
60
|
end
|
data/lib/cobot_client/version.rb
CHANGED
@@ -2,18 +2,18 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe CobotClient::ApiClient do
|
4
4
|
let(:api_client) { CobotClient::ApiClient.new('token-123') }
|
5
|
-
let(:default_response) {
|
5
|
+
let(:default_response) { double(:default_response, body: '{}') }
|
6
6
|
|
7
7
|
context 'listing resources' do
|
8
8
|
it 'calls rest client' do
|
9
9
|
RestClient.should_receive(:get).with('https://co-up.cobot.me/api/resources',
|
10
|
-
'Authorization' => 'Bearer token-123') { default_response }
|
10
|
+
hash_including('Authorization' => 'Bearer token-123')) { default_response }
|
11
11
|
|
12
12
|
api_client.get_resources 'co-up'
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'returns the json' do
|
16
|
-
RestClient.stub(:get) {
|
16
|
+
RestClient.stub(:get) { double(:response, body: [{id: 'resource-1'}].to_json) }
|
17
17
|
|
18
18
|
resources = api_client.get_resources 'co-up'
|
19
19
|
|
@@ -25,13 +25,13 @@ describe CobotClient::ApiClient do
|
|
25
25
|
it 'calls rest client' do
|
26
26
|
RestClient.should_receive(:post).with('https://co-up.cobot.me/api/resources/res-1/bookings',
|
27
27
|
{title: 'meeting'},
|
28
|
-
'Authorization' => 'Bearer token-123') { default_response }
|
28
|
+
hash_including('Authorization' => 'Bearer token-123')) { default_response }
|
29
29
|
|
30
30
|
api_client.create_booking 'co-up', 'res-1', title: 'meeting'
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'returns the json' do
|
34
|
-
RestClient.stub(:post) {
|
34
|
+
RestClient.stub(:post) { double(:response, body: {title: 'meeting'}.to_json) }
|
35
35
|
|
36
36
|
booking = api_client.create_booking 'co-up', 'res-1', title: 'meeting'
|
37
37
|
|
@@ -43,13 +43,13 @@ describe CobotClient::ApiClient do
|
|
43
43
|
it 'calls rest client' do
|
44
44
|
RestClient.should_receive(:put).with('https://co-up.cobot.me/api/bookings/booking-1',
|
45
45
|
{title: 'meeting'},
|
46
|
-
'Authorization' => 'Bearer token-123') { default_response }
|
46
|
+
hash_including('Authorization' => 'Bearer token-123')) { default_response }
|
47
47
|
|
48
48
|
api_client.update_booking 'co-up', 'booking-1', title: 'meeting'
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'returns the json' do
|
52
|
-
RestClient.stub(:put) {
|
52
|
+
RestClient.stub(:put) { double(:response, body: {title: 'meeting'}.to_json) }
|
53
53
|
|
54
54
|
booking = api_client.update_booking 'co-up', 'booking-1', title: 'meeting'
|
55
55
|
|
@@ -60,7 +60,7 @@ describe CobotClient::ApiClient do
|
|
60
60
|
context 'deleting a booking' do
|
61
61
|
it 'calls rest client' do
|
62
62
|
RestClient.should_receive(:delete).with('https://co-up.cobot.me/api/bookings/booking-1',
|
63
|
-
'Authorization' => 'Bearer token-123') { default_response }
|
63
|
+
hash_including('Authorization' => 'Bearer token-123')) { default_response }
|
64
64
|
|
65
65
|
api_client.delete_booking 'co-up', 'booking-1'
|
66
66
|
end
|
@@ -69,13 +69,22 @@ describe CobotClient::ApiClient do
|
|
69
69
|
context '#get' do
|
70
70
|
it 'calls rest client' do
|
71
71
|
RestClient.should_receive(:get).with('https://co-up.cobot.me/api/invoices?from=2013-10-6&to=2013-10-12',
|
72
|
-
'Authorization' => 'Bearer token-123') { default_response }
|
72
|
+
hash_including('Authorization' => 'Bearer token-123')) { default_response }
|
73
73
|
|
74
74
|
api_client.get 'co-up', '/invoices', {from: '2013-10-6', to: '2013-10-12'}
|
75
75
|
end
|
76
76
|
|
77
|
+
it 'sends a user agent header' do
|
78
|
+
CobotClient::ApiClient.user_agent = 'test agent'
|
79
|
+
|
80
|
+
RestClient.should_receive(:get).with(anything,
|
81
|
+
hash_including('User-Agent' => 'test agent')) { default_response }
|
82
|
+
|
83
|
+
api_client.get 'co-up', '/invoices'
|
84
|
+
end
|
85
|
+
|
77
86
|
it 'returns the response json' do
|
78
|
-
RestClient.stub(:get) {
|
87
|
+
RestClient.stub(:get) { double(:response, body: [{number: 1}].to_json) }
|
79
88
|
|
80
89
|
expect(api_client.get('co-up', '/invoices')).to eql([{number: 1}])
|
81
90
|
end
|
@@ -2,16 +2,16 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe CobotClient::NavigationLinkService, '#install_links' do
|
4
4
|
let(:service) { CobotClient::NavigationLinkService.new(oauth_client, 'token-1', 'co-up') }
|
5
|
-
let(:oauth_client) {
|
5
|
+
let(:oauth_client) { double(:oauth_client) }
|
6
6
|
|
7
7
|
before(:each) do
|
8
|
-
@token =
|
8
|
+
@token = double(:token).as_null_object
|
9
9
|
OAuth2::AccessToken.stub(new: @token)
|
10
10
|
end
|
11
11
|
|
12
12
|
context 'when there are links already' do
|
13
13
|
before(:each) do
|
14
|
-
@token.stub(:get).with('https://co-up.cobot.me/api/navigation_links') do
|
14
|
+
@token.stub(:get).with('https://co-up.cobot.me/api/navigation_links') do double(:response, parsed: [
|
15
15
|
{label: 'test link'}])
|
16
16
|
end
|
17
17
|
end
|
@@ -19,30 +19,30 @@ describe CobotClient::NavigationLinkService, '#install_links' do
|
|
19
19
|
it 'installs no links' do
|
20
20
|
@token.should_not_receive(:post)
|
21
21
|
|
22
|
-
service.install_links [
|
22
|
+
service.install_links [double(:link)]
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'returns the links' do
|
26
|
-
expect(service.install_links([
|
26
|
+
expect(service.install_links([double(:link)]).map(&:label)).to eql(['test link'])
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
context 'when there are no links installed' do
|
31
|
-
let(:link) {
|
31
|
+
let(:link) { double(:link, section: 'admin/manage', label: 'test link', iframe_url: '/test') }
|
32
32
|
before(:each) do
|
33
|
-
@token.stub(:get).with('https://co-up.cobot.me/api/navigation_links') {
|
33
|
+
@token.stub(:get).with('https://co-up.cobot.me/api/navigation_links') { double(:response, parsed: []) }
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'installs the links' do
|
37
37
|
@token.should_receive(:post).with('https://co-up.cobot.me/api/navigation_links', body: {
|
38
38
|
section: 'admin/manage', label: 'test link', iframe_url: '/test'
|
39
|
-
}) {
|
39
|
+
}) { double(:response, status: 201, parsed: {}) }
|
40
40
|
|
41
41
|
service.install_links [link]
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'returns the links created' do
|
45
|
-
response =
|
45
|
+
response = double(:response, status: 201, parsed: {label: 'test link'})
|
46
46
|
@token.stub(:post) { response }
|
47
47
|
|
48
48
|
expect(service.install_links([link]).map(&:label)).to eql(['test link'])
|
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.7.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-
|
11
|
+
date: 2014-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|