cobot_client 1.0.0 → 1.1.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: d97efe9d55e36afb226b47dfd1b27fb96a6ca8e5
4
- data.tar.gz: a930cbe33ae0f205409e1e4c47ad627b4849b574
3
+ metadata.gz: 01c5e183c0d951a2b1d0670e521e416ce12c5763
4
+ data.tar.gz: ec90ac312c8481a42cc17b8027db038a3d2f415e
5
5
  SHA512:
6
- metadata.gz: 9376fa5ff793d02f983d80b084f7349e3d6ba3c203915c24aaa56c249d6f932204f81a398b07837c22faf96ac0579f65cae0238d7ecc113e11942316c424b484
7
- data.tar.gz: e390b92e01f27a8f3065bb78f68bc2b33981ede0e7914905ee5d37ef51abd3062417c1406e9554b9ab1d334bb6f7eea91e4d18a8aab90da2a008ea64c4ce54db
6
+ metadata.gz: 1968d198e816a0d3712fcfb1cf2790d273568a8b5565d21f8b4612dcd1a0e1c7c5677f94b500d5a3d605713a2826dd3a057ad8a72c9806a2def04224c4f7c653
7
+ data.tar.gz: 93d4f4a79520d93d1170263aeae5e98dfb9d53837a15133270f4cf9130d074fe9c234b901e1cc3fe612d4c43d2e117916b3383f871c9f924d5ddea72e001f2c9
data/README.md CHANGED
@@ -74,6 +74,10 @@ For everything else you can use the low-level get/post/put/delete metods:
74
74
  client.get 'www', '/user'
75
75
  client.post 'my-subdomain', '/users', {"email": "joe@doe.com"}
76
76
 
77
+ You can also pass a URL instead of subdomain/path:
78
+
79
+ client.get 'https://www/cobot.me/user'
80
+
77
81
  ## Contributing
78
82
 
79
83
  1. Fork it
@@ -29,35 +29,73 @@ module CobotClient
29
29
  delete subdomain, "/bookings/#{id}"
30
30
  end
31
31
 
32
- def put(subdomain, path, body)
32
+ # args: either a full URL or subdomain, path, plus a body as hash
33
+ def put(*args)
34
+ url, subdomain, path, body = parse_args *args
33
35
  JSON.parse RestClient.put(
34
- cobot_url(subdomain, "/api#{path}"),
36
+ build_url(url || subdomain, path),
35
37
  body.to_json,
36
38
  headers.merge(content_type_header)).body,
37
39
  symbolize_names: true
38
40
  end
39
41
 
40
- def delete(subdomain, path)
41
- RestClient.delete(cobot_url(subdomain, "/api#{path}"), headers)
42
+ # args: either a full URL or subdomain, path
43
+ def delete(*args)
44
+ url, subdomain, path, _ = parse_args *args
45
+ RestClient.delete(build_url(url || subdomain, path), headers)
42
46
  end
43
47
 
44
- def post(subdomain, path, body)
48
+ # args: either a full URL or subdomain, path, plus a body as hash
49
+ def post(*args)
50
+ url, subdomain, path, body = parse_args *args
45
51
  JSON.parse RestClient.post(
46
- cobot_url(subdomain, "/api#{path}"),
52
+ build_url(url || subdomain, path),
47
53
  body.to_json,
48
54
  headers.merge(content_type_header)).body,
49
55
  symbolize_names: true
50
56
  end
51
57
 
52
- def get(subdomain, path, params = {})
58
+ # args: either a full URL or subdomain, path, plus an optional params hash
59
+ def get(*args)
60
+ url, subdomain, path, params = parse_args *args
53
61
  JSON.parse(
54
62
  RestClient.get(
55
- cobot_url(subdomain, "/api#{path}", params: params),
63
+ build_url(url || subdomain, path, params),
56
64
  headers).body,
57
65
  symbolize_names: true
58
66
  )
59
67
  end
60
68
 
