cobot_client 0.8.0 → 1.0.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: 5ef6565b60d68b573425d7e0cc139b6a050aedeb
4
- data.tar.gz: 3e08fc83c9d58b3e08efc4b3b943fa4d6f20acec
3
+ metadata.gz: d97efe9d55e36afb226b47dfd1b27fb96a6ca8e5
4
+ data.tar.gz: a930cbe33ae0f205409e1e4c47ad627b4849b574
5
5
  SHA512:
6
- metadata.gz: 311d59891c2b4cd2b30c828d5e4c264cfbd22e97f235f23d4cda3c4646f48507d849b158e0234857c071b30b7b49a4215121c1031500e0e45cb0ef6d5f82b489
7
- data.tar.gz: 99efdb44a13c364905e7953bf496233f6986544649556505ae07dd330b9b15cd72304a0df36af7471ea695e1c387bf3fd85b9a5a4955bd680f9897323a314dc8
6
+ metadata.gz: 9376fa5ff793d02f983d80b084f7349e3d6ba3c203915c24aaa56c249d6f932204f81a398b07837c22faf96ac0579f65cae0238d7ecc113e11942316c424b484
7
+ data.tar.gz: e390b92e01f27a8f3065bb78f68bc2b33981ede0e7914905ee5d37ef51abd3062417c1406e9554b9ab1d334bb6f7eea91e4d18a8aab90da2a008ea64c4ce54db
data/README.md CHANGED
@@ -24,8 +24,8 @@ Or install it yourself as:
24
24
 
25
25
  You can install links to your app into the navigation on Cobot. When users click the link an iframe pointing to the given `iframe_url` will be shown.
26
26
 
27
- client = OAuth2::Client.new <...>
28
- CobotClient::NavigationLinkService.new(client, '<access token>', 'co-up').install_links [
27
+ client = CobotClient::ApiClient.new <access token>
28
+ CobotClient::NavigationLinkService.new(client, 'co-up').install_links [
29
29
  CobotClient::NavigationLink.new(section: 'admin/manage', label: 'My App', iframe_url: 'http://example.com')]
30
30
 
31
31
  ### Setting up automatic iframe resizing
@@ -64,9 +64,15 @@ There is a module `CobotClient::UrlHelper`. After you include it you can call `c
64
64
 
65
65
  ### Calling the API
66
66
 
67
- CobotClient::ApiClient.new('<access token>').list_resources('<subdomain>')
67
+ At the moment there are only a few high-level methods. For more details see the specs.
68
68
 
69
- For more details see the specs.
69
+ client = CobotClient::ApiClient.new('<access token>')
70
+ client.list_resources('<subdomain>')
71
+
72
+ For everything else you can use the low-level get/post/put/delete metods:
73
+
74
+ client.get 'www', '/user'
75
+ client.post 'my-subdomain', '/users', {"email": "joe@doe.com"}
70
76
 
71
77
  ## Contributing
72
78
 
@@ -3,13 +3,10 @@ require 'oauth2'
3
3
  module CobotClient
4
4
  # Used to install links into the Cobot navigation of a space.
5
5
  class NavigationLinkService
6
- include UrlHelper
7
-
8
- # oauth_client - an OAuth2::Client
6
+ # oauth_client - an CobotClient::ApiClient
9
7
  # access_token - an access token string (owner must be admin of the space to be used)
10
- def initialize(oauth_client, access_token, space_sudomain)
11
- @oauth_client = oauth_client
12
- @access_token = access_token
8
+ def initialize(api_client, space_sudomain)
9
+ @api_client = api_client
13
10
  @subdomain = space_sudomain
14
11
  end
15
12
 
@@ -30,31 +27,19 @@ module CobotClient
30
27
  private
31
28
 
32
29
  def get_links
33
- token.get(cobot_url(@subdomain, "/api/navigation_links")).parsed.map do |attributes|
30
+ @api_client.get(@subdomain, "/navigation_links").map do |attributes|
34
31
  NavigationLink.new attributes
35
32
  end
36
33
  end
37
34
 
38
35
  def create_link(link)
39
- response = token.post(cobot_url(@subdomain, '/api/navigation_links'), body: {
36
+ response = @api_client.post(@subdomain, '/navigation_links',
40
37
  section: link.section,
41
38
  label: link.label,
42
39
  iframe_url: link.iframe_url
43
- })
44
-
45
- unless successful?(response)
46
- raise "Error installing link: #{response.body}"
47
- end
48
-
49
- NavigationLink.new response.parsed
50
- end
51
-
52
- def token
53
- @token ||= OAuth2::AccessToken.new(@oauth_client, @access_token)
54
- end
40
+ )
55
41
 
56
- def successful?(response)
57
- [200, 201].include?(response.status)
42
+ NavigationLink.new response
58
43
  end
59
44
  end
60
45
  end
@@ -1,3 +1,3 @@
1
1
  module CobotClient
2
- VERSION = "0.8.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -1,23 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe CobotClient::NavigationLinkService, '#install_links' do
4
- let(:service) { CobotClient::NavigationLinkService.new(oauth_client, 'token-1', 'co-up') }
5
- let(:oauth_client) { double(:oauth_client) }
6
-
7
- before(:each) do
8
- @token = double(:token).as_null_object
9
- OAuth2::AccessToken.stub(new: @token)
10
- end
4
+ let(:service) { CobotClient::NavigationLinkService.new(api_client, 'co-up') }
5
+ let(:api_client) { double(:api_client) }
11
6
 
12
7
  context 'when there are links already' do
13
8
  before(:each) do
14
- @token.stub(:get).with('https://co-up.cobot.me/api/navigation_links') do double(:response, parsed: [
15
- {label: 'test link'}])
16
- end
9
+ api_client.stub(:get).with(
10
+ 'co-up', '/navigation_links') { [{label: 'test link'}] }
17
11
  end
18
12
 
19
13
  it 'installs no links' do
20
- @token.should_not_receive(:post)
14
+ api_client.should_not_receive(:post)
21
15
 
22
16
  service.install_links [double(:link)]
23
17
  end
@@ -29,21 +23,21 @@ describe CobotClient::NavigationLinkService, '#install_links' do
29
23
 
30
24
  context 'when there are no links installed' do
31
25
  let(:link) { double(:link, section: 'admin/manage', label: 'test link', iframe_url: '/test') }
26
+
32
27
  before(:each) do
33
- @token.stub(:get).with('https://co-up.cobot.me/api/navigation_links') { double(:response, parsed: []) }
28
+ api_client.stub(:get).with('co-up', '/navigation_links') { [] }
34
29
  end
35
30
 
36
31
  it 'installs the links' do
37
- @token.should_receive(:post).with('https://co-up.cobot.me/api/navigation_links', body: {
32
+ api_client.should_receive(:post).with('co-up', '/navigation_links', {
38
33
  section: 'admin/manage', label: 'test link', iframe_url: '/test'
39
- }) { double(:response, status: 201, parsed: {}) }
34
+ }) { {} }
40
35
 
41
36
  service.install_links [link]
42
37
  end
43
38
 
44
39
  it 'returns the links created' do
45
- response = double(:response, status: 201, parsed: {label: 'test link'})
46
- @token.stub(:post) { response }
40
+ api_client.stub(:post) { {label: 'test link'} }
47
41
 
48
42
  expect(service.install_links([link]).map(&:label)).to eql(['test link'])
49
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: 0.8.0
4
+ version: 1.0.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-22 00:00:00.000000000 Z
11
+ date: 2014-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus