Class: E621::Search::Posts
- Inherits:
-
Object
- Object
- E621::Search::Posts
- Defined in:
- lib/rubyhexagon/search/posts.rb
Overview
Class to hold methods for Post searches.
Class Method Summary collapse
-
.deleted(page = 1) ⇒ Array<Post>
Retrieve a list of deleted post, with deletion reason.
-
.fetch_posts(parameters) ⇒ Array<Post>
Helper function for posts.
-
.list(tags, limit = 320, before_id = 2_000_000) ⇒ Array<Post>
Retrieve a list of post data, which is filtered by arguments.
-
.popular(timespan = :day) ⇒ Array<Post>
Fetch popular posts by day, week or month.
Class Method Details
.deleted(page = 1) ⇒ Array<Post>
Retrieve a list of deleted post, with deletion reason. Only id and del_reason is present. This method accepts blocks and only returns one page without blocks
37 38 39 40 41 42 43 44 45 |
# File 'lib/rubyhexagon/search/posts.rb', line 37 def self.deleted(page = 1) d = fetch_deleted(page) while block_given? && d != [] d.each { |del| yield del } d = fetch_deleted(page) page += 1 end d end |
.fetch_posts(parameters) ⇒ Array<Post>
Helper function for posts
106 107 108 109 110 |
# File 'lib/rubyhexagon/search/posts.rb', line 106 def self.fetch_posts(parameters) API.new.fetch('post', 'index', parameters).map do |data| Post.new(data[:id]).show(data) end end |
.list(tags, limit = 320, before_id = 2_000_000) ⇒ Array<Post>
Retrieve a list of post data, which is filtered by arguments. This method requires a block to be passed to it!
This method accepts blocks and only returns one page without blocks
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rubyhexagon/search/posts.rb', line 61 def self.list(, limit = 320, before_id = 2_000_000) parameters = { tags: , limit: limit, before_id: before_id } posts = fetch_posts(parameters) while block_given? && posts != [] posts.each { |post| yield post } posts = fetch_posts(parameters) parameters[:before_id] = posts.last.nil? ? 0 : posts.last.id end posts end |
.popular(timespan = :day) ⇒ Array<Post>
Fetch popular posts by day, week or month
80 81 82 83 84 85 86 87 |
# File 'lib/rubyhexagon/search/posts.rb', line 80 def self.popular(timespan = :day) unless %i[day week month].include?(timespan) raise ArgumentError, "Unknown time span: #{timespan}" end API.new.fetch('post', "popular_by_#{timespan}", {}).map do |post| Post.new(post[:id]).show(post) end end |