moonrope 1.4.1 → 2.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.
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,93 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>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
+ <h1>Users API</h1>
47
+
48
+ <p class='text'> The Users API provides full access to manage the users
49
+ which exist on your account.
50
+ </p>
51
+
52
+ <h2>Action</h2>
53
+ <p class='text'>
54
+ The following actions are available. Choose from the list below
55
+ to view full details of how to access them.
56
+ </p>
57
+ <ul class='standardList'>
58
+
59
+ <li>
60
+ <a class='link' href='../controllers/users/list.html'>List all users</a>
61
+ <p class='apiURL'><span>/api/v1/</span><b>users/list</b></p>
62
+ <p class='meta'>This action will return a list of all users which the authenticated user has access to.</p>
63
+ </li>
64
+
65
+ <li>
66
+ <a class='link' href='../controllers/users/show.html'>Get unit information</a>
67
+ <p class='apiURL'><span>/api/v1/</span><b>users/show</b></p>
68
+
69
+ </li>
70
+
71
+ <li>
72
+ <a class='link' href='../controllers/users/create.html'>Create a new user</a>
73
+ <p class='apiURL'><span>/api/v1/</span><b>users/create</b></p>
74
+ <p class='meta'> This action will create a new user with the properties which have been provided.
75
+ </p>
76
+ </li>
77
+
78
+ <li>
79
+ <a class='link' href='../controllers/users/update.html'>Update an existing user</a>
80
+ <p class='apiURL'><span>/api/v1/</span><b>users/update</b></p>
81
+ <p class='meta'>This action will update an existing user with the properties provided.</p>
82
+ </li>
83
+
84
+ </ul>
85
+
86
+ </section>
87
+ <footer class='footer'>
88
+ <p>Generated by Moonrope at 12:43 on Monday 22 February 2016 for d3c499</p>
89
+ </footer>
90
+ <script src='https://code.jquery.com/jquery-1.12.0.min.js'></script>
91
+ <script src='../assets/try.js'></script>
92
+ </body>
93
+ </html>
data/html/index.html ADDED
@@ -0,0 +1,166 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Welcome - 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="active">
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="">
36
+ Users API
37
+ </a>
38
+ </li>
39
+
40
+ </ul>
41
+ </nav>
42
+ </section>
43
+ <section class='content'>
44
+
45
+
46
+ <h1>Welcome to our API documentation</h1>
47
+ <p class='text'>
48
+ From here you can browse the full documentation for our HTTP
49
+ API. Our API is split into sections which you can browse using
50
+ the menu on the right. If you have any questions, you can
51
+ <a href='#'>contact our team</a> and we'll be happy to help out.
52
+ </p>
53
+ <p class='text'>
54
+ Before you get started, take a few minutes to review the
55
+ information below about how to interact with our API. It includes
56
+ information about how to send requests, what response data is
57
+ sent in and how to handle errors.
58
+ </p>
59
+
60
+ <h2>Making requests</h2>
61
+ <p class='text'>
62
+ Our API works over the HTTP protocol with JSON. It is implemented
63
+ in an RPC-like manner and everything you can do with the API has
64
+ its own <em>action</em>.
65
+ </p>
66
+ <p class='text'>
67
+ All HTTP requests must be made over HTTPS to the URL shown on the
68
+ action's page in this documentation. All responses you receive from
69
+ the API will be returned in JSON. Requests should be made using the
70
+ <code>POST</code> method with any parameters encoded as JSON in the
71
+ body of the request.
72
+ </p>
73
+
74
+ <h2>Receiving responses</h2>
75
+ <p class='text'>
76
+ All responses will be returned to you encoded as JSON. You will always
77
+ receive a hash as the response which will look like the JSON below:
78
+ </p>
79
+ <pre class='code'>
80
+ {
81
+ <span class='jsonKey'>"status"</span>:<span class='jsonString'>"success"</span>,
82
+ <span class='jsonKey'>"time"</span>:<span class='jsonString'>0.123</span>,
83
+ <span class='jsonKey'>"flags"</span>:{
84
+ <span class='jsonComment'>... additional information about the request ...</span>
85
+ },
86
+ <span class='jsonKey'>"data"</span>:{
87
+ <span class='jsonComment'>... the data returned from the action ...</span>
88
+ }
89
+ }
90
+ </pre>
91
+ <p class='text'>
92
+ The <b>status</b> attribute will give you can indication about whether the
93
+ request was performed successfully or whether an error occurred. Values which
94
+ may be returned are shown below:
95
+ </p>
96
+ <ul class='standardList'>
97
+ <li>
98
+ <code>success</code> - this means that the request completed successfully
99
+ and returned the data that was expected.
100
+ </li>
101
+ <li>
102
+ <code>parameter-error</code> - the parameters provided for the action are
103
+ not valid and should be revised.
104
+ </li>
105
+ <li>
106
+ <code>error</code> - an error occurred that didn't fit into the above categories.
107
+ This will be accompanied with an error code, a descriptive message and further
108
+ attributes which may be useful. The actual potential errors for each action are
109
+ shown in the documentation.
110
+ </li>
111
+ </ul>
112
+ <p class='text'>
113
+ The <b>time</b> attribute shows how long the request took to complete on the
114
+ server side.
115
+ </p>
116
+ <p class='text'>
117
+ The <b>flags</b> attribute contains a hash of additional attributes
118
+ which are relevant to your request. For example, if you receive an array of data
119
+ it may be paginated and this pagination data will be returned in this
120
+ hash.
121
+ </p>
122
+ <p class='text'>
123
+ The <b>data</b> attribute contains the result of your request. Depending on the
124
+ status, this will either contain the data requested or details of any
125
+ error which has occurred.
126
+ </p>
127
+ <h3>A note about HTTP status code</h3>
128
+ <p class='text'>
129
+ The API does not generally use HTTP status codes to return information
130
+ about the outcome of a request. There are two supported statuses with
131
+ the API:
132
+ </p>
133
+ <ul class='standardList'>
134
+ <li>
135
+ <code>200 OK</code> - This is the code you'll usually receive.
136
+ It indicates that the response was successfully delivered and
137
+ returned to our service (although does not nessesary mean that
138
+ the action you were expecting was successful). Further status
139
+ information will be provided in the <code>status</code> attribute
140
+ on your response body.
141
+ </li>
142
+ <li>
143
+ <code>301 Moved Permanently</code> or <code>308 Permanent Redirect</code> -
144
+ This means that the API request should be sent to an alternative
145
+ URL. This may just mean you need to send your request using <code>https</code>
146
+ rather than <code>http</code> as the protocol.
147
+ </li>
148
+ <li>
149
+ <code>500 Internal Server Error</code> - This will be returned
150
+ when an error occurred within the API itself. This was not
151
+ anticipated by us and should be reported to us.
152
+ </li>
153
+ <li>
154
+ <code>503 Service Unavailable</code> - This will be returned if
155
+ API is currently unavailable for maintenance or other issue.
156
+ </li>
157
+ </ul>
158
+
159
+ </section>
160
+ <footer class='footer'>
161
+ <p>Generated by Moonrope at 12:43 on Monday 22 February 2016 for d3c499</p>
162
+ </footer>
163
+ <script src='https://code.jquery.com/jquery-1.12.0.min.js'></script>
164
+ <script src='assets/try.js'></script>
165
+ </body>
166
+ </html>
data/html/moonrope.txt ADDED
File without changes
@@ -0,0 +1,176 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Pet Structure - 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="">
36
+ Users API
37
+ </a>
38
+ </li>
39
+
40
+ </ul>
41
+ </nav>
42
+ </section>
43
+ <section class='content'>
44
+
45
+
46
+ <h1>Pet Structure</h1>
47
+
48
+ <h2>Base Attributes</h2>
49
+ <table class='table paramTable'>
50
+ <thead>
51
+ <tr>
52
+ <th width="45%">Attribute</th>
53
+ <th width="20%">Type</th>
54
+ <th width="35%">Example</th>
55
+ </tr>
56
+ </thead>
57
+
58
+ <tr>
59
+ <td>
60
+ <p>
61
+ <span class='paramTable__name'>id</span>
62
+ </p>
63
+
64
+ <p class='paramTable__description'>The ID of the pet</p>
65
+
66
+
67
+
68
+
69
+ </td>
70
+ <td>Integer</td>
71
+ <td>
72
+
73
+ 148
74
+
75
+ </td>
76
+ </tr>
77
+
78
+ <tr>
79
+ <td>
80
+ <p>
81
+ <span class='paramTable__name'>name</span>
82
+ </p>
83
+
84
+ <p class='paramTable__description'>The name of the pet</p>
85
+
86
+
87
+
88
+
89
+ </td>
90
+ <td>String</td>
91
+ <td>
92
+
93
+ Fido
94
+
95
+ </td>
96
+ </tr>
97
+
98
+ <tr>
99
+ <td>
100
+ <p>
101
+ <span class='paramTable__name'>color</span>
102
+ </p>
103
+
104
+ <p class='paramTable__description'>What color is the pet?</p>
105
+
106
+
107
+
108
+
109
+ </td>
110
+ <td>String</td>
111
+ <td>
112
+
113
+ Green
114
+
115
+ </td>
116
+ </tr>
117
+
118
+
119
+
120
+ </table>
121
+
122
+
123
+
124
+
125
+
126
+
127
+ <h2>Expansions</h2>
128
+ <p class='text'>
129
+ Expansions are embedded structures of other objects that are related to the structure
130
+ that you're viewing. Which expansions are returned by a specific action are shown on that
131
+ action's documentation however some actions allow you to choose which expansions are
132
+ returned.
133
+ </p>
134
+ <table class='table paramTable'>
135
+ <thead>
136
+ <tr>
137
+ <th width="45%">Attribute</th>
138
+ <th width="20%">Type</th>
139
+ <th width="35%">Example</th>
140
+ </tr>
141
+ </thead>
142
+
143
+ <tr>
144
+ <td>
145
+ <p>
146
+ <span class='paramTable__name'>user</span>
147
+ </p>
148
+
149
+ <p class='paramTable__description'>The user who owns this pet</p>
150
+
151
+
152
+
153
+
154
+ </td>
155
+ <td>Hash</td>
156
+ <td>
157
+
158
+ <a class='link' href="../structures/user.html">User structure</a>
159
+
160
+ </td>
161
+ </tr>
162
+
163
+
164
+
165
+ </table>
166
+
167
+
168
+
169
+ </section>
170
+ <footer class='footer'>
171
+ <p>Generated by Moonrope at 12:43 on Monday 22 February 2016 for d3c499</p>
172
+ </footer>
173
+ <script src='https://code.jquery.com/jquery-1.12.0.min.js'></script>
174
+ <script src='../assets/try.js'></script>
175
+ </body>
176
+ </html>