cobot_client 1.1.0 → 1.1.1

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: 01c5e183c0d951a2b1d0670e521e416ce12c5763
4
- data.tar.gz: ec90ac312c8481a42cc17b8027db038a3d2f415e
3
+ metadata.gz: 7e15ca6aec9f2e4b87115f96ad199b4e9689badc
4
+ data.tar.gz: 3d47e5b284423f8984d299f887e55fc74322d945
5
5
  SHA512:
6
- metadata.gz: 1968d198e816a0d3712fcfb1cf2790d273568a8b5565d21f8b4612dcd1a0e1c7c5677f94b500d5a3d605713a2826dd3a057ad8a72c9806a2def04224c4f7c653
7
- data.tar.gz: 93d4f4a79520d93d1170263aeae5e98dfb9d53837a15133270f4cf9130d074fe9c234b901e1cc3fe612d4c43d2e117916b3383f871c9f924d5ddea72e001f2c9
6
+ metadata.gz: c4ff2fbfd692cce791d982c511a088c8c3226207564d1aa6e5608b10447cba41fb7e83e8bea20591e9ccded1603c9abfa774270e9b2abbbe2c759f5e17df8b1a
7
+ data.tar.gz: 88df0bde69c06d859a642d099de7cda4926712798fe2feeb2817d0a471c07416e931b596f51968f536d0f962253ac092194019d1b7dc0719fde575281187253b
data/cobot_client.gemspec CHANGED
@@ -16,10 +16,10 @@ Gem::Specification.new do |gem|
16
16
  gem.require_paths = ["lib"]
17
17
  gem.version = CobotClient::VERSION
18
18
 
19
- gem.add_dependency 'virtus', '~>1.0.0'
20
- gem.add_dependency 'oauth2'
21
- gem.add_dependency 'rest-client'
22
- gem.add_dependency 'json'
23
- gem.add_development_dependency 'rspec'
24
- gem.add_development_dependency 'rake'
19
+ gem.add_dependency 'virtus', '~>1.0'
20
+ gem.add_dependency 'oauth2', '~>1.0'
21
+ gem.add_dependency 'rest-client', '~>1.7'
22
+ gem.add_dependency 'json', '~>1.8'
23
+ gem.add_development_dependency 'rspec', '~>3.0'
24
+ gem.add_development_dependency 'rake', '~>10.0'
25
25
  end
@@ -32,11 +32,11 @@ module CobotClient
32
32
  # args: either a full URL or subdomain, path, plus a body as hash
33
33
  def put(*args)
34
34
  url, subdomain, path, body = parse_args *args
35
- JSON.parse RestClient.put(
36
- build_url(url || subdomain, path),
37
- body.to_json,
38
- headers.merge(content_type_header)).body,
39
- symbolize_names: true
35
+ response = RestClient.put(
36
+ build_url(url || subdomain, path),
37
+ body.to_json,
38
+ headers.merge(content_type_header))
39
+ JSON.parse response.body, symbolize_names: true unless response.code == 204
40
40
  end
41
41
 
42
42
  # args: either a full URL or subdomain, path
@@ -48,11 +48,11 @@ module CobotClient
48
48
  # args: either a full URL or subdomain, path, plus a body as hash
49
49
  def post(*args)
50
50
  url, subdomain, path, body = parse_args *args
51
- JSON.parse RestClient.post(
51
+ response = RestClient.post(
52
52
  build_url(url || subdomain, path),
53
53
  body.to_json,
54
- headers.merge(content_type_header)).body,
55
- symbolize_names: true
54
+ headers.merge(content_type_header))
55
+ JSON.parse response.body, symbolize_names: true unless response.code == 204
56
56
  end
57
57
 
58
58
  # args: either a full URL or subdomain, path, plus an optional params hash
@@ -1,3 +1,3 @@
1
1
  module CobotClient
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -2,7 +2,7 @@ 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) { double(:default_response, body: '{}') }
5
+ let(:default_response) { double(:default_response, code: 200, body: '{}') }
6
6
 
