From 0d6ecf25c0397512c3862336c6433c07b10ff637 Mon Sep 17 00:00:00 2001 From: albert Date: Mon, 18 Mar 2013 16:19:09 -0700 Subject: [PATCH] fixes #889 --- ..._change_tag_subscription_tag_query_type.rb | 9 +++++ db/structure.sql | 6 ++- doc/api.txt | 39 +++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20130318231740_change_tag_subscription_tag_query_type.rb create mode 100644 doc/api.txt diff --git a/db/migrate/20130318231740_change_tag_subscription_tag_query_type.rb b/db/migrate/20130318231740_change_tag_subscription_tag_query_type.rb new file mode 100644 index 000000000..59f3ebc24 --- /dev/null +++ b/db/migrate/20130318231740_change_tag_subscription_tag_query_type.rb @@ -0,0 +1,9 @@ +class ChangeTagSubscriptionTagQueryType < ActiveRecord::Migration + def up + execute "alter table tag_subscriptions alter column tag_query type text" + end + + def down + execute "alter table tag_subscriptions alter column tag_query type varchar(255)" + end +end diff --git a/db/structure.sql b/db/structure.sql index baf20924b..ae1917482 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2393,7 +2393,7 @@ CREATE TABLE tag_subscriptions ( id integer NOT NULL, creator_id integer NOT NULL, name character varying(255) NOT NULL, - tag_query character varying(255) NOT NULL, + tag_query text NOT NULL, post_ids text NOT NULL, is_public boolean DEFAULT true NOT NULL, last_accessed_at timestamp without time zone, @@ -6256,4 +6256,6 @@ INSERT INTO schema_migrations (version) VALUES ('20130318012517'); INSERT INTO schema_migrations (version) VALUES ('20130318030619'); -INSERT INTO schema_migrations (version) VALUES ('20130318031705'); \ No newline at end of file +INSERT INTO schema_migrations (version) VALUES ('20130318031705'); + +INSERT INTO schema_migrations (version) VALUES ('20130318231740'); \ No newline at end of file diff --git a/doc/api.txt b/doc/api.txt new file mode 100644 index 000000000..24f0d059c --- /dev/null +++ b/doc/api.txt @@ -0,0 +1,39 @@ +Danbooru offers a REST-like API to make scripting easy. All you need is a way to GET, POST, PUT and DELETE to URLs. Responses are given in either XML or JSON format. + +h1. Basics + +HTTP defines four basic request methods: GET, POST, PUT and DELETE. You'll be using these methods to interact with the Danbooru API. Most API calls that change the state of the database (like creating, updating, or deleting something) require an HTTP POST, PUT or DELETE call. API calls that only retrieve data can typically be done with an HTTP GET call. + +A URL is considered a resource and the HTTP methods are actions you perform on the resource. For example, GET "/posts/1.json":/posts/1.json returns a JSON representation of a post. GET "/posts/1.xml":/posts/1.xml returns an XML representation. POST /posts/1.json would update the resource, for example changing its tags. + +Some resources require parameters. For example, you can search for tags named abc by calling GET "/tags.json?search[name_matches]=abc":/tags.json?search[name_matches]=abc will give you a JSON listing of all tags with name abc. + +For POST, PUT and DELETE requests you will be passing these parameters along in the body instead of the query parameters. + +h1. Responses + +All API calls that change state will return a single element response (for XML calls). They are formatted like this: + +[quote] + + +[/quote] + +For JSON responses, they'll look like this: + +[quote] +{success: false, reason: "duplicate"} +[/quote] + +While you can usually determine success or failure based on the response object, you can also figure out what happened based on the HTTP status code. In addition to the standard ones, Danbooru uses some custom status codes in the 4xx and 5xx range. + +* [b]200 OK[/b]: Request was successful +* [b]403 Forbidden[/b]: Access denied +* [b]404 Not Found[/b]: Not found +* [b]420 Invalid Record[/b]: Record could not be saved +* [b]421 User Throttled[/b]: User is throttled, try again later +* [b]422 Locked[/b]: The resource is locked and cannot be modified +* [b]423 Already Exists[/b]: Resource already exists +* [b]424 Invalid Parameters[/b]: The given parameters were invalid +* [b]500 Internal Server Error[/b]: Some unknown error occurred on the server +* [b]503 Service Unavailable[/b]: Server cannot currently handle the request, try again later