Class: Redd::Models::FrontPage
- Inherits:
-
BasicModel
- Object
- BasicModel
- Redd::Models::FrontPage
- Defined in:
- lib/redd/models/front_page.rb
Overview
The front page. FIXME: deal with serious code duplication from Subreddit
Instance Attribute Summary
Attributes inherited from BasicModel
Instance Method Summary collapse
-
#comment_stream(**params, &block) ⇒ Object
Stream newly submitted comments.
- #comments(**params) ⇒ Object
- #controversial(**params) ⇒ Object
- #gilded(**params) ⇒ Object
- #hot(**params) ⇒ Object
-
#listing(sort, **params) ⇒ Listing<Submission>
Get the appropriate listing.
- #new(**params) ⇒ Object
-
#post_stream(**params, &block) ⇒ Object
Stream newly submitted posts.
- #rising(**params) ⇒ Object
- #top(**params) ⇒ Object
-
#wiki_page(title) ⇒ WikiPage
Get a wiki page by its title.
-
#wiki_pages ⇒ Array<String>
Reddit’s base wiki pages.
Methods inherited from BasicModel
from_id, #initialize, #inspect, #method_missing, #respond_to_missing?, #to_ary, #to_h
Constructor Details
This class inherits a constructor from Redd::Models::BasicModel
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Redd::Models::BasicModel
Instance Method Details
#comment_stream(**params, &block) ⇒ Object
Stream newly submitted comments.
65 66 67 68 69 70 71 72 |
# File 'lib/redd/models/front_page.rb', line 65 def comment_stream(**params, &block) params[:limit] ||= 100 stream = Utilities::Stream.new do |previous| before = previous ? previous.first.name : nil listing(:comments, params.merge(before: before)) end block_given? ? stream.stream(&block) : stream.enum_for(:stream) end |
#comments(**params) ⇒ Object
50 51 52 |
# File 'lib/redd/models/front_page.rb', line 50 %i(hot new top controversial comments rising gilded).each do |sort| define_method(sort) { |**params| listing(sort, **params) } end |
#controversial(**params) ⇒ Object
50 51 52 |
# File 'lib/redd/models/front_page.rb', line 50 %i(hot new top controversial comments rising gilded).each do |sort| define_method(sort) { |**params| listing(sort, **params) } end |
#gilded(**params) ⇒ Object
50 51 52 |
# File 'lib/redd/models/front_page.rb', line 50 %i(hot new top controversial comments rising gilded).each do |sort| define_method(sort) { |**params| listing(sort, **params) } end |
#hot(**params) ⇒ Object
50 51 52 |
# File 'lib/redd/models/front_page.rb', line 50 %i(hot new top controversial comments rising gilded).each do |sort| define_method(sort) { |**params| listing(sort, **params) } end |
#listing(sort, **params) ⇒ Listing<Submission>
Note:
The option :time only applies to the top and controversial sorts.
Get the appropriate listing.
36 37 38 39 |
# File 'lib/redd/models/front_page.rb', line 36 def listing(sort, **params) params[:t] = params.delete(:time) if params.key?(:time) @client.model(:get, "/#{sort}", params) end |
#new(**params) ⇒ Object
50 51 52 |
# File 'lib/redd/models/front_page.rb', line 50 %i(hot new top controversial comments rising gilded).each do |sort| define_method(sort) { |**params| listing(sort, **params) } end |
#post_stream(**params, &block) ⇒ Object
Stream newly submitted posts.
55 56 57 58 59 60 61 62 |
# File 'lib/redd/models/front_page.rb', line 55 def post_stream(**params, &block) params[:limit] ||= 100 stream = Utilities::Stream.new do |previous| before = previous ? previous.first.name : nil listing(:new, params.merge(before: before)) end block_given? ? stream.stream(&block) : stream.enum_for(:stream) end |
#rising(**params) ⇒ Object
50 51 52 |
# File 'lib/redd/models/front_page.rb', line 50 %i(hot new top controversial comments rising gilded).each do |sort| define_method(sort) { |**params| listing(sort, **params) } end |
#top(**params) ⇒ Object
50 51 52 |
# File 'lib/redd/models/front_page.rb', line 50 %i(hot new top controversial comments rising gilded).each do |sort| define_method(sort) { |**params| listing(sort, **params) } end |
#wiki_page(title) ⇒ WikiPage
Get a wiki page by its title.
19 20 21 |
# File 'lib/redd/models/front_page.rb', line 19 def wiki_page(title) WikiPage.new(@client, title: title) end |
#wiki_pages ⇒ Array<String>
Returns reddit’s base wiki pages.
12 13 14 |
# File 'lib/redd/models/front_page.rb', line 12 def wiki_pages @client.get('/wiki/pages').body[:data] end |