From 410e7bdfe7f814688a1d65cb405630e1ca4803c2 Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Sat, 24 Dec 2016 03:03:56 +0900 Subject: static apidocs --- app/controllers/apidocs_controller.rb | 22 --- frontend/src/components/apidocs/endpoint.vue | 54 +++--- frontend/src/components/apidocs/sidebar.vue | 9 +- frontend/src/lib/aclog.js | 3 - frontend/src/lib/apidocs.js | 276 +++++++++++++++++++++++++++ 5 files changed, 303 insertions(+), 61 deletions(-) delete mode 100644 app/controllers/apidocs_controller.rb create mode 100644 frontend/src/lib/apidocs.js diff --git a/app/controllers/apidocs_controller.rb b/app/controllers/apidocs_controller.rb deleted file mode 100644 index 8b8fab8..0000000 --- a/app/controllers/apidocs_controller.rb +++ /dev/null @@ -1,22 +0,0 @@ -class ApidocsController < ApplicationController - def all - apidocs = Rails.cache.fetch("apidocs/all") do - nss = {} - Api.routes.each { |route| - next if route.route_nodoc - next if route.route_method == "HEAD" - namespace = route.route_namespace.sub(/^\//, "") - nss[namespace] ||= [] - nss[namespace] << { method: route.route_method, - description: route.route_description, - path: route.route_path.sub(/^\//, "").sub(/\(\.:format\)$/, ""), - params: route.route_params.map { |n, o| [n, { required: o[:required], description: o[:desc], type: o[:type] }] }.to_h, - example_params: route.route_example_params, - } - } - nss - end - - render_json data: { namespaces: apidocs } - end -end diff --git a/frontend/src/components/apidocs/endpoint.vue b/frontend/src/components/apidocs/endpoint.vue index aeddced..c87448f 100644 --- a/frontend/src/components/apidocs/endpoint.vue +++ b/frontend/src/components/apidocs/endpoint.vue @@ -40,7 +40,7 @@ diff --git a/frontend/src/lib/aclog.js b/frontend/src/lib/aclog.js index b41f459..39525a3 100644 --- a/frontend/src/lib/aclog.js +++ b/frontend/src/lib/aclog.js @@ -65,9 +65,6 @@ export default { destroy: () => post("sessions/destroy"), verify: () => get("sessions/verify"), }, - apidocs: { - load: () => get("apidocs/all"), - }, optout: { redirect: (cb) => post("optout/redirect", { oauth_callback: cb }), callback: (verifier) => get("optout/callback", { oauth_verifier: verifier }), diff --git a/frontend/src/lib/apidocs.js b/frontend/src/lib/apidocs.js new file mode 100644 index 0000000..9757501 --- /dev/null +++ b/frontend/src/lib/apidocs.js @@ -0,0 +1,276 @@ +export default { + "namespaces": { + "tweets": [ + { + "method": "GET", + "description": "Returns a single Tweet, specified by ID.", + "path": "tweets/show", + "params": { + "id": { + "required": true, + "description": "The numerical ID of the desired Tweet.", + "type": "Integer" + } + }, + "example_params": { + "id": 43341783446466560 + } + }, + { + "method": "GET", + "description": "Returns Tweets, specified by comma-separated IDs.", + "path": "tweets/lookup", + "params": { + "ids": { + "required": true, + "description": "A comma-separated list of Tweet IDs, up to 100 are allowed in a single request.", + "type": "String" + } + }, + "example_params": { + "ids": "43341783446466560,340640143058825216" + } + }, + { + "method": "GET", + "description": "Returns the best Tweets of a user, specified by username or user ID.", + "path": "tweets/user_best", + "params": { + "user_id": { + "required": false, + "description": "The numerical ID of the user for whom to return results for.", + "type": "Integer" + }, + "screen_name": { + "required": false, + "description": "The username of the user for whom to return results for.", + "type": "String" + }, + "count": { + "required": false, + "description": "The number of tweets to retrieve. Must be less than or equal to 100, defaults to 10.", + "type": "Integer" + }, + "page": { + "required": false, + "description": "The page number of results to retrieve.", + "type": "Integer" + }, + "recent": { + "required": false, + "description": "When specified, returns only recent tweets in the term. Format is: /^\\d+[dwmy]$/", + "type": "String" + } + }, + "example_params": { + "user_id": 15926668, + "count": 2, + "page": 3, + "recent": "1m" + } + }, + { + "method": "GET", + "description": "Returns the newest Tweets of a user, specified by username or user ID.", + "path": "tweets/user_timeline", + "params": { + "user_id": { + "required": false, + "description": "The numerical ID of the user for whom to return results for.", + "type": "Integer" + }, + "screen_name": { + "required": false, + "description": "The username of the user for whom to return results for.", + "type": "String" + }, + "count": { + "required": false, + "description": "The number of tweets to retrieve. Must be less than or equal to 100, defaults to 10.", + "type": "Integer" + }, + "page": { + "required": false, + "description": "The page number of results to retrieve.", + "type": "Integer" + }, + "since_id": { + "required": false, + "description": "Returns results with an ID greater than the specified ID.", + "type": "Integer" + }, + "max_id": { + "required": false, + "description": "Returns results with an ID less than or equal to the specified ID.", + "type": "Integer" + }, + "reactions": { + "required": false, + "description": "Returns Tweets which has received reactions more than (or equal to) the specified number of times.", + "type": "Integer" + } + }, + "example_params": { + "screen_name": "toshi_a", + "count": 3, + "max_id": 432112694871605250 + } + }, + { + "method": "GET", + "description": "Returns the Tweets which a user specified by username or user ID favorited.", + "path": "tweets/user_favorites", + "params": { + "user_id": { + "required": false, + "description": "The numerical ID of the user for whom to return results for.", + "type": "Integer" + }, + "screen_name": { + "required": false, + "description": "The username of the user for whom to return results for.", + "type": "String" + }, + "count": { + "required": false, + "description": "The number of tweets to retrieve. Must be less than or equal to 100, defaults to 10.", + "type": "Integer" + }, + "page": { + "required": false, + "description": "The page number of results to retrieve.", + "type": "Integer" + }, + "reactions": { + "required": false, + "description": "Returns Tweets which has received reactions more than (or equal to) the specified number of times.", + "type": "Integer" + } + }, + "example_params": { + "user_id": 120726371, + "count": 2 + } + }, + { + "method": "GET", + "description": "Returns the specified user's Tweets which another specified user favorited.", + "path": "tweets/user_favorited_by", + "params": { + "user_id": { + "required": false, + "description": "The numerical ID of the user for whom to return results for.", + "type": "Integer" + }, + "screen_name": { + "required": false, + "description": "The username of the user for whom to return results for.", + "type": "String" + }, + "source_user_id": { + "required": false, + "description": "The numerical ID of the user for whom to return results for.", + "type": "Integer" + }, + "source_screen_name": { + "required": false, + "description": "The username of the user for whom to return results for.", + "type": "String" + }, + "count": { + "required": false, + "description": "The number of tweets to retrieve. Must be less than or equal to 100, defaults to 10.", + "type": "Integer" + }, + "page": { + "required": false, + "description": "The page number of results to retrieve.", + "type": "Integer" + }, + "since_id": { + "required": false, + "description": "Returns results with an ID greater than the specified ID.", + "type": "Integer" + }, + "max_id": { + "required": false, + "description": "Returns results with an ID less than or equal to the specified ID.", + "type": "Integer" + }, + "reactions": { + "required": false, + "description": "Returns Tweets which has received reactions more than (or equal to) the specified number of times.", + "type": "Integer" + } + }, + "example_params": { + "user_id": 120726371, + "count": 2, + "source_screen_name": "haru067" + } + } + ], + "users": [ + { + "method": "GET", + "description": "Returns the stats of a user, specified by username or user ID.", + "path": "users/stats", + "params": { + "id": { + "required": false, + "description": "The numerical ID of the user for whom to return results for.", + "type": "Integer" + }, + "screen_name": { + "required": false, + "description": "The username of the user for whom to return results for.", + "type": "String" + } + }, + "example_params": { + "id": 15926668 + } + }, + { + "method": "GET", + "description": "Returns the list of the users who discovered the Tweets of a user, specified by username or user ID.", + "path": "users/discovered_by", + "params": { + "id": { + "required": false, + "description": "The numerical ID of the user for whom to return results for.", + "type": "Integer" + }, + "screen_name": { + "required": false, + "description": "The username of the user for whom to return results for.", + "type": "String" + } + }, + "example_params": { + "id": 15926668 + } + }, + { + "method": "GET", + "description": "Returns the list of the users discovered by a user, specified by username or user ID.", + "path": "users/discovered_users", + "params": { + "id": { + "required": false, + "description": "The numerical ID of the user for whom to return results for.", + "type": "Integer" + }, + "screen_name": { + "required": false, + "description": "The username of the user for whom to return results for.", + "type": "String" + } + }, + "example_params": { + "screen_name": "toshi_a" + } + } + ] + } +}; -- cgit v1.2.3