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 +4 -4
- data/README.md +4 -0
- data/lib/cobot_client/api_client.rb +46 -8
- data/lib/cobot_client/navigation_link_service.rb +1 -1
- data/lib/cobot_client/version.rb +1 -1
- data/spec/cobot_client/api_client_spec.rb +37 -0
- 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: 01c5e183c0d951a2b1d0670e521e416ce12c5763
|
4
|
+
data.tar.gz: ec90ac312c8481a42cc17b8027db038a3d2f415e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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
|
-
|
41
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
#
|
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
|
data/lib/cobot_client/version.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2014-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|