7
7
  before(:each) do
8
8
  CobotClient::ApiClient.user_agent = 'test agent'
@@ -10,14 +10,14 @@ describe CobotClient::ApiClient do
10
10
 
11
11
  context 'listing resources' do
12
12
  it 'calls rest client' do
13
- RestClient.should_receive(:get).with('https://co-up.cobot.me/api/resources',
13
+ expect(RestClient).to receive(:get).with('https://co-up.cobot.me/api/resources',
14
14
  hash_including('Authorization' => 'Bearer token-123')) { default_response }
15
15
 
16
16
  api_client.get_resources 'co-up'
17
17
  end
18
18
 
19
19
  it 'returns the json' do
20
- RestClient.stub(:get) { double(:response, body: [{id: 'resource-1'}].to_json) }
20
+ allow(RestClient).to receive(:get) { double(:response, body: [{id: 'resource-1'}].to_json) }
21
21
 
22
22
  resources = api_client.get_resources 'co-up'
23
23
 
@@ -27,7 +27,7 @@ describe CobotClient::ApiClient do
27
27
 
28
28
  context 'creating a booking' do
29
29
  it 'calls rest client' do
30
- RestClient.should_receive(:post).with(
30
+ expect(RestClient).to receive(:post).with(
31
31
  'https://co-up.cobot.me/api/resources/res-1/bookings',
32
32
  {title: 'meeting'}.to_json,
33
33
  hash_including('Authorization' => 'Bearer token-123')) { default_response }
@@ -36,7 +36,8 @@ describe CobotClient::ApiClient do
36
36
  end
37
37
 
38
38
  it 'returns the json' do
39
- RestClient.stub(:post) { double(:response, body: {title: 'meeting'}.to_json) }
39
+ allow(RestClient).to receive(:post) { double(:response,
40
+ code: 201, body: {title: 'meeting'}.to_json) }
40
41
 
41
42
  booking = api_client.create_booking 'co-up', 'res-1', title: 'meeting'
42
43
 
@@ -46,7 +47,7 @@ describe CobotClient::ApiClient do
46
47
 
47
48
  context 'updating a booking' do
48
49
  it 'calls rest client' do
49
- RestClient.should_receive(:put).with('https://co-up.cobot.me/api/bookings/booking-1',
50
+ expect(RestClient).to receive(:put).with('https://co-up.cobot.me/api/bookings/booking-1',
50
51
  {title: 'meeting'}.to_json,
51
52
  hash_including('Authorization' => 'Bearer token-123')) { default_response }
52
53
 
@@ -54,7 +55,8 @@ describe CobotClient::ApiClient do
54
55
  end
55
56
 
56
57
  it 'returns the json' do
57
- RestClient.stub(:put) { double(:response, body: {title: 'meeting'}.to_json) }
58
+ allow(RestClient).to receive(:put) { double(:response, code: 200,
59
+ body: {title: 'meeting'}.to_json) }
58
60
 
59
61
  booking = api_client.update_booking 'co-up', 'booking-1', title: 'meeting'
60
62
 
@@ -64,7 +66,7 @@ describe CobotClient::ApiClient do
64
66
 
65
67
  context 'deleting a booking' do
66
68
  it 'calls rest client' do
67
- RestClient.should_receive(:delete).with('https://co-up.cobot.me/api/bookings/booking-1',
69
+ expect(RestClient).to receive(:delete).with('https://co-up.cobot.me/api/bookings/booking-1',
68
70
  hash_including('Authorization' => 'Bearer token-123')) { default_response }
69
71
 
70
72
  api_client.delete_booking 'co-up', 'booking-1'
@@ -73,7 +75,7 @@ describe CobotClient::ApiClient do
73
75
 
74
76
  context '#put' do
75
77
  it 'calls rest client' do
76
- RestClient.should_receive(:put).with(
78
+ expect(RestClient).to receive(:put).with(
77
79
  'https://co-up.cobot.me/api/invoices',
78
80
  {id: '1'}.to_json,
79
81
  'Content-Type' => 'application/json',
@@ -84,7 +86,7 @@ describe CobotClient::ApiClient do
84
86
  end
85
87
 
86
88
  it 'accepts a url' do
87
- RestClient.should_receive(:put).with(
89
+ expect(RestClient).to receive(:put).with(
88
90
  'https://co-up.cobot.me/api/invoices',
89
91
  {id: '1'}.to_json,
90
92
  'Content-Type' => 'application/json',
@@ -95,15 +97,21 @@ describe CobotClient::ApiClient do
95
97
  end
96
98
 
97
99
  it 'returns the response json' do
98
- RestClient.stub(:put) { double(:response, body: [{number: 1}].to_json) }
100
+ allow(RestClient).to receive(:put) { double(:response, code: 200, body: [{number: 1}].to_json) }
99
101
 
100
102
  expect(api_client.put('co-up', '/invoices', {})).to eql([{number: 1}])
101
103
  end
104
+
105
+ it 'returns nil when the status code is 204' do
106
+ allow(RestClient).to receive(:put) { double(:response, body: '', code: 204) }
107
+
108
+ expect(api_client.put('co-up', '/invoices', {})).to be_nil
109
+ end
102
110
  end
103
111
 
104
112
  context '#post' do
105
113
  it 'calls rest client' do
106
- RestClient.should_receive(:post).with(
114
+ expect(RestClient).to receive(:post).with(
107
115
  'https://co-up.cobot.me/api/invoices',
108
116
  {id: '1'}.to_json,
109
117
  'Content-Type' => 'application/json',
@@ -114,7 +122,7 @@ describe CobotClient::ApiClient do
114
122
  end
115
123
 
116
124
  it 'accepts a url' do
117
- RestClient.should_receive(:post).with(
125
+ expect(RestClient).to receive(:post).with(
118
126
  'https://co-up.cobot.me/api/invoices',
119
127
  {id: '1'}.to_json,
120
128
  'Content-Type' => 'application/json',
@@ -125,29 +133,37 @@ describe CobotClient::ApiClient do
125
133
  end
126
134
 
127
135
  it 'returns the response json' do
128
- RestClient.stub(:post) { double(:response, body: [{number: 1}].to_json) }
136
+ allow(RestClient).to receive(:post) { double(:response,
137
+ code: 201, body: [{number: 1}].to_json) }
129
138
 
130
139
  expect(api_client.post('co-up', '/invoices', {})).to eql([{number: 1}])
131
140
  end
141
+
142
+ it 'returns nil when the status code is 204' do
143
+ allow(RestClient).to receive(:post) { double(:response, code: 204,
144
+ body: '') }
145
+
146
+ expect(api_client.post('co-up', '/invoices', {})).to be_nil
147
+ end
132
148
  end
133
149
 
134
150
  context '#get' do
135
151
  it 'calls rest client' do
136
- RestClient.should_receive(:get).with('https://co-up.cobot.me/api/invoices?from=2013-10-6&to=2013-10-12',
152
+ expect(RestClient).to receive(:get).with('https://co-up.cobot.me/api/invoices?from=2013-10-6&to=2013-10-12',
137
153
  'User-Agent' => 'test agent', 'Authorization' => 'Bearer token-123') { default_response }
138
154
 
139
155
  api_client.get 'co-up', '/invoices', {from: '2013-10-6', to: '2013-10-12'}
140
156
  end
141
157
 
142
158
  it 'accepts a url' do
143
- RestClient.should_receive(:get).with('https://co-up.cobot.me/api/invoices?from=2013-10-6&to=2013-10-12',
159
+ expect(RestClient).to receive(:get).with('https://co-up.cobot.me/api/invoices?from=2013-10-6&to=2013-10-12',
144
160
  'User-Agent' => 'test agent', 'Authorization' => 'Bearer token-123') { default_response }
145
161
 
146
162
  api_client.get 'https://co-up.cobot.me/api/invoices', {from: '2013-10-6', to: '2013-10-12'}
147
163
  end
148
164
 
149
165
  it 'returns the response json' do
150
- RestClient.stub(:get) { double(:response, body: [{number: 1}].to_json) }
166
+ allow(RestClient).to receive(:get) { double(:response, body: [{number: 1}].to_json) }
151
167
 
152
168
  expect(api_client.get('co-up', '/invoices')).to eql([{number: 1}])
153
169
  end
@@ -155,7 +171,7 @@ describe CobotClient::ApiClient do
155
171
 
156
172
  context '#delete' do
157
173
  it 'calls rest client' do
158
- RestClient.should_receive(:delete).with(
174
+ expect(RestClient).to receive(:delete).with(
159
175
  'https://co-up.cobot.me/api/invoices/1',
160
176
  'User-Agent' => 'test agent', 'Authorization' => 'Bearer token-123') { default_response }
161
177
 
@@ -163,7 +179,7 @@ describe CobotClient::ApiClient do
163
179
  end
164
180
 
165
181
  it 'accepts a url' do
166
- RestClient.should_receive(:delete).with(
182
+ expect(RestClient).to receive(:delete).with(
167
183
  'https://co-up.cobot.me/api/invoices/1',
168
184
  'User-Agent' => 'test agent', 'Authorization' => 'Bearer token-123') { default_response }
169
185
 
@@ -6,12 +6,12 @@ describe CobotClient::NavigationLinkService, '#install_links' do
6
6
 
7
7
  context 'when there are links already' do
8
8
  before(:each) do
9
- api_client.stub(:get).with(
9
+ allow(api_client).to receive(:get).with(
10
10
  'co-up', '/navigation_links') { [{label: 'test link'}] }
11
11
  end
12
12
 
13
13
  it 'installs no links' do
14
- api_client.should_not_receive(:post)
14
+ expect(api_client).to_not receive(:post)
15
15
 
16
16
  service.install_links [double(:link)]
17
17
  end
@@ -25,11 +25,11 @@ describe CobotClient::NavigationLinkService, '#install_links' do
25
25
  let(:link) { double(:link, section: 'admin/manage', label: 'test link', iframe_url: '/test') }
26
26
 
27
27
  before(:each) do
28
- api_client.stub(:get).with('co-up', '/navigation_links') { [] }
28
+ allow(api_client).to receive(:get).with('co-up', '/navigation_links') { [] }
29
29
  end
30
30
 
31
31
  it 'installs the links' do
32
- api_client.should_receive(:post).with('co-up', '/navigation_links', {
32
+ expect(api_client).to receive(:post).with('co-up', '/navigation_links', {
33
33
  section: 'admin/manage', label: 'test link', iframe_url: '/test'
34
34
  }) { {} }
35
35
 
@@ -37,7 +37,7 @@ describe CobotClient::NavigationLinkService, '#install_links' do
37
37
  end
38
38
 
39
39
  it 'returns the links created' do
40
- api_client.stub(:post) { {label: 'test link'} }
40
+ allow(api_client).to receive(:post) { {label: 'test link'} }
41
41
 
42
42
  expect(service.install_links([link]).map(&:label)).to eql(['test link'])
43
43
  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: 1.1.0
4
+ version: 1.1.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: 2014-06-24 00:00:00.000000000 Z
11
+ date: 2014-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -16,84 +16,84 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.0
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.0
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: oauth2
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rest-client
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '1.7'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '1.7'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: json
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '1.8'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '1.8'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '3.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '3.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '10.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '10.0'
97
97
  description: Client for the Cobot API plus helpers
98
98
  email:
99
99
  - alex@cobot.me