easy_api_doc 0.2.1

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 (123) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +58 -0
  4. data/Rakefile +40 -0
  5. data/app/assets/images/easy_api_doc/favicon.ico +0 -0
  6. data/app/assets/images/easy_api_doc/glyphicons-halflings-white.png +0 -0
  7. data/app/assets/images/easy_api_doc/glyphicons-halflings.png +0 -0
  8. data/app/assets/images/easy_api_doc/loading.gif +0 -0
  9. data/app/assets/javascripts/easy_api_doc/api.js +2 -0
  10. data/app/assets/javascripts/easy_api_doc/application.js +15 -0
  11. data/app/assets/javascripts/easy_api_doc/base64.js +65 -0
  12. data/app/assets/javascripts/easy_api_doc/bootstrap.js +1999 -0
  13. data/app/assets/javascripts/easy_api_doc/documentation.js +223 -0
  14. data/app/assets/javascripts/easy_api_doc/status_codes.js +61 -0
  15. data/app/assets/stylesheets/easy_api_doc/api.css +4 -0
  16. data/app/assets/stylesheets/easy_api_doc/application.css +13 -0
  17. data/app/assets/stylesheets/easy_api_doc/bootstrap.css +6805 -0
  18. data/app/assets/stylesheets/easy_api_doc/documentation.css +47 -0
  19. data/app/controllers/easy_api_doc/api_controller.rb +13 -0
  20. data/app/controllers/easy_api_doc/application_controller.rb +17 -0
  21. data/app/controllers/easy_api_doc/documentation_controller.rb +42 -0
  22. data/app/helpers/easy_api_doc/application_helper.rb +71 -0
  23. data/app/helpers/easy_api_doc/documentation_helper.rb +5 -0
  24. data/app/models/easy_api_doc/action.rb +59 -0
  25. data/app/models/easy_api_doc/api_version.rb +18 -0
  26. data/app/models/easy_api_doc/namespace.rb +14 -0
  27. data/app/models/easy_api_doc/parameter.rb +49 -0
  28. data/app/models/easy_api_doc/resource.rb +18 -0
  29. data/app/views/easy_api_doc/api/index.html.erb +5 -0
  30. data/app/views/easy_api_doc/documentation/_parameter.html.erb +29 -0
  31. data/app/views/easy_api_doc/documentation/_resource_index.html.erb +16 -0
  32. data/app/views/easy_api_doc/documentation/api_action.html.erb +105 -0
  33. data/app/views/easy_api_doc/documentation/namespace.html.erb +13 -0
  34. data/app/views/easy_api_doc/documentation/resource.html.erb +18 -0
  35. data/app/views/layouts/easy_api_doc/_header.html.erb +23 -0
  36. data/app/views/layouts/easy_api_doc/application.html.erb +34 -0
  37. data/app/views/shared/_versions_index.html.erb +10 -0
  38. data/config/routes.rb +9 -0
  39. data/lib/configurable.rb +92 -0
  40. data/lib/configuration.rb +31 -0
  41. data/lib/easy_api_doc/engine.rb +5 -0
  42. data/lib/easy_api_doc/version.rb +3 -0
  43. data/lib/easy_api_doc.rb +6 -0
  44. data/test/dummy/README.rdoc +261 -0
  45. data/test/dummy/Rakefile +7 -0
  46. data/test/dummy/app/assets/javascripts/application.js +15 -0
  47. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  48. data/test/dummy/app/controllers/application_controller.rb +3 -0
  49. data/test/dummy/app/helpers/application_helper.rb +2 -0
  50. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  51. data/test/dummy/config/application.rb +59 -0
  52. data/test/dummy/config/boot.rb +10 -0
  53. data/test/dummy/config/database.yml +25 -0
  54. data/test/dummy/config/environment.rb +5 -0
  55. data/test/dummy/config/environments/development.rb +36 -0
  56. data/test/dummy/config/environments/production.rb +67 -0
  57. data/test/dummy/config/environments/test.rb +39 -0
  58. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  59. data/test/dummy/config/initializers/inflections.rb +15 -0
  60. data/test/dummy/config/initializers/mime_types.rb +5 -0
  61. data/test/dummy/config/initializers/secret_token.rb +7 -0
  62. data/test/dummy/config/initializers/session_store.rb +8 -0
  63. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  64. data/test/dummy/config/locales/en.yml +5 -0
  65. data/test/dummy/config/routes.rb +3 -0
  66. data/test/dummy/config.ru +4 -0
  67. data/test/dummy/doc/api_doc.yml +104 -0
  68. data/test/dummy/log/development.log +742 -0
  69. data/test/dummy/public/404.html +26 -0
  70. data/test/dummy/public/422.html +26 -0
  71. data/test/dummy/public/500.html +25 -0
  72. data/test/dummy/public/favicon.ico +0 -0
  73. data/test/dummy/script/rails +6 -0
  74. data/test/dummy/tmp/cache/assets/development/sprockets/04965396c9cfe69081b5dd98c3212fae +0 -0
  75. data/test/dummy/tmp/cache/assets/development/sprockets/16d88b38a506ba01a817e258ad8fb263 +0 -0
  76. data/test/dummy/tmp/cache/assets/development/sprockets/203aa633656e7d9c927c57c46e470c83 +0 -0
  77. data/test/dummy/tmp/cache/assets/development/sprockets/2f062b493cefffdbc012a973e9a105d5 +0 -0
  78. data/test/dummy/tmp/cache/assets/development/sprockets/2f0ed6020953bd16ba9b363edbf7cda0 +0 -0
  79. data/test/dummy/tmp/cache/assets/development/sprockets/30465ccaba36954861158b4242883bd6 +0 -0
  80. data/test/dummy/tmp/cache/assets/development/sprockets/36351f369d6eaf233c5e86e07555c170 +0 -0
  81. data/test/dummy/tmp/cache/assets/development/sprockets/405c9c78a785fb067d1c67657cfc62ef +0 -0
  82. data/test/dummy/tmp/cache/assets/development/sprockets/4abfd2becb22be944eb58bcf7107c873 +0 -0
  83. data/test/dummy/tmp/cache/assets/development/sprockets/4c371d51ee36edfddc4b8428b18dd632 +0 -0
  84. data/test/dummy/tmp/cache/assets/development/sprockets/4e7b4f8fde8fe12c9c12da639bed576e +0 -0
  85. data/test/dummy/tmp/cache/assets/development/sprockets/543e8b4a615c1577865f6ef73059d40f +0 -0
  86. data/test/dummy/tmp/cache/assets/development/sprockets/593636db3cefe193ebf65f5b58f57c9a +0 -0
  87. data/test/dummy/tmp/cache/assets/development/sprockets/67409083f86d1b03662b495d04418132 +0 -0
  88. data/test/dummy/tmp/cache/assets/development/sprockets/6afb7fed89c6f68558c4186d7a740a3a +0 -0
  89. data/test/dummy/tmp/cache/assets/development/sprockets/6b1110992dffe4c4455380229a0b8dff +0 -0
  90. data/test/dummy/tmp/cache/assets/development/sprockets/6db6675fbfed66d3d342f71869217dac +0 -0
  91. data/test/dummy/tmp/cache/assets/development/sprockets/75d2dc9028e3a3f3e6ca14d8f2fe7b5e +0 -0
  92. data/test/dummy/tmp/cache/assets/development/sprockets/76b036b95dde7edc081890640b4e7ed0 +0 -0
  93. data/test/dummy/tmp/cache/assets/development/sprockets/76da432edc6235bd7d73c3335233b1ed +0 -0
  94. data/test/dummy/tmp/cache/assets/development/sprockets/76faccd1d102ff2260e90ba48328b865 +0 -0
  95. data/test/dummy/tmp/cache/assets/development/sprockets/7cbc737c6b2b24706bf9170823e12d87 +0 -0
  96. data/test/dummy/tmp/cache/assets/development/sprockets/7de191b871e66d0c65b1cbaf04a60f58 +0 -0
  97. data/test/dummy/tmp/cache/assets/development/sprockets/802227e7577d1f42b5991586df8c9f02 +0 -0
  98. data/test/dummy/tmp/cache/assets/development/sprockets/848e56c99230cfa8034c10a99fc52c28 +0 -0
  99. data/test/dummy/tmp/cache/assets/development/sprockets/8619cf373138f78fdaab67c14cf6593b +0 -0
  100. data/test/dummy/tmp/cache/assets/development/sprockets/8b8f23bb1606d4e7f5738827686ff14f +0 -0
  101. data/test/dummy/tmp/cache/assets/development/sprockets/8dde0af325a3c57426da61982576c899 +0 -0
  102. data/test/dummy/tmp/cache/assets/development/sprockets/92396eadb57dc8abfb0bf5b3a01295a8 +0 -0
  103. data/test/dummy/tmp/cache/assets/development/sprockets/92a86617e44e9093fb483fc122b75752 +0 -0
  104. data/test/dummy/tmp/cache/assets/development/sprockets/940b911c55d2dc0ea6ca56b25f087739 +0 -0
  105. data/test/dummy/tmp/cache/assets/development/sprockets/a39a3034ca0b3e6ae8eaca11c3ca5ad6 +0 -0
  106. data/test/dummy/tmp/cache/assets/development/sprockets/a8036af98430c82633505d9ca5fcde5f +0 -0
  107. data/test/dummy/tmp/cache/assets/development/sprockets/b4869b1ad3dab2a1821989791a57171f +0 -0
  108. data/test/dummy/tmp/cache/assets/development/sprockets/b7ad7703003d24dab911bd3730756ca6 +0 -0
  109. data/test/dummy/tmp/cache/assets/development/sprockets/b89605b311bfb96d01c875e7a9710861 +0 -0
  110. data/test/dummy/tmp/cache/assets/development/sprockets/c237c4326b837e51c2650d4f6ed7b7a5 +0 -0
  111. data/test/dummy/tmp/cache/assets/development/sprockets/c780d1da090d4bb4d9fa09753f04e17f +0 -0
  112. data/test/dummy/tmp/cache/assets/development/sprockets/ca91101b167a195ab54cdbc39efec3e9 +0 -0
  113. data/test/dummy/tmp/cache/assets/development/sprockets/cdb61eee371606ef082a5ee3189889d2 +0 -0
  114. data/test/dummy/tmp/cache/assets/development/sprockets/d86f52fe55c0b5686bacec92537b0c03 +0 -0
  115. data/test/dummy/tmp/cache/assets/development/sprockets/e9636c04426623ad28848cb917d96a95 +0 -0
  116. data/test/dummy/tmp/cache/assets/development/sprockets/ee9a7b09a7ab141b6ae0cf8ce9197a3c +0 -0
  117. data/test/dummy/tmp/cache/assets/development/sprockets/f0fcdc72564e7709bcdeb9e88dd86135 +0 -0
  118. data/test/dummy/tmp/cache/assets/development/sprockets/f5bcd46e1a1371d63dec98bc97bcda4c +0 -0
  119. data/test/dummy/tmp/cache/assets/development/sprockets/fb3e3925ae8dcb2704d2602719387463 +0 -0
  120. data/test/dummy/tmp/cache/assets/development/sprockets/fcbbb63c7069e7c3b471d13ff0441d2a +0 -0
  121. data/test/dummy/tmp/cache/assets/development/sprockets/ff8858e82d7df03c855d847837676e31 +0 -0
  122. data/test/test_helper.rb +10 -0
  123. metadata +291 -0
