Class: Redd::Models::FrontPage

Inherits:
Model
  • Object
show all
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 Model

#client

Instance Method Summary collapse

Methods inherited from Model

#initialize

Constructor Details

This class inherits a constructor from Redd::Models::Model

Instance Method Details

#comments(**params) ⇒ Object

See Also:


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

See Also:


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

See Also:


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

See Also:


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, **options) ⇒ PaginatedListing<Submission>

Note:

The option :time only applies to the top and controversial sorts.

Get the appropriate listing.

Parameters:

  • sort (:hot, :new, :top, :controversial, :comments, :rising, :gilded)

    the type of listing

  • options (Hash)

    a list of options to send with the request

Options Hash (**options):

  • :after (String)

    return results after the given fullname

  • :before (String)

    return results before the given fullname

  • :limit (Integer, nil)

    maximum number of items to return (nil for no limit)

  • :time (:hour, :day, :week, :month, :year, :all)

    the time period to consider when sorting.

Returns:


34
35
36
37
38
39
# File 'lib/redd/models/front_page.rb', line 34

def listing(sort, **options)
  options[:t] = options.delete(:time) if options.key?(:time)
  PaginatedListing.new(client, options) do |**req_options|
    client.model(:get, "/#{sort}", options.merge(req_options))
  end
end

#new(**params) ⇒ Object

See Also:


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

#rising(**params) ⇒ Object

See Also:


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

See Also:


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.

Parameters:

  • title (String)

    the page's title

Returns:


18
19
20
# File 'lib/redd/models/front_page.rb', line 18

def wiki_page(title)
  WikiPage.new(client, title: title)
end

#wiki_pagesArray<String>

Returns reddit's base wiki pages.

Returns:

  • (Array<String>)

    reddit's base wiki pages


11
12
13
# File 'lib/redd/models/front_page.rb', line 11

def wiki_pages
  client.get('/wiki/pages').body[:data]
end