restpack_web 0.0.5 → 0.2.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +14 -6
- data/.gitignore +1 -1
- data/Gemfile +0 -2
- data/LICENSE +22 -0
- data/README.md +29 -2
- data/Rakefile +39 -2
- data/lib/restpack_web/app.rb +67 -0
- data/lib/restpack_web/context.rb +90 -53
- data/lib/restpack_web/rails/controller.rb +13 -9
- data/lib/restpack_web/sinatra/app.rb +16 -9
- data/lib/restpack_web/test_support.rb +26 -0
- data/lib/restpack_web/version.rb +2 -2
- data/lib/restpack_web.rb +1 -6
- data/restpack_web.gemspec +24 -23
- data/spec/fixtures/channels.json +354 -0
- data/spec/fixtures/configurations_root.json +59 -0
- data/spec/fixtures/domains_search.json +40 -0
- data/spec/fixtures/users.json +14 -0
- data/spec/lib/restpack_web_spec.rb +39 -0
- data/spec/lib/test_support_spec.rb +23 -0
- data/spec/spec_helper.rb +8 -0
- metadata +94 -55
- data/LICENSE.txt +0 -22
- data/lib/restpack_web/configuration.rb +0 -16
- data/lib/restpack_web/rack/domain.rb +0 -36
- data/lib/restpack_web/rack/session.rb +0 -7
- data/lib/restpack_web/rack/user.rb +0 -35
@@ -0,0 +1,354 @@
|
|
1
|
+
{
|
2
|
+
"channels": [
|
3
|
+
{
|
4
|
+
"id": "1",
|
5
|
+
"name": "RestPack Sample Apps",
|
6
|
+
"href": "/api/v1/channels/1.json"
|
7
|
+
},
|
8
|
+
{
|
9
|
+
"id": "2",
|
10
|
+
"name": "Irish Developer Jobs",
|
11
|
+
"href": "/api/v1/channels/2.json"
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"id": "3",
|
15
|
+
"name": "Beer Roulette",
|
16
|
+
"href": "/api/v1/channels/3.json"
|
17
|
+
}
|
18
|
+
],
|
19
|
+
"meta": {
|
20
|
+
"channels": {
|
21
|
+
"page": 1,
|
22
|
+
"page_size": 50,
|
23
|
+
"count": 3,
|
24
|
+
"includes": [
|
25
|
+
"applications",
|
26
|
+
"domains",
|
27
|
+
"configurations"
|
28
|
+
],
|
29
|
+
"page_count": 1,
|
30
|
+
"previous_page": null,
|
31
|
+
"next_page": null,
|
32
|
+
"previous_href": null,
|
33
|
+
"next_href": null
|
34
|
+
},
|
35
|
+
"applications": {
|
36
|
+
"page": 1,
|
37
|
+
"page_size": 50,
|
38
|
+
"count": 4,
|
39
|
+
"includes": [],
|
40
|
+
"page_count": 1,
|
41
|
+
"previous_page": null,
|
42
|
+
"next_page": null,
|
43
|
+
"previous_href": null,
|
44
|
+
"next_href": null
|
45
|
+
},
|
46
|
+
"domains": {
|
47
|
+
"page": 1,
|
48
|
+
"page_size": 50,
|
49
|
+
"count": 9,
|
50
|
+
"includes": [],
|
51
|
+
"page_count": 1,
|
52
|
+
"previous_page": null,
|
53
|
+
"next_page": null,
|
54
|
+
"previous_href": null,
|
55
|
+
"next_href": null
|
56
|
+
},
|
57
|
+
"configurations": {
|
58
|
+
"page": 1,
|
59
|
+
"page_size": 50,
|
60
|
+
"count": 7,
|
61
|
+
"includes": [],
|
62
|
+
"page_count": 1,
|
63
|
+
"previous_page": null,
|
64
|
+
"next_page": null,
|
65
|
+
"previous_href": null,
|
66
|
+
"next_href": null
|
67
|
+
}
|
68
|
+
},
|
69
|
+
"links": {
|
70
|
+
"channels.applications": {
|
71
|
+
"href": "/api/v1/applications.json?channel_id={channels.id}",
|
72
|
+
"type": "applications"
|
73
|
+
},
|
74
|
+
"channels.domains": {
|
75
|
+
"href": "/api/v1/domains.json?channel_id={channels.id}",
|
76
|
+
"type": "domains"
|
77
|
+
},
|
78
|
+
"channels.configurations": {
|
79
|
+
"href": "/api/v1/configurations.json?channel_id={channels.id}",
|
80
|
+
"type": "configurations"
|
81
|
+
},
|
82
|
+
"applications.channel": {
|
83
|
+
"href": "/api/v1/channels/{applications.channel}.json",
|
84
|
+
"type": "channels"
|
85
|
+
},
|
86
|
+
"applications.domains": {
|
87
|
+
"href": "/api/v1/domains.json?application_id={applications.id}",
|
88
|
+
"type": "domains"
|
89
|
+
},
|
90
|
+
"applications.configurations": {
|
91
|
+
"href": "/api/v1/configurations.json?application_id={applications.id}",
|
92
|
+
"type": "configurations"
|
93
|
+
},
|
94
|
+
"domains.channel": {
|
95
|
+
"href": "/api/v1/channels/{domains.channel}.json",
|
96
|
+
"type": "channels"
|
97
|
+
},
|
98
|
+
"domains.application": {
|
99
|
+
"href": "/api/v1/applications/{domains.application}.json",
|
100
|
+
"type": "applications"
|
101
|
+
},
|
102
|
+
"domains.configurations": {
|
103
|
+
"href": "/api/v1/configurations.json?domain_id={domains.id}",
|
104
|
+
"type": "configurations"
|
105
|
+
},
|
106
|
+
"configurations.channel": {
|
107
|
+
"href": "/api/v1/channels/{configurations.channel}.json",
|
108
|
+
"type": "channels"
|
109
|
+
},
|
110
|
+
"configurations.application": {
|
111
|
+
"href": "/api/v1/applications/{configurations.application}.json",
|
112
|
+
"type": "applications"
|
113
|
+
},
|
114
|
+
"configurations.domain": {
|
115
|
+
"href": "/api/v1/domains/{configurations.domain}.json",
|
116
|
+
"type": "domains"
|
117
|
+
}
|
118
|
+
},
|
119
|
+
"applications": [
|
120
|
+
{
|
121
|
+
"id": "1",
|
122
|
+
"name": "Simple Sinatra App",
|
123
|
+
"href": "/api/v1/applications/1.json",
|
124
|
+
"links": {
|
125
|
+
"channel": "1"
|
126
|
+
}
|
127
|
+
},
|
128
|
+
{
|
129
|
+
"id": "2",
|
130
|
+
"name": "Ruby Jobs",
|
131
|
+
"href": "/api/v1/applications/2.json",
|
132
|
+
"links": {
|
133
|
+
"channel": "2"
|
134
|
+
}
|
135
|
+
},
|
136
|
+
{
|
137
|
+
"id": "3",
|
138
|
+
"name": "Python Jobs",
|
139
|
+
"href": "/api/v1/applications/3.json",
|
140
|
+
"links": {
|
141
|
+
"channel": "2"
|
142
|
+
}
|
143
|
+
},
|
144
|
+
{
|
145
|
+
"id": "4",
|
146
|
+
"name": "Beer Roulette",
|
147
|
+
"href": "/api/v1/applications/4.json",
|
148
|
+
"links": {
|
149
|
+
"channel": "3"
|
150
|
+
}
|
151
|
+
}
|
152
|
+
],
|
153
|
+
"domains": [
|
154
|
+
{
|
155
|
+
"id": "1",
|
156
|
+
"host": "sinatra.restpack-sample.org",
|
157
|
+
"href": "/api/v1/domains/1.json",
|
158
|
+
"links": {
|
159
|
+
"channel": "1",
|
160
|
+
"application": "1"
|
161
|
+
}
|
162
|
+
},
|
163
|
+
{
|
164
|
+
"id": "2",
|
165
|
+
"host": "rails.restpack-sample.org",
|
166
|
+
"href": "/api/v1/domains/2.json",
|
167
|
+
"links": {
|
168
|
+
"channel": "1",
|
169
|
+
"application": "1"
|
170
|
+
}
|
171
|
+
},
|
172
|
+
{
|
173
|
+
"id": "3",
|
174
|
+
"host": "auth.restpack-sample.org",
|
175
|
+
"href": "/api/v1/domains/3.json",
|
176
|
+
"links": {
|
177
|
+
"channel": "1",
|
178
|
+
"application": "1"
|
179
|
+
}
|
180
|
+
},
|
181
|
+
{
|
182
|
+
"id": "4",
|
183
|
+
"host": "www.rubyjobs.io",
|
184
|
+
"href": "/api/v1/domains/4.json",
|
185
|
+
"links": {
|
186
|
+
"channel": "2",
|
187
|
+
"application": "2"
|
188
|
+
}
|
189
|
+
},
|
190
|
+
{
|
191
|
+
"id": "5",
|
192
|
+
"host": "auth.rubyjobs.io",
|
193
|
+
"href": "/api/v1/domains/5.json",
|
194
|
+
"links": {
|
195
|
+
"channel": "2",
|
196
|
+
"application": "2"
|
197
|
+
}
|
198
|
+
},
|
199
|
+
{
|
200
|
+
"id": "6",
|
201
|
+
"host": "www.pythonjobs.io",
|
202
|
+
"href": "/api/v1/domains/6.json",
|
203
|
+
"links": {
|
204
|
+
"channel": "2",
|
205
|
+
"application": "3"
|
206
|
+
}
|
207
|
+
},
|
208
|
+
{
|
209
|
+
"id": "7",
|
210
|
+
"host": "auth.pythonjobs.io",
|
211
|
+
"href": "/api/v1/domains/7.json",
|
212
|
+
"links": {
|
213
|
+
"channel": "2",
|
214
|
+
"application": "3"
|
215
|
+
}
|
216
|
+
},
|
217
|
+
{
|
218
|
+
"id": "8",
|
219
|
+
"host": "www.beer-roulette.io",
|
220
|
+
"href": "/api/v1/domains/8.json",
|
221
|
+
"links": {
|
222
|
+
"channel": "3",
|
223
|
+
"application": "4"
|
224
|
+
}
|
225
|
+
},
|
226
|
+
{
|
227
|
+
"id": "9",
|
228
|
+
"host": "auth.beer-roulette.io",
|
229
|
+
"href": "/api/v1/domains/9.json",
|
230
|
+
"links": {
|
231
|
+
"channel": "3",
|
232
|
+
"application": "4"
|
233
|
+
}
|
234
|
+
}
|
235
|
+
],
|
236
|
+
"configurations": [
|
237
|
+
{
|
238
|
+
"id": "2",
|
239
|
+
"key": "domains",
|
240
|
+
"value": {
|
241
|
+
"home": "sinatra.restpack-sample.org",
|
242
|
+
"auth": "auth.restpack-sample.org"
|
243
|
+
},
|
244
|
+
"href": "/api/v1/configurations/2.json",
|
245
|
+
"links": {
|
246
|
+
"channel": "1",
|
247
|
+
"application": "1",
|
248
|
+
"domain": ""
|
249
|
+
}
|
250
|
+
},
|
251
|
+
{
|
252
|
+
"id": "3",
|
253
|
+
"key": "omniauth",
|
254
|
+
"value": {
|
255
|
+
"twitter": {
|
256
|
+
"consumer_key": "ldgpkTRjhslbNkRQXqldig",
|
257
|
+
"consumer_secret": "bYETiBG4TLpo5kXEXlr7ZgpBnDz0Ajo9hhKq7ypjyM"
|
258
|
+
},
|
259
|
+
"google_oauth2": {
|
260
|
+
"consumer_key": "597265966348.apps.googleusercontent.com",
|
261
|
+
"consumer_secret": "F6fzVpkzsHf-S3vi-ijdUn9-"
|
262
|
+
}
|
263
|
+
},
|
264
|
+
"href": "/api/v1/configurations/3.json",
|
265
|
+
"links": {
|
266
|
+
"channel": "1",
|
267
|
+
"application": "1",
|
268
|
+
"domain": ""
|
269
|
+
}
|
270
|
+
},
|
271
|
+
{
|
272
|
+
"id": "4",
|
273
|
+
"key": "domains",
|
274
|
+
"value": {
|
275
|
+
"home": "www.rubyjobs.io:8080",
|
276
|
+
"auth": "auth.rubyjobs.io:8081"
|
277
|
+
},
|
278
|
+
"href": "/api/v1/configurations/4.json",
|
279
|
+
"links": {
|
280
|
+
"channel": "2",
|
281
|
+
"application": "2",
|
282
|
+
"domain": ""
|
283
|
+
}
|
284
|
+
},
|
285
|
+
{
|
286
|
+
"id": "5",
|
287
|
+
"key": "omniauth",
|
288
|
+
"value": {
|
289
|
+
"twitter": {
|
290
|
+
"consumer_key": "aaaaaaaaaaaaaaa",
|
291
|
+
"consumer_secret": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
|
292
|
+
},
|
293
|
+
"google_oauth2": {
|
294
|
+
"consumer_key": "ccccccccccccccc",
|
295
|
+
"consumer_secret": "dddddddddddddddddddddddddddddd"
|
296
|
+
}
|
297
|
+
},
|
298
|
+
"href": "/api/v1/configurations/5.json",
|
299
|
+
"links": {
|
300
|
+
"channel": "2",
|
301
|
+
"application": "2",
|
302
|
+
"domain": ""
|
303
|
+
}
|
304
|
+
},
|
305
|
+
{
|
306
|
+
"id": "6",
|
307
|
+
"key": "domains",
|
308
|
+
"value": {
|
309
|
+
"home": "www.pythonjobs.io:8080",
|
310
|
+
"auth": "auth.pythonjobs.io:8081"
|
311
|
+
},
|
312
|
+
"href": "/api/v1/configurations/6.json",
|
313
|
+
"links": {
|
314
|
+
"channel": "2",
|
315
|
+
"application": "3",
|
316
|
+
"domain": ""
|
317
|
+
}
|
318
|
+
},
|
319
|
+
{
|
320
|
+
"id": "7",
|
321
|
+
"key": "omniauth",
|
322
|
+
"value": {
|
323
|
+
"twitter": {
|
324
|
+
"consumer_key": "eeeeeeeeeeeeeeee",
|
325
|
+
"consumer_secret": "fffffffffffffffffffffffffffffff"
|
326
|
+
},
|
327
|
+
"google_oauth2": {
|
328
|
+
"consumer_key": "gggggggggggggggggggggggggggggggggg",
|
329
|
+
"consumer_secret": "hhhhhhhhhhhhh"
|
330
|
+
}
|
331
|
+
},
|
332
|
+
"href": "/api/v1/configurations/7.json",
|
333
|
+
"links": {
|
334
|
+
"channel": "2",
|
335
|
+
"application": "3",
|
336
|
+
"domain": ""
|
337
|
+
}
|
338
|
+
},
|
339
|
+
{
|
340
|
+
"id": "8",
|
341
|
+
"key": "domains",
|
342
|
+
"value": {
|
343
|
+
"home": "www.beer-roulette.io:8090",
|
344
|
+
"auth": "auth.beer-roulette.io:8081"
|
345
|
+
},
|
346
|
+
"href": "/api/v1/configurations/8.json",
|
347
|
+
"links": {
|
348
|
+
"channel": "3",
|
349
|
+
"application": "4",
|
350
|
+
"domain": ""
|
351
|
+
}
|
352
|
+
}
|
353
|
+
]
|
354
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
{
|
2
|
+
"configurations": [
|
3
|
+
{
|
4
|
+
"id": "1",
|
5
|
+
"key": "services",
|
6
|
+
"value": [
|
7
|
+
{
|
8
|
+
"name": "restpack-core-service",
|
9
|
+
"domain": "core.restpack-sample.org"
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"name": "restpack-user-service",
|
13
|
+
"domain": "users.restpack-sample.org"
|
14
|
+
},
|
15
|
+
{
|
16
|
+
"name": "restpack-group-service",
|
17
|
+
"domain": "groups.restpack-sample.org"
|
18
|
+
},
|
19
|
+
{
|
20
|
+
"name": "restpack-activity-service",
|
21
|
+
"domain": "activity.restpack-sample.org"
|
22
|
+
}
|
23
|
+
],
|
24
|
+
"href": "/api/v1/configurations/1.json",
|
25
|
+
"links": {
|
26
|
+
"channel": "",
|
27
|
+
"application": "",
|
28
|
+
"domain": ""
|
29
|
+
}
|
30
|
+
}
|
31
|
+
],
|
32
|
+
"meta": {
|
33
|
+
"configurations": {
|
34
|
+
"page": 1,
|
35
|
+
"page_size": 50,
|
36
|
+
"count": 1,
|
37
|
+
"includes": [],
|
38
|
+
"page_count": 1,
|
39
|
+
"previous_page": null,
|
40
|
+
"next_page": null,
|
41
|
+
"previous_href": null,
|
42
|
+
"next_href": null
|
43
|
+
}
|
44
|
+
},
|
45
|
+
"links": {
|
46
|
+
"configurations.channel": {
|
47
|
+
"href": "/api/v1/channels/{configurations.channel}.json",
|
48
|
+
"type": "channels"
|
49
|
+
},
|
50
|
+
"configurations.application": {
|
51
|
+
"href": "/api/v1/applications/{configurations.application}.json",
|
52
|
+
"type": "applications"
|
53
|
+
},
|
54
|
+
"configurations.domain": {
|
55
|
+
"href": "/api/v1/domains/{configurations.domain}.json",
|
56
|
+
"type": "domains"
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
{
|
2
|
+
"domains": [
|
3
|
+
{
|
4
|
+
"id": "1",
|
5
|
+
"host": "sinatra.restpack-sample.org",
|
6
|
+
"href": "/api/v1/domains/1.json",
|
7
|
+
"links": {
|
8
|
+
"channel": "1",
|
9
|
+
"application": "1"
|
10
|
+
}
|
11
|
+
}
|
12
|
+
],
|
13
|
+
"meta": {
|
14
|
+
"domains": {
|
15
|
+
"page": 1,
|
16
|
+
"page_size": 50,
|
17
|
+
"count": 1,
|
18
|
+
"includes": [],
|
19
|
+
"page_count": 1,
|
20
|
+
"previous_page": null,
|
21
|
+
"next_page": null,
|
22
|
+
"previous_href": null,
|
23
|
+
"next_href": null
|
24
|
+
}
|
25
|
+
},
|
26
|
+
"links": {
|
27
|
+
"domains.channel": {
|
28
|
+
"href": "/api/v1/channels/{domains.channel}.json",
|
29
|
+
"type": "channels"
|
30
|
+
},
|
31
|
+
"domains.application": {
|
32
|
+
"href": "/api/v1/applications/{domains.application}.json",
|
33
|
+
"type": "applications"
|
34
|
+
},
|
35
|
+
"domains.configurations": {
|
36
|
+
"href": "/api/v1/configurations.json?domain_id={domains.id}",
|
37
|
+
"type": "configurations"
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"user": {
|
3
|
+
"id":1,
|
4
|
+
"channel_id":1,
|
5
|
+
"description":null,
|
6
|
+
"email":"lukasz.krystkowiak@gmail.com",
|
7
|
+
"image":null,
|
8
|
+
"avatar":"http://robohash.org/1.png?size=200x200",
|
9
|
+
"location":null,
|
10
|
+
"name":"Lukasz",
|
11
|
+
"nickname":"lukkry",
|
12
|
+
"url":"/api/v1/users/1.json"
|
13
|
+
}
|
14
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require "rack/test"
|
3
|
+
require 'restpack_web/test_support'
|
4
|
+
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
describe RestPack::Web do
|
8
|
+
let(:app) {
|
9
|
+
RestPack::Web::App.new(
|
10
|
+
lambda { |env| [200, {'Content-Type' => 'text/plain'}, 'hello world'] },
|
11
|
+
{ core_domain: ENV['RESTPACK_CORE_SERVICE'], password: ENV['RESTPACK_ACCESS_KEY'] })
|
12
|
+
}
|
13
|
+
|
14
|
+
before do
|
15
|
+
RestPack::Web::TestSupport.stub_restpack_web
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns a valid response" do
|
19
|
+
get '/'
|
20
|
+
last_response.ok?.must_equal true
|
21
|
+
last_response.body.must_equal 'hello world'
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#add_user' do
|
25
|
+
let(:users_path){ File.expand_path('./spec/fixtures/users.json') }
|
26
|
+
|
27
|
+
before do
|
28
|
+
stub_request(:get, 'http://auth.restpack-sample.org/api/v1/users/1.json').
|
29
|
+
to_return(:body => File.read(users_path))
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'inject an user into env' do
|
33
|
+
get '/', {}, 'rack.session' => { :user_id => 1 }
|
34
|
+
last_request.env[:restpack][:user_id].must_equal 1
|
35
|
+
last_request.env[:restpack][:user]['email'].must_equal 'lukasz.krystkowiak@gmail.com'
|
36
|
+
last_request.env[:restpack][:user]['nickname'].must_equal 'lukkry'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'restpack_web/test_support'
|
5
|
+
|
6
|
+
describe RestPack::Web::TestSupport do
|
7
|
+
let(:configurations_root_path){ File.expand_path('./spec/fixtures/configurations_root.json') }
|
8
|
+
let(:domains_search_path){ File.expand_path('./spec/fixtures/domains_search.json') }
|
9
|
+
let(:channels_path){ File.expand_path('./spec/fixtures/channels.json') }
|
10
|
+
|
11
|
+
describe '#stub_restpack_web' do
|
12
|
+
before do
|
13
|
+
RestPack::Web::TestSupport.stub_restpack_web
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'stub all requests to the core service' do
|
17
|
+
host = "http://:#{ENV['RESTPACK_ACCESS_KEY']}@#{ENV['RESTPACK_CORE_SERVICE']}/api/v1"
|
18
|
+
RestClient.get("#{host}/configurations/root.json").must_equal File.read(configurations_root_path)
|
19
|
+
RestClient.get("#{host}/domains/search.json?host=sinatra.restpack-sample.org").must_equal File.read(domains_search_path)
|
20
|
+
RestClient.get("#{host}/channels/1.json").must_equal File.read(channels_path)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|