@@ -0,0 +1,223 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
3
+
4
+ // Disables all fields in the API example, (convenience so that not all are needed to be disabled one at a time to update just one field)
5
+ $(document).ready(function () {
6
+ $('.disable-all-toggle').on('click', function(e){
7
+ var link = $(e.target);
8
+ if(link.html().match(/disable/)){
9
+ $('form.api_call .input').attr('disabled', 'disabled');
10
+ link.html('enable all');
11
+ $('form.api_call .disable-field-toggle').html('enable');
12
+ }
13
+ else {
14
+ $('form.api_call .input').removeAttr('disabled');
15
+ link.html('disable all');
16
+ $('form.api_call .disable-field-toggle').html('disable');
17
+ }
18
+ });
19
+
20
+ // Execute the example API call form
21
+ $('form.api_call .run_api_call').on('click', function(e) {
22
+ try {
23
+ var form = $(e.target).parents('form');
24
+ var params = get_form_params(form);
25
+ var format = params.format;
26
+ delete params['format'];
27
+ var uri = form.attr('action') + '.' + format;
28
+ var auth_settings = pop_auth_settings(params);
29
+
30
+ // switch out url variables;
31
+ var matches = uri.match(/\/(\:\w+)/g);
32
+ if(matches) {
33
+ $.each(matches, function(i, key) {
34
+ param_name = key.replace("/:", "");
35
+ var value = params[param_name];
36
+ uri = uri.replace(key, "/" + value);
37
+ delete params[param_name];
38
+ });
39
+ }
40
+ if (params['_doc_post_data'] != null) {
41
+ params = serialize_params(params);
42
+ var query_string = [];
43
+ for (var key in params)
44
+ if (key != '_doc_post_data') {
45
+ query_string.push(key + "=" + params[key]);
46
+ }
47
+ if (query_string.length > 0) {
48
+ uri += "?" + query_string.join("&")
49
+ }
50
+ params = params['_doc_post_data'];
51
+ } else {
52
+ params = serialize_params(params);
53
+ }
54
+
55
+ var remote_method = form.attr('method');
56
+
57
+ process_api_call(uri, remote_method, params, auth_settings, {'form': form, 'format': format});
58
+ }
59
+ catch(e) {
60
+ alert("There was an error within the test harness");
61
+ throw(e);
62
+ }
63
+ return false;
64
+ });
65
+
66
+ // Disable a single field in the API example (prevents blank parameters being passed that aren't wanted to be filled out)
67
+ $('form.api_call .disable-field-toggle').on('click', function(e){
68
+ var link = $(e.target);
69
+ var input = link.closest('tr').children().children('.input');
70
+
71
+ if(input.attr('disabled')){
72
+ input.removeAttr('disabled');
73
+ link.html('disable');
74
+ }
75
+ else {
76
+ input.attr('disabled', 'disabled')
77
+ link.html('enable');
78
+ }
79
+ return false;
80
+ });
81
+
82
+ // Array data structure support:
83
+ // appends fields using a hash structure with keys of '_array_0' ...
84
+ $('.append-fields').on('click', function(e){
85
+ var link = $(e.target);
86
+ var input = link.parent().children('.input').first();
87
+
88
+ new_node = input.clone();
89
+ new_node.val(""); // blank contents
90
+ new_node.addClass('additional');
91
+
92
+ elem_to_insert_after = link.parent().children('.input, .append-fields').last();
93
+ elem_to_insert_after.after(new_node);
94
+
95
+ link.parent().children('.input').each(function(i, elem) {
96
+ elem = $(elem);
97
+ var field_name = elem.attr('name');
98
+ field_name = field_name.replace(/\[(_array_)?\d*\]$/, "[_array_" + i + "]");
99
+ elem.attr('name', field_name);
100
+ });
101
+
102
+ return false;
103
+ });
104
+
105
+ });
106
+
107
+ // Example of how to send an api call via jQuery. Note that there are issues running this from a separate domain
108
+ // when executed in a web browser, due to Cross-Site security constraints from browsers
109
+ // For basic auth, either use already encoded credentials, or you'll need a javascript Base64 library as used below
110
+ // See: http://ostermiller.org/calc/encode.html for an example Base64 encoding js library
111
+ function process_api_call(uri, method, data, auth_settings, options) {
112
+ var form = options.form;
113
+ $.ajax({
114
+ url: uri,
115
+ type: method,
116
+ data: data,
117
+ error: function(xhr, data, ex) {
118
+ response = xhr.responseText;
119
+ if(response == null || response == '' || response.size == 0){
120
+ response = data;
121
+ }
122
+ form_output(options.form, response, xhr.status, options.format);
123
+ },
124
+ beforeSend: function(xhr, settings) {
125
+ form_output(options.form, '', '', options.format); // clear output
126
+ form.children('.loading').show();
127
+ auth_value = null;
128
+ if(auth_settings && auth_settings.type == 'basic') {
129
+ auth_value = "Basic " + encodeBase64(auth_settings.user + ":" + auth_settings.password);
130
+ } else if (auth_settings && auth_settings.type == 'oauth_grant') {
131
+ auth_value = "Basic " + encodeBase64(auth_settings.client_id + ":" + auth_settings.secret);
132
+ } else if (auth_settings && auth_settings.type == 'oauth_bearer') {
133
+ auth_value = "Bearer " + auth_settings.access_token;
134
+ }
135
+ if (auth_value != null)
136
+ xhr.setRequestHeader("Authorization", auth_value.replace(/(\r\n|\n|\r)/gm,"")); // dont send through \n on headers or they will be ignored
137
+ return true;
138
+ },
139
+ success: function(data, textStatus, xhr) {
140
+ response = xhr.responseText;
141
+ form_output(options.form, response, xhr.status, options.format);
142
+ },
143
+ complete: function(xhr, textStatus){
144
+ form.children('.loading').hide();
145
+ }
146
+ });
147
+ }
148
+
149
+ // Print the API response
150
+ function form_output(form, response, status, format) {
151
+ form.children('.response').show();
152
+
153
+ var pre = $(form.children('.response').children('.output'));
154
+ if(format == 'json') {
155
+ try {
156
+ response = JSON.stringify(JSON.parse(response), null, 4);
157
+ }
158
+ catch(e) {
159
+ // ignore formatting errors, and fall back to plain string response
160
+ }
161
+ }
162
+ // pre.html(response);
163
+ pre.val(response);
164
+
165
+ if(status != null) {
166
+ status_header = HTTP_STATUS_CODES[status.toString()[0] + 'XX'];
167
+ status_message = HTTP_STATUS_CODES[status];
168
+ if(status_header || status_message) {
169
+ status = status.toString() + " - " + status_header + " (" + status_message + ")";
170
+ }
171
+ form.children('.response').children().children('.http_status').html(status);
172
+ }
173
+ }
174
+
175
+ function pop_auth_settings(params){
176
+ var auth_settings = {};
177
+
178
+ auth_settings['type'] = params['_doc_authentication[type]'];
179
+ auth_settings['user'] = params['_doc_authentication[user]'];
180
+ auth_settings['client_id'] = params['_doc_authentication[client_id]'];
181
+ auth_settings['password'] = params['_doc_authentication[password]'];
182
+ auth_settings['secret'] = params['_doc_authentication[secret]'];
183
+ auth_settings['access_token'] = params['_doc_authentication[access_token]'];
184
+ delete params['_doc_authentication[type]'];
185
+ delete params['_doc_authentication[user]'];
186
+ delete params['_doc_authentication[client_id]'];
187
+ delete params['_doc_authentication[password]'];
188
+ delete params['_doc_authentication[secret]'];
189
+ delete params['_doc_authentication[access_token]'];
190
+
191
+ return auth_settings;
192
+ }
193
+
194
+ // helper to map the html form parameters to a hash
195
+ function get_form_params(form) {
196
+ var attrs = {};
197
+ jQuery.map(form.serializeArray(), function(n, i){
198
+ attrs[n['name']] = n['value'];
199
+ });
200
+ delete attrs['utf8']; // remove this jQuery param
201
+ return attrs;
202
+ }
203
+
204
+ // This maps our pseudo array hash structure into a true javascript array value
205
+ function serialize_params(params) {
206
+ formatted_params = {};
207
+ jQuery.map(params, function(value, key){
208
+ if(key.match(/\[\_array\_\d+\]$/)) {
209
+ real_key_name = key.replace(/\[\_array\_\d+\]$/, '');
210
+ if(formatted_params[real_key_name]){
211
+ formatted_params[real_key_name].push(value);
212
+ }
213
+ else {
214
+ formatted_params[real_key_name] = [value];
215
+ }
216
+ }
217
+ else {
218
+ formatted_params[key] = value;
219
+ }
220
+ });
221
+ return formatted_params;
222
+ }
223
+
@@ -0,0 +1,61 @@
1
+ var HTTP_STATUS_CODES = {
2
+ '2XX': 'Success',
3
+ 200: 'OK',
4
+ 201: 'Created',
5
+ 202: 'Accepted',
6
+ 203: 'Non-Authoritative Information',
7
+ 204: 'No Content',
8
+ 205: 'Reset Content',
9
+ 206: 'Partial Content',
10
+ 207: 'Multi-Status',
11
+ 208: 'Already Reported',
12
+ 226: 'IM Used',
13
+
14
+ '3XX': 'Redirect',
15
+ 300: 'Multiple Choices',
16
+ 301: 'Moved Permanently',
17
+ 302: 'Found',
18
+ 303: 'See Other',
19
+ 304: 'Not Modified',
20
+ 305: 'Use Proxy',
21
+ 306: 'Switch Proxy',
22
+ 307: 'Temporary Redirect',
23
+ 308: 'Permanent Redirect',
24
+
25
+ '4XX': 'Client Error',
26
+ 400: 'Bad Request',
27
+ 401: 'Unauthorized',
28
+ 402: 'Payment Required',
29
+ 403: 'Forbidden',
30
+ 404: 'Not Found',
31
+ 405: 'Method Not Allowed',
32
+ 406: 'Not Acceptable',
33
+ 407: 'Proxy Authentication Required',
34
+ 408: 'Request Timeout',
35
+ 409: 'Conflict',
36
+ 410: 'Gone',
37
+ 411: 'Length Required',
38
+ 412: 'Precondition Failed',
39
+ 413: 'Request Entity Too Large',
40
+ 414: 'Request-URI Too Long',
41
+ 415: 'Unsupported Media Type',
42
+ 416: 'Requested Range Not Satisfiable',
43
+ 429: 'Too Many Requests',
44
+ 431: 'Request Header Fields Too Large',
45
+ 444: 'No Response',
46
+ 449: 'Retry With',
47
+ 499: 'Client Closed Request',
48
+
49
+ '5XX': 'Server Error',
50
+ 500: 'Internal Server Error',
51
+ 501: 'Not Implemented',
52
+ 502: 'Bad Gateway',
53
+ 503: 'Service Unavailable',
54
+ 504: 'Gateway Timeout',
55
+ 505: 'HTTP Version Not Supported',
56
+ 509: 'Bandwidth Limit Exceeded',
57
+ 511: 'Network Authentication Required',
58
+ 598: 'Network read timeout error',
59
+ 599: 'Network connect timeout error',
60
+
61
+ };
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */