moonrope 1.4.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +9 -0
  3. data/Gemfile.lock +47 -0
  4. data/MIT-LICENCE +20 -0
  5. data/README.md +24 -0
  6. data/bin/moonrope +28 -0
  7. data/docs/authentication.md +114 -0
  8. data/docs/controllers.md +106 -0
  9. data/docs/exceptions.md +27 -0
  10. data/docs/introduction.md +29 -0
  11. data/docs/structures.md +214 -0
  12. data/example/authentication.rb +50 -0
  13. data/example/controllers/meta_controller.rb +14 -0
  14. data/example/controllers/users_controller.rb +92 -0
  15. data/example/structures/pet_structure.rb +12 -0
  16. data/example/structures/user_structure.rb +35 -0
  17. data/html/assets/lock.svg +3 -0
  18. data/html/assets/reset.css +101 -0
  19. data/html/assets/style.css +348 -0
  20. data/html/assets/tool.svg +4 -0
  21. data/html/assets/try.js +151 -0
  22. data/html/authenticators/default.html +191 -0
  23. data/html/controllers/meta/version.html +144 -0
  24. data/html/controllers/meta.html +73 -0
  25. data/html/controllers/users/create.html +341 -0
  26. data/html/controllers/users/list.html +348 -0
  27. data/html/controllers/users/show.html +261 -0
  28. data/html/controllers/users/update.html +387 -0
  29. data/html/controllers/users.html +93 -0
  30. data/html/index.html +166 -0
  31. data/html/moonrope.txt +0 -0
  32. data/html/structures/pet.html +176 -0
  33. data/html/structures/user.html +338 -0
  34. data/lib/moonrope/action.rb +165 -37
  35. data/lib/moonrope/authenticator.rb +39 -0
  36. data/lib/moonrope/base.rb +24 -6
  37. data/lib/moonrope/controller.rb +4 -2
  38. data/lib/moonrope/doc_context.rb +94 -0
  39. data/lib/moonrope/doc_server.rb +123 -0
  40. data/lib/moonrope/dsl/action_dsl.rb +159 -9
  41. data/lib/moonrope/dsl/authenticator_dsl.rb +31 -0
  42. data/lib/moonrope/dsl/base_dsl.rb +21 -18
  43. data/lib/moonrope/dsl/controller_dsl.rb +60 -9
  44. data/lib/moonrope/dsl/filterable_dsl.rb +27 -0
  45. data/lib/moonrope/dsl/structure_dsl.rb +27 -2
  46. data/lib/moonrope/errors.rb +3 -0
  47. data/lib/moonrope/eval_environment.rb +82 -3
  48. data/lib/moonrope/eval_helpers/filter_helper.rb +82 -0
  49. data/lib/moonrope/eval_helpers.rb +28 -5
  50. data/lib/moonrope/guard.rb +35 -0
  51. data/lib/moonrope/html_generator.rb +65 -0
  52. data/lib/moonrope/param_set.rb +11 -1
  53. data/lib/moonrope/rack_middleware.rb +1 -1
  54. data/lib/moonrope/railtie.rb +31 -14
  55. data/lib/moonrope/request.rb +25 -14
  56. data/lib/moonrope/structure.rb +74 -11
  57. data/lib/moonrope/structure_attribute.rb +15 -0
  58. data/lib/moonrope/version.rb +1 -1
  59. data/lib/moonrope.rb +5 -4
  60. data/moonrope.gemspec +21 -0
  61. data/spec/spec_helper.rb +32 -0
  62. data/spec/specs/action_spec.rb +455 -0
  63. data/spec/specs/base_spec.rb +29 -0
  64. data/spec/specs/controller_spec.rb +31 -0
  65. data/spec/specs/param_set_spec.rb +31 -0
  66. data/templates/basic/_action_form.erb +77 -0
  67. data/templates/basic/_errors_table.erb +32 -0
  68. data/templates/basic/_structure_attributes_list.erb +55 -0
  69. data/templates/basic/action.erb +168 -0
  70. data/templates/basic/assets/lock.svg +3 -0
  71. data/templates/basic/assets/reset.css +101 -0
  72. data/templates/basic/assets/style.css +348 -0
  73. data/templates/basic/assets/tool.svg +4 -0
  74. data/templates/basic/assets/try.js +151 -0
  75. data/templates/basic/authenticator.erb +51 -0
  76. data/templates/basic/controller.erb +20 -0
  77. data/templates/basic/index.erb +114 -0
  78. data/templates/basic/layout.erb +46 -0
  79. data/templates/basic/structure.erb +23 -0
  80. data/test/test_helper.rb +81 -0
  81. data/test/tests/action_access_test.rb +63 -0
  82. data/test/tests/actions_test.rb +524 -0
  83. data/test/tests/authenticators_test.rb +87 -0
  84. data/test/tests/base_test.rb +35 -0
  85. data/test/tests/controllers_test.rb +49 -0
  86. data/test/tests/eval_environment_test.rb +136 -0
  87. data/test/tests/evel_helpers_test.rb +60 -0
  88. data/test/tests/examples_test.rb +11 -0
  89. data/test/tests/helpers_test.rb +97 -0
  90. data/test/tests/param_set_test.rb +44 -0
  91. data/test/tests/rack_middleware_test.rb +109 -0
  92. data/test/tests/request_test.rb +232 -0
  93. data/test/tests/structures_param_extensions_test.rb +159 -0
  94. data/test/tests/structures_test.rb +335 -0
  95. metadata +82 -48
