aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2016-12-24 03:03:56 +0900
committerKazuki Yamaguchi <k@rhe.jp>2016-12-24 03:10:34 +0900
commit410e7bdfe7f814688a1d65cb405630e1ca4803c2 (patch)
tree69acf809dffd52525b5e5878d59b61bb6e996d38
parent98563422c7daffaea11c29c5f5820fbc78791209 (diff)
downloadaclog-410e7bdfe7f814688a1d65cb405630e1ca4803c2.tar.gz
static apidocs
-rw-r--r--app/controllers/apidocs_controller.rb22
-rw-r--r--frontend/src/components/apidocs/endpoint.vue54
-rw-r--r--frontend/src/components/apidocs/sidebar.vue9
-rw-r--r--frontend/src/lib/aclog.js3
-rw-r--r--frontend/src/lib/apidocs.js276
5 files changed, 303 insertions, 61 deletions
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 @@
<script>
import ApidocsSidebar from "./sidebar.vue";
-import aclog from "aclog";
+import apidocs from "apidocs";
import utils from "utils";
export default {
@@ -74,34 +74,30 @@ export default {
transition.abort();
};
- aclog.apidocs.load().then(docs => {
- const path = this.$route.params.path;
- const ns = path.split("/", 2)[0];
- const es = docs.namespaces[ns];
- if (!es) return notFound();
- const endpoint = es.find(endp => endp.path === path);
- if (!endpoint) return notFound();
-
- transition.next({ endpoint: endpoint, example: { loading: false, result: null } });
- }).catch(notFound).then(() => {
- this.example.loading = true;
- fetch(this.example_url).then(res => {
- if (res.status >= 400) {
- var err = new Error(res.statusText);
- err.response = res;
- throw err;
- }
- return res.json();
- }).then(body => {
- this.example.loading = false;
- this.example.result = JSON.stringify(body, null, 2);
- }).catch(err => {
- this.example.loading = false;
- this.example.result = "Failed to load example. (" + err + ")";
- if (err.response) {
- err.response.json().then(body => this.example.result += "\n" + JSON.stringify(body, null, 2));
- }
- });
+ const path = this.$route.params.path;
+ const ns = path.split("/", 2)[0];
+ const es = apidocs.namespaces[ns];
+ if (!es) return notFound();
+ const endpoint = es.find(endp => endp.path === path);
+ if (!endpoint) return notFound();
+ transition.next({ endpoint: endpoint, example: { loading: false, result: null } });
+ this.example.loading = true;
+ fetch(this.example_url).then(res => {
+ if (res.status >= 400) {
+ var err = new Error(res.statusText);
+ err.response = res;
+ throw err;
+ }
+ return res.json();
+ }).then(body => {
+ this.example.loading = false;
+ this.example.result = JSON.stringify(body, null, 2);
+ }).catch(err => {
+ this.example.loading = false;
+ this.example.result = "Failed to load example. (" + err + ")";
+ if (err.response) {
+ err.response.json().then(body => this.example.result += "\n" + JSON.stringify(body, null, 2));
+ }
});
}
},
diff --git a/frontend/src/components/apidocs/sidebar.vue b/frontend/src/components/apidocs/sidebar.vue
index 0c3a43b..dda2722 100644
--- a/frontend/src/components/apidocs/sidebar.vue
+++ b/frontend/src/components/apidocs/sidebar.vue
@@ -14,12 +14,12 @@
</template>
<script>
-import aclog from "aclog";
+import apidocs from "apidocs";
export default {
data() {
return {
- apidocs: {},
+ apidocs: apidocs.namespaces,
loading: false,
};
},
@@ -32,11 +32,6 @@ export default {
},
},
created() {
- this.loading = true;
- aclog.apidocs.load().then(docs => {
- this.loading = false;
- this.apidocs = docs.namespaces
- });
}
};
</script>
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"
+ }
+ }
+ ]
+ }
+};