Class: Rubyhexagon::Search::Posts
- Inherits:
-
Object
- Object
- Rubyhexagon::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.
-
.list(tags, limit = 320) ⇒ 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
39 40 41 42 43 44 45 46 47 |
# File 'lib/rubyhexagon/search/posts.rb', line 39 def self.deleted(page = 1) d = fetch_deleted(page) while block_given? && d != [] d.each { |del| yield del } page += 1 d = fetch_deleted(page) end d end |
.list(tags, limit = 320) ⇒ 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
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rubyhexagon/search/posts.rb', line 63 def self.list(, limit = 320) parameters = { tags: , limit: limit } posts = fetch_posts(parameters) while block_given? && posts != [] posts.each { |post| yield post } parameters[:before_id] = posts.last.nil? ? 0 : posts.last.id posts = fetch_posts(parameters) end posts end |
.popular(timespan = :day) ⇒ Array<Post>
Fetch popular posts by day, week or month
82 83 84 85 86 87 88 89 |
# File 'lib/rubyhexagon/search/posts.rb', line 82 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 |