2010-04-20 23:05:11 +00:00
|
|
|
module PostApiMethods
|
|
|
|
def api_attributes
|
2010-06-15 06:49:05 +00:00
|
|
|
ret = {
|
2010-04-20 23:05:11 +00:00
|
|
|
:id => id,
|
|
|
|
:tags => cached_tags,
|
2010-11-30 05:31:15 +00:00
|
|
|
:created_at => created_at.to_i,
|
2010-04-20 23:05:11 +00:00
|
|
|
:creator_id => user_id,
|
|
|
|
:author => author,
|
|
|
|
:change => change_seq,
|
|
|
|
:source => source,
|
|
|
|
:score => score,
|
|
|
|
:md5 => md5,
|
|
|
|
:file_size => file_size,
|
|
|
|
:file_url => file_url,
|
|
|
|
:is_shown_in_index => is_shown_in_index,
|
|
|
|
:preview_url => preview_url,
|
|
|
|
:preview_width => preview_dimensions[0],
|
|
|
|
:preview_height => preview_dimensions[1],
|
2010-11-14 22:50:58 +00:00
|
|
|
:actual_preview_width => raw_preview_dimensions[0],
|
|
|
|
:actual_preview_height => raw_preview_dimensions[1],
|
2010-04-20 23:05:11 +00:00
|
|
|
:sample_url => sample_url,
|
|
|
|
:sample_width => sample_width || width,
|
|
|
|
:sample_height => sample_height || height,
|
|
|
|
:sample_file_size => sample_size,
|
|
|
|
:jpeg_url => jpeg_url,
|
|
|
|
:jpeg_width => jpeg_width || width,
|
|
|
|
:jpeg_height => jpeg_height || height,
|
|
|
|
:jpeg_file_size => jpeg_size,
|
|
|
|
:rating => rating,
|
|
|
|
:has_children => has_children,
|
|
|
|
:parent_id => parent_id,
|
|
|
|
:status => status,
|
|
|
|
:width => width,
|
2010-11-29 03:02:16 +00:00
|
|
|
:height => height,
|
|
|
|
:is_held => is_held,
|
2010-04-20 23:05:11 +00:00
|
|
|
}
|
2010-06-15 06:49:05 +00:00
|
|
|
|
2010-11-29 03:27:20 +00:00
|
|
|
if status == "deleted"
|
|
|
|
ret.delete(:sample_url)
|
|
|
|
ret.delete(:jpeg_url)
|
|
|
|
ret.delete(:file_url)
|
|
|
|
end
|
|
|
|
|
2010-11-29 02:53:02 +00:00
|
|
|
if status == "flagged" or status == "deleted"
|
2010-11-15 23:12:39 +00:00
|
|
|
ret[:flag_detail] = flag_detail
|
2010-11-29 02:53:02 +00:00
|
|
|
|
2010-11-29 02:56:46 +00:00
|
|
|
flag_detail.hide_user = (status == "deleted" and not Thread.current["danbooru-user"].is_mod_or_higher?)
|
2010-11-15 23:12:39 +00:00
|
|
|
end
|
|
|
|
|
2010-06-15 06:49:05 +00:00
|
|
|
# If we're being formatted as the contents of a pool, we'll have the pool_post
|
|
|
|
# sequence loaded too.
|
2010-11-18 19:39:33 +00:00
|
|
|
if self.respond_to?("pool_sequence") then
|
|
|
|
ret[:pool_post] = {}
|
|
|
|
ret[:pool_post][:pool_id] = pool_pool_id
|
|
|
|
ret[:pool_post][:next_post_id] = pool_next_post_id
|
|
|
|
ret[:pool_post][:prev_post_id] = pool_prev_post_id
|
|
|
|
ret[:pool_post][:sequence] = pool_sequence
|
|
|
|
end
|
2010-06-15 06:49:05 +00:00
|
|
|
|
|
|
|
return ret
|
2010-04-20 23:05:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_json(*args)
|
|
|
|
return api_attributes.to_json(*args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_xml(options = {})
|
2010-11-23 00:39:59 +00:00
|
|
|
return api_attributes.to_xml(options.reverse_merge(:root => "post"))
|
2010-04-20 23:05:11 +00:00
|
|
|
end
|
2010-11-30 02:23:40 +00:00
|
|
|
|
|
|
|
def api_data
|
|
|
|
{
|
|
|
|
:post => self,
|
2010-12-09 02:39:03 +00:00
|
|
|
:tags => Tag.batch_get_tag_types_for_posts([self]),
|
2010-11-30 02:23:40 +00:00
|
|
|
}
|
|
|
|
end
|
2010-11-30 02:54:59 +00:00
|
|
|
|
|
|
|
module ClassMethods
|
|
|
|
def batch_api_data(posts, options={})
|
|
|
|
result = { :posts => posts }
|
|
|
|
if options[:include_tags] then
|
2010-12-09 02:39:03 +00:00
|
|
|
result[:tags] = Tag.batch_get_tag_types_for_posts(posts)
|
2010-11-30 02:54:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.included(m)
|
|
|
|
m.extend(ClassMethods)
|
|
|
|
end
|
2010-04-20 23:05:11 +00:00
|
|
|
end
|