Class: Redd::Models::Multireddit

Inherits:
LazyModel show all
Defined in:
lib/redd/models/multireddit.rb

Overview

A multi.

Instance Attribute Summary

Attributes inherited from BasicModel

#client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from LazyModel

#force_load, #initialize, #method_missing, #respond_to_missing?, #to_h

Methods inherited from BasicModel

#initialize, #inspect, #method_missing, #respond_to_missing?, #to_ary, #to_h

Constructor Details

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Redd::Models::LazyModel

Class Method Details

.from_id(client, id) ⇒ Multireddit

Create a Multireddit from its path.

Parameters:

  • client (APIClient)

    the api client to initialize the object with

  • id (String)

    the multi's path (with a leading and trailing slash)

Returns:


13
14
15
# File 'lib/redd/models/multireddit.rb', line 13

def self.from_id(client, id)
  new(client, path: id)
end

Instance Method Details

#comments(**params) ⇒ Object

See Also:


44
45
46
# File 'lib/redd/models/multireddit.rb', line 44

%i(hot new top controversial comments rising gilded).each do |sort|
  define_method(sort) { |**params| listing(sort, **params) }
end

#controversial(**params) ⇒ Object

See Also:


44
45
46
# File 'lib/redd/models/multireddit.rb', line 44

%i(hot new top controversial comments rising gilded).each do |sort|
  define_method(sort) { |**params| listing(sort, **params) }
end

#gilded(**params) ⇒ Object

See Also:


44
45
46
# File 'lib/redd/models/multireddit.rb', line 44

%i(hot new top controversial comments rising gilded).each do |sort|
  define_method(sort) { |**params| listing(sort, **params) }
end

#hot(**params) ⇒ Object

See Also:


44
45
46
# File 'lib/redd/models/multireddit.rb', line 44

%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.

Parameters:

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

    the type of listing

  • params (Hash)

    a list of params to send with the request

Options Hash (**params):

  • :after (String)

    return results after the given fullname

  • :before (String)

    return results before the given fullname

  • :count (Integer)

    the number of items already seen in the listing

  • :limit (1..100)

    the maximum number of things to return

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

    the time period to consider when sorting.

Returns:


30
31
32
33
# File 'lib/redd/models/multireddit.rb', line 30

def listing(sort, **params)
  params[:t] = params.delete(:time) if params.key?(:time)
  @client.model(:get, "#{get_attribute(:path)}#{sort}", params)
end

#new(**params) ⇒ Object

See Also:


44
45
46
# File 'lib/redd/models/multireddit.rb', line 44

%i(hot new top controversial comments rising gilded).each do |sort|
  define_method(sort) { |**params| listing(sort, **params) }
end

#rising(**params) ⇒ Object

See Also:


44
45
46
# File 'lib/redd/models/multireddit.rb', line 44

%i(hot new top controversial comments rising gilded).each do |sort|
  define_method(sort) { |**params| listing(sort, **params) }
end

#top(**params) ⇒ Object

See Also:


44
45
46
# File 'lib/redd/models/multireddit.rb', line 44

%i(hot new top controversial comments rising gilded).each do |sort|
  define_method(sort) { |**params| listing(sort, **params) }
end