@@ -0,0 +1,261 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Get unit information - Users API - API Documentation</title>
5
+ <link href='https://fonts.googleapis.com/css?family=Lato:400,700,900' rel='stylesheet' type='text/css'>
6
+ <link href='https://fonts.googleapis.com/css?family=Droid+Sans+Mono' rel='stylesheet' type='text/css'>
7
+ <link rel="stylesheet" href="../../assets/reset.css">
8
+ <link rel="stylesheet" href="../../assets/style.css">
9
+ </head>
10
+ <body>
11
+ <section class='sidebarBackground'></section>
12
+ <section class="sidebar">
13
+ <nav>
14
+ <ul>
15
+ <li>
16
+ <a href='../../index.html' class="">
17
+ Home
18
+ </a>
19
+ </li>
20
+
21
+ <li>
22
+ <a href='../../authenticators/default.html' class="">
23
+ Authentication
24
+ </a>
25
+ </li>
26
+
27
+
28
+ <li>
29
+ <a href='../../controllers/meta.html' class="">
30
+ Meta API
31
+ </a>
32
+ </li>
33
+
34
+ <li>
35
+ <a href='../../controllers/users.html' class="active">
36
+ Users API
37
+ </a>
38
+ </li>
39
+
40
+ </ul>
41
+ </nav>
42
+ </section>
43
+ <section class='content'>
44
+
45
+
46
+
47
+ <h1>Get unit information</h1>
48
+
49
+
50
+ <p class='tryFormActivate'><a class='tryFormActivate__button' href='#'>Try this request in your browser</a></p>
51
+ <form class='tryForm'>
52
+ <input type='hidden' name='controller' value='users'>
53
+ <input type='hidden' name='action' value='show'>
54
+ <div class='tryForm__header'>
55
+ <input type='text' id='host' name='host' value=''>
56
+ /api/
57
+ <input type='text' id='version' name='version' value='v1' class='v'>
58
+ /users/show
59
+ </div>
60
+
61
+
62
+ <p class='tryForm__heading'>Headers</p>
63
+ <table class='tryForm__table'>
64
+
65
+ <tr>
66
+ <td width="50%"><code>X-Auth-Application</code></td>
67
+ <td width="50%"><input type='text' class='tryForm__tableField headerField' name='X-Auth-Application'></td>
68
+ </tr>
69
+
70
+ <tr>
71
+ <td width="50%"><code>X-Auth-Token</code></td>
72
+ <td width="50%"><input type='text' class='tryForm__tableField headerField' name='X-Auth-Token'></td>
73
+ </tr>
74
+
75
+ </table>
76
+
77
+
78
+
79
+ <p class='tryForm__heading'>Parameters</p>
80
+ <table class='tryForm__table'>
81
+
82
+ <tr>
83
+ <td width="30%"><code>username</code></td>
84
+ <td width="20%">String</td>
85
+ <td width="50%"><input type='text' class='tryForm__tableField paramField' name='username' placeholder='' data-type='String'></td>
86
+ </tr>
87
+
88
+ </table>
89
+
90
+
91
+
92
+ <p class='tryForm__heading'>Structures</p>
93
+ <table class='tryForm__table'>
94
+
95
+ <tr>
96
+ <td width="50%">Include extended attributes?</td>
97
+ <td width="50%">
98
+ <div class='tryForm__checkbox'>
99
+ <input type='checkbox' class='tryForm__fullAttrs' name='full' id="full_attrs" >
100
+ <label for="full_attrs">Yes - include extended attributes</label>
101
+ </div>
102
+ </td>
103
+ </tr>
104
+
105
+
106
+ <tr>
107
+ <td width="50%">Include expansions?</td>
108
+ <td width="50%">
109
+
110
+ <div class='tryForm__checkbox'>
111
+ <input type='checkbox' class='tryForm__expansions' name='pets' id="expan_pets" >
112
+ <label for="expan_pets">pets</label>
113
+ </div>
114
+
115
+ <div class='tryForm__checkbox'>
116
+ <input type='checkbox' class='tryForm__expansions' name='balance' id="expan_balance" >
117
+ <label for="expan_balance">balance</label>
118
+ </div>
119
+
120
+ <div class='tryForm__checkbox'>
121
+ <input type='checkbox' class='tryForm__expansions' name='hidden' id="expan_hidden" >
122
+ <label for="expan_hidden">hidden</label>
123
+ </div>
124
+
125
+ </td>
126
+ </tr>
127
+
128
+
129
+ </table>
130
+
131
+
132
+
133
+ <p class='tryForm__button'>
134
+ <button class='tryForm__buttonLink' type='submit'>Make this request</button>
135
+ <button class='tryForm__buttonLink tryFormCancel' type='button'>Cancel</button>
136
+ </p>
137
+
138
+ <pre class='tryForm__output'>The request output will be shown here...</pre>
139
+ </form>
140
+
141
+
142
+
143
+
144
+ <h2>URL</h2>
145
+ <p class='apiURLFull'><span>/api/v1/</span>users/show</p>
146
+
147
+
148
+
149
+
150
+ <h2>Access</h2>
151
+ <p class='text'>
152
+ Must be authenticated with a valid user API token.
153
+
154
+ If not authorised, a <code>NotAuthenticated</code> error will be returned.
155
+
156
+ </p>
157
+
158
+
159
+
160
+
161
+ <h2>Parameters</h2>
162
+
163
+ <table class='table paramTable'>
164
+ <thead>
165
+ <tr>
166
+ <th width="60%">Parameter</th>
167
+ <th width="20%">Type</th>
168
+ <th width="20%">Default</th>
169
+ </tr>
170
+ </thead>
171
+
172
+ <tr>
173
+ <td>
174
+ <p>
175
+ <span class='paramTable__name'>username</span>
176
+ <span class='paramTable__req'>Required</span>
177
+ </p>
178
+
179
+ <p class='paramTable__description'>The user's username</p>
180
+
181
+ </td>
182
+ <td>String</td>
183
+ <td>
184
+
185
+ <span class='paramTable__nil'>null</span>
186
+
187
+ </td>
188
+ </tr>
189
+
190
+ </table>
191
+
192
+
193
+
194
+
195
+ <h2>Errors</h2>
196
+
197
+
198
+ <table class='table errorsTable'>
199
+ <thead>
200
+ <tr>
201
+ <th width="60%">Error</th>
202
+ <th width="40%">Attributes</th>
203
+ </tr>
204
+ </thead>
205
+
206
+ <tr>
207
+ <td>
208
+ <p>
209
+ <span class='paramTable__name'>UserNotFound</span>
210
+
211
+ <p class='paramTable__description'>No user was found matching the given username</p>
212
+
213
+ </p>
214
+ </td>
215
+ <td>
216
+
217
+ <ul class='errorAttributeList'>
218
+
219
+ <li>
220
+ <p class='errorAttributeList__name'>username</p>
221
+ <p class='errorAttributeList__desc'>The username which was looked up</p>
222
+ </li>
223
+
224
+ </ul>
225
+
226
+ </td>
227
+ </tr>
228
+
229
+ </table>
230
+
231
+
232
+
233
+
234
+ <h2>Response Data</h2>
235
+
236
+
237
+ <p class='text'>This action will return a <a class='link' href='../../structures/user.html'>user structure</a>.</p>
238
+
239
+
240
+
241
+
242
+ <p class='text'>
243
+ You'll receive this structure in the most basic form, without extended data or
244
+ any expansions. You can choose to receive extended attributes by providing the <code>_full</code> parameter. You can
245
+ also choose to receive any expansions by providing an array in the <code>_expansions</code>
246
+ parameter. A full list of expansions can be found on the
247
+ <a class='link' href='../../structures/user.html'>structure page</a>.
248
+ </p>
249
+
250
+
251
+
252
+
253
+
254
+ </section>
255
+ <footer class='footer'>
256
+ <p>Generated by Moonrope at 12:43 on Monday 22 February 2016 for d3c499</p>
257
+ </footer>
258
+ <script src='https://code.jquery.com/jquery-1.12.0.min.js'></script>
259
+ <script src='../../assets/try.js'></script>
260
+ </body>
261
+ </html>
@@ -0,0 +1,387 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Update an existing user - Users API - API Documentation</title>
5
+ <link href='https://fonts.googleapis.com/css?family=Lato:400,700,900' rel='stylesheet' type='text/css'>
6
+ <link href='https://fonts.googleapis.com/css?family=Droid+Sans+Mono' rel='stylesheet' type='text/css'>
7
+ <link rel="stylesheet" href="../../assets/reset.css">
8
+ <link rel="stylesheet" href="../../assets/style.css">
9
+ </head>
10
+ <body>
11
+ <section class='sidebarBackground'></section>
12
+ <section class="sidebar">
13
+ <nav>
14
+ <ul>
15
+ <li>
16
+ <a href='../../index.html' class="">
17
+ Home
18
+ </a>
19
+ </li>
20
+
21
+ <li>
22
+ <a href='../../authenticators/default.html' class="">
23
+ Authentication
24
+ </a>
25
+ </li>
26
+
27
+
28
+ <li>
29
+ <a href='../../controllers/meta.html' class="">
30
+ Meta API
31
+ </a>
32
+ </li>
33
+
34
+ <li>
35
+ <a href='../../controllers/users.html' class="active">
36
+ Users API
37
+ </a>
38
+ </li>
39
+
40
+ </ul>
41
+ </nav>
42
+ </section>
43
+ <section class='content'>
44
+
45
+
46
+
47
+ <h1>Update an existing user</h1>
48
+
49
+ <p class='text'>This action will update an existing user with the properties provided.</p>
50
+
51
+
52
+ <p class='tryFormActivate'><a class='tryFormActivate__button' href='#'>Try this request in your browser</a></p>
53
+ <form class='tryForm'>
54
+ <input type='hidden' name='controller' value='users'>
55
+ <input type='hidden' name='action' value='update'>
56
+ <div class='tryForm__header'>
57
+ <input type='text' id='host' name='host' value=''>
58
+ /api/
59
+ <input type='text' id='version' name='version' value='v1' class='v'>
60
+ /users/update
61
+ </div>
62
+
63
+
64
+ <p class='tryForm__heading'>Headers</p>
65
+ <table class='tryForm__table'>
66
+
67
+ <tr>
68
+ <td width="50%"><code>X-Auth-Application</code></td>
69
+ <td width="50%"><input type='text' class='tryForm__tableField headerField' name='X-Auth-Application'></td>
70
+ </tr>
71
+
72
+ <tr>
73
+ <td width="50%"><code>X-Auth-Token</code></td>
74
+ <td width="50%"><input type='text' class='tryForm__tableField headerField' name='X-Auth-Token'></td>
75
+ </tr>
76
+
77
+ </table>
78
+
79
+
80
+
81
+ <p class='tryForm__heading'>Parameters</p>
82
+ <table class='tryForm__table'>
83
+
84
+ <tr>
85
+ <td width="30%"><code>id</code></td>
86
+ <td width="20%">Integer</td>
87
+ <td width="50%"><input type='text' class='tryForm__tableField paramField' name='id' placeholder='' data-type='Integer'></td>
88
+ </tr>
89
+
90
+ <tr>
91
+ <td width="30%"><code>username</code></td>
92
+ <td width="20%">String</td>
93
+ <td width="50%"><input type='text' class='tryForm__tableField paramField' name='username' placeholder='' data-type='String'></td>
94
+ </tr>
95
+
96
+ <tr>
97
+ <td width="30%"><code>first_name</code></td>
98
+ <td width="20%">String</td>
99
+ <td width="50%"><input type='text' class='tryForm__tableField paramField' name='first_name' placeholder='' data-type='String'></td>
100
+ </tr>
101
+
102
+ <tr>
103
+ <td width="30%"><code>last_name</code></td>
104
+ <td width="20%">String</td>
105
+ <td width="50%"><input type='text' class='tryForm__tableField paramField' name='last_name' placeholder='' data-type='String'></td>
106
+ </tr>
107
+
108
+ <tr>
109
+ <td width="30%"><code>email_address</code></td>
110
+ <td width="20%">String</td>
111
+ <td width="50%"><input type='text' class='tryForm__tableField paramField' name='email_address' placeholder='' data-type='String'></td>
112
+ </tr>
113
+
114
+ <tr>
115
+ <td width="30%"><code>password</code></td>
116
+ <td width="20%">String</td>
117
+ <td width="50%"><input type='text' class='tryForm__tableField paramField' name='password' placeholder='' data-type='String'></td>
118
+ </tr>
119
+
120
+ <tr>
121
+ <td width="30%"><code>admin</code></td>
122
+ <td width="20%">Boolean</td>
123
+ <td width="50%"><input type='text' class='tryForm__tableField paramField' name='admin' placeholder='' data-type='boolean'></td>
124
+ </tr>
125
+
126
+ </table>
127
+
128
+
129
+
130
+
131
+ <p class='tryForm__button'>
132
+ <button class='tryForm__buttonLink' type='submit'>Make this request</button>
133
+ <button class='tryForm__buttonLink tryFormCancel' type='button'>Cancel</button>
134
+ </p>
135
+
136
+ <pre class='tryForm__output'>The request output will be shown here...</pre>
137
+ </form>
138
+
139
+
140
+
141
+
142
+ <h2>URL</h2>
143
+ <p class='apiURLFull'><span>/api/v1/</span>users/update</p>
144
+
145
+
146
+
147
+
148
+ <h2>Access</h2>
149
+ <p class='text'>
150
+ Must be authenticated with a valid user API token.
151
+
152
+ If not authorised, a <code>NotAuthenticated</code> error will be returned.
153
+
154
+ </p>
155
+
156
+
157
+
158
+
159
+ <h2>Parameters</h2>
160
+
161
+ <table class='table paramTable'>
162
+ <thead>
163
+ <tr>
164
+ <th width="60%">Parameter</th>
165
+ <th width="20%">Type</th>
166
+ <th width="20%">Default</th>
167
+ </tr>
168
+ </thead>
169
+
170
+ <tr>
171
+ <td>
172
+ <p>
173
+ <span class='paramTable__name'>id</span>
174
+ <span class='paramTable__req'>Required</span>
175
+ </p>
176
+
177
+ <p class='paramTable__description'>The ID of the user to update</p>
178
+
179
+ </td>
180
+ <td>Integer</td>
181
+ <td>
182
+
183
+ <span class='paramTable__nil'>null</span>
184
+
185
+ </td>
186
+ </tr>
187
+
188
+ <tr>
189
+ <td>
190
+ <p>
191
+ <span class='paramTable__name'>username</span>
192
+
193
+ </p>
194
+
195
+ <p class='paramTable__description'>The user's username</p>
196
+
197
+ </td>
198
+ <td>String</td>
199
+ <td>
200
+
201
+ <span class='paramTable__nil'>null</span>
202
+
203
+ </td>
204
+ </tr>
205
+
206
+ <tr>
207
+ <td>
208
+ <p>
209
+ <span class='paramTable__name'>first_name</span>
210
+
211
+ </p>
212
+
213
+ <p class='paramTable__description'>The user's first name</p>
214
+
215
+ </td>
216
+ <td>String</td>
217
+ <td>
218
+
219
+ <span class='paramTable__nil'>null</span>
220
+
221
+ </td>
222
+ </tr>
223
+
224
+ <tr>
225
+ <td>
226
+ <p>
227
+ <span class='paramTable__name'>last_name</span>
228
+
229
+ </p>
230
+
231
+ <p class='paramTable__description'>The user's last name</p>
232
+
233
+ </td>
234
+ <td>String</td>
235
+ <td>
236
+
237
+ <span class='paramTable__nil'>null</span>
238
+
239
+ </td>
240
+ </tr>
241
+
242
+ <tr>
243
+ <td>
244
+ <p>
245
+ <span class='paramTable__name'>email_address</span>
246
+
247
+ </p>
248
+
249
+ <p class='paramTable__description'>The user's e-mail address</p>
250
+
251
+ </td>
252
+ <td>String</td>
253
+ <td>
254
+
255
+ <span class='paramTable__nil'>null</span>
256
+
257
+ </td>
258
+ </tr>
259
+
260
+ <tr>
261
+ <td>
262
+ <p>
263
+ <span class='paramTable__name'>password</span>
264
+
265
+ </p>
266
+
267
+ <p class='paramTable__description'>The user's password</p>
268
+
269
+ </td>
270
+ <td>String</td>
271
+ <td>
272
+
273
+ <span class='paramTable__nil'>null</span>
274
+
275
+ </td>
276
+ </tr>
277
+
278
+ <tr>
279
+ <td>
280
+ <p>
281
+ <span class='paramTable__name'>admin</span>
282
+
283
+ </p>
284
+
285
+ <p class='paramTable__description'>Should this user be an admin?</p>
286
+
287
+ </td>
288
+ <td>Boolean</td>
289
+ <td>
290
+
291
+ <span class='paramTable__nil'>null</span>
292
+
293
+ </td>
294
+ </tr>
295
+
296
+ </table>
297
+
298
+
299
+
300
+
301
+ <h2>Errors</h2>
302
+
303
+
304
+ <table class='table errorsTable'>
305
+ <thead>
306
+ <tr>
307
+ <th width="60%">Error</th>
308
+ <th width="40%">Attributes</th>
309
+ </tr>
310
+ </thead>
311
+
312
+ <tr>
313
+ <td>
314
+ <p>
315
+ <span class='paramTable__name'>UserNotFound</span>
316
+
317
+ <p class='paramTable__description'>The user specified could not be found</p>
318
+
319
+ </p>
320
+ </td>
321
+ <td>
322
+
323
+ <ul class='errorAttributeList'>
324
+
325
+ <li>
326
+ <p class='errorAttributeList__name'>id</p>
327
+ <p class='errorAttributeList__desc'>The ID that was looked up</p>
328
+ </li>
329
+
330
+ </ul>
331
+
332
+ </td>
333
+ </tr>
334
+
335
+ <tr>
336
+ <td>
337
+ <p>
338
+ <span class='paramTable__name'>ValidationError</span>
339
+
340
+ <p class='paramTable__description'>The details provided were not sufficient to save the user</p>
341
+
342
+ </p>
343
+ </td>
344
+ <td>
345
+
346
+ <ul class='errorAttributeList'>
347
+
348
+ <li>
349
+ <p class='errorAttributeList__name'>errors</p>
350
+ <p class='errorAttributeList__desc'>An array of errors for each field</p>
351
+ </li>
352
+
353
+ </ul>
354
+
355
+ </td>
356
+ </tr>
357
+
358
+ </table>
359
+
360
+
361
+
362
+
363
+ <h2>Response Data</h2>
364
+
365
+
366
+ <p class='text'>This action will return a <a class='link' href='../../structures/user.html'>user structure</a>.</p>
367
+
368
+
369
+
370
+
371
+
372
+ You'll receive all attributes for this structure (basic and extended attributes).
373
+
374
+
375
+
376
+
377
+
378
+
379
+
380
+ </section>
381
+ <footer class='footer'>
382
+ <p>Generated by Moonrope at 12:43 on Monday 22 February 2016 for d3c499</p>
383
+ </footer>
384
+ <script src='https://code.jquery.com/jquery-1.12.0.min.js'></script>
385
+ <script src='../../assets/try.js'></script>
386
+ </body>
387
+ </html>