Module: Booru::API::Post

Included in:
Client
Defined in:
lib/booru/api/post.rb

Instance Method Summary collapse

Instance Method Details

#create_post(options = {}) ⇒ Object

Create: This action creates a post

There are only two mandatory fields: you need to supply the tags, and you need to supply the file, either through a multipart form or through a source URL.

options - The Hash used to refine the selection (default: {}):

:post[tags]             - A space delimited list of tags
                          (optional).
:post[file]             - The file data encoded as a
                          multipart form (optional).
:post[rating]           - The rating for the post
                          (optional).
                          Can be: safe, questionable, or
                          explicit.
:post[source]           - If this is a URL, Danbooru will
                          download the file (optional).
:post[is_rating_locked] - Set to true to prevent others
                          from changing the rating
                          (optional).
:post[is_note_locked]   - Set to true to prevent others
                          from adding notes (optional).
:post[parent_id]        - The ID of the parent post
                          (optional).
:md5                    - Supply an MD5 if you want
                          Danbooru to verify the file
                          after uploading it. If the MD5
                          doesn't match, the post is
                          destroyed (optional).

If the call fails, the following response reasons are possible:

MD5 mismatch: This means you supplied an MD5 parameter and what
              Danbooru got doesn't match. Try uploading the file
              again.
duplicate:    This post already exists in Danbooru (based on the
              MD5 hash). An additional attribute called location
              will be set, pointing to the (relative) URL of the
              original post.
other:        Any other error will print its error message.

If the post upload succeeded, you’ll get an attribute called location in the response pointing to the relative URL of your newly uploaded post.



68
69
70
71
72
# File 'lib/booru/api/post.rb', line 68

def create_post(options = {})
  base_url = '/post/create'
  query = query_string(base_url, options)
  parse(post(query))
end

#destroy_post(options = {}) ⇒ Object Also known as: delete_post

Destroy: This action lets you delete a post.

options - The Hash used to refine the selection (default: {}):

:id - The id number of the post to delete.

You must be logged in to use this action. You must also be the user who uploaded the post (or you must be a moderator).



112
113
114
115
116
# File 'lib/booru/api/post.rb', line 112

def destroy_post(options = {})
  base_url = '/post/destroy'
  query = query_string(base_url, options)
  parse(post(query))
end

#list_posts(options = {}) ⇒ Object

List: This action retrieves a list of posts

options - The Hash used to refine the selection (default: {}):

:limit - How many posts you want to retrieve. There is a
         hard limit of 100 posts per request
         (default: 100).
:page  - The page number (default: 1).
:tags  - The tags to search for. Any tag combination that
         works on the web site will work here. This
         includes all the meta-tags.


16
17
18
19
20
21
22
23
# File 'lib/booru/api/post.rb', line 16

def list_posts(options = {})
  base_url = '/post/index'
  defaults = {:limit => 100, :page => 1}
  options = defaults.merge(options)

  query = query_string(base_url, options)
  parse(get(query))
end

#post_vote(options = {}) ⇒ Object Also known as: vote_on_post

Vote: This action lets you vote for a post. You can only vote once per post per IP address.

options - The Hash used to refine the selection (default: {}):

:id    - The post id number to update.
:score - Set to 1 to vote up and -1 to vote down. All
         other values will be ignored.

If the call did not succeed, the following reasons are possible:

Already voted: You have already voted for this post.
Invalid score: You have supplied an invalid score.


144
145
146
147
148
# File 'lib/booru/api/post.rb', line 144

def post_vote(options = {})
  base_url = '/post/vote'
  query = query_string(base_url, options)
  parse(post(query))
end

#revert_post_tags(options = {}) ⇒ Object Also known as: revert_post

Revert Tags: This action reverts a post to a previous set of tags.

options - The Hash used to refine the selection (default: {}):

:id         - The post id number to update.
:history_id - The id number of the tag history.


125
126
127
128
129
# File 'lib/booru/api/post.rb', line 125

def (options = {})
  base_url = '/post/revert_tags'
  query = query_string(base_url, options)
  parse(post(query))
end

#update_post(options = {}) ⇒ Object

Update: This action updates a post’s attributes

Only the id parameter is required. Leave the other parameters blank if you don’t want to change them.

options - The Hash used to refine the selection (default: {}):

:id                     - The id number of the post to
                          update.
:post[tags]             - A space delimited list of tags
                          (optional).
:post[file]             - The file data encoded as a
                          multipart form (optional).
:post[rating]           - The rating for the post
                          (optional).
                          Can be: safe, questionable, or
                          explicit.
:post[source]           - If this is a URL, Danbooru will
                          download the file (optional).
:post[is_rating_locked] - Set to true to prevent others
                          from changing the rating
                          (optional).
:post[is_note_locked]   - Set to true to prevent others
                          from adding notes (optional).
:post[parent_id]        - The ID of the parent post
                          (optional).


99
100
101
102
103
# File 'lib/booru/api/post.rb', line 99

def update_post(options = {})
  base_url = '/post/update'
  query = query_string(base_url, options)
  parse(post(query))
end