69
+ private
70
+
71
+ def parse_args(*args)
72
+ if args.last.is_a?(Hash)
73
+ params = args.pop
74
+ else
75
+ params = {}
76
+ end
77
+ if args.size == 1
78
+ url = args[0]
79
+ path = nil
80
+ subdomain = nil
81
+ else
82
+ subdomain = args[0]
83
+ path = args[1]
84
+ url = nil
85
+ end
86
+ [url, subdomain, path, params]
87
+ end
88
+
89
+ def build_url(subdomain_or_url, path, params = {})
90
+ if path
91
+ cobot_url(subdomain_or_url, "/api#{path}", params: params)
92
+ else
93
+ uri = URI.parse(subdomain_or_url)
94
+ uri.query = URI.encode_www_form(params) if params && params.any?
95
+ uri.to_s
96
+ end
97
+ end
98
+
61
99
  def content_type_header
62
100
  {'Content-Type' => 'application/json'}
63
101
  end
@@ -3,7 +3,7 @@ require 'oauth2'
3
3
  module CobotClient
4
4
  # Used to install links into the Cobot navigation of a space.
5
5
  class NavigationLinkService
6
- # oauth_client - an CobotClient::ApiClient
6
+ # api_client - an CobotClient::ApiClient
7
7
  # access_token - an access token string (owner must be admin of the space to be used)
8
8
  def initialize(api_client, space_sudomain)
9
9
  @api_client = api_client
@@ -1,3 +1,3 @@
1
1
  module CobotClient
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -83,6 +83,17 @@ describe CobotClient::ApiClient do
83
83
  api_client.put 'co-up', '/invoices', {id: '1'}
84
84
  end
85
85
 
86
+ it 'accepts a url' do
87
+ RestClient.should_receive(:put).with(
88
+ 'https://co-up.cobot.me/api/invoices',
89
+ {id: '1'}.to_json,
90
+ 'Content-Type' => 'application/json',
91
+ 'User-Agent' => 'test agent',
92
+ 'Authorization' => 'Bearer token-123') { default_response }
93
+
94
+ api_client.put 'https://co-up.cobot.me/api/invoices', {id: '1'}
95
+ end
96
+
86
97
  it 'returns the response json' do
87
98
  RestClient.stub(:put) { double(:response, body: [{number: 1}].to_json) }
88
99
 
@@ -102,6 +113,17 @@ describe CobotClient::ApiClient do
102
113
  api_client.post 'co-up', '/invoices', {id: '1'}
103
114
  end
104
115
 
116
+ it 'accepts a url' do
117
+ RestClient.should_receive(:post).with(
118
+ 'https://co-up.cobot.me/api/invoices',
119
+ {id: '1'}.to_json,
120
+ 'Content-Type' => 'application/json',
121
+ 'User-Agent' => 'test agent',
122
+ 'Authorization' => 'Bearer token-123') { default_response }
123
+
124
+ api_client.post 'https://co-up.cobot.me/api/invoices', {id: '1'}
125
+ end
126
+
105
127
  it 'returns the response json' do
106
128
  RestClient.stub(:post) { double(:response, body: [{number: 1}].to_json) }
107
129
 
@@ -117,6 +139,13 @@ describe CobotClient::ApiClient do
117
139
  api_client.get 'co-up', '/invoices', {from: '2013-10-6', to: '2013-10-12'}
118
140
  end
119
141
 
142
+ 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',
144
+ 'User-Agent' => 'test agent', 'Authorization' => 'Bearer token-123') { default_response }
145
+
146
+ api_client.get 'https://co-up.cobot.me/api/invoices', {from: '2013-10-6', to: '2013-10-12'}
147
+ end
148
+
120
149
  it 'returns the response json' do
121
150
  RestClient.stub(:get) { double(:response, body: [{number: 1}].to_json) }
122
151
 
@@ -132,5 +161,13 @@ describe CobotClient::ApiClient do
132
161
 
133
162
  api_client.delete 'co-up', '/invoices/1'
134
163
  end
164
+
165
+ it 'accepts a url' do
166
+ RestClient.should_receive(:delete).with(
167
+ 'https://co-up.cobot.me/api/invoices/1',
168
+ 'User-Agent' => 'test agent', 'Authorization' => 'Bearer token-123') { default_response }
169
+
170
+ api_client.delete 'https://co-up.cobot.me/api/invoices/1'
171
+ end
135
172
  end
136
173
  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.0.0
4
+ version: 1.1.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-23 00:00:00.000000000 Z
11
+ date: 2014-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus