Class: Redd::Models::LiveThread

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

Overview

Represents a live thread.

Defined Under Namespace

Classes: LiveUpdate

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) ⇒ LiveThread

Get a LiveThread from its id.

Parameters:

  • id (String)

    the id

Returns:


16
17
18
# File 'lib/redd/models/live_thread.rb', line 16

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

Instance Method Details

#configure(**params) ⇒ Object

Configure the settings of this live thread

Parameters:

  • params (Hash)

    a list of params to send with the request

Options Hash (**params):

  • :description (String)

    the new description

  • :nsfw (Boolean)

    whether the thread is for users 18 and above

  • :resources (String)

    the new resources

  • :title (String)

    the thread title


37
38
39
# File 'lib/redd/models/live_thread.rb', line 37

def configure(**params)
  @client.post("/api/live/#{get_attribute(:id)}/edit", params)
end

#contributorsArray<User>

Returns the contributors to this thread.

Returns:

  • (Array<User>)

    the contributors to this thread


48
49
50
51
52
# File 'lib/redd/models/live_thread.rb', line 48

def contributors
  @client.get("/live/#{get_attribute(:id)}/contributors").body[0][:data].map do |user|
    User.new(@client, user)
  end
end

#discussions(**params) ⇒ Listing<Submission>

Returns all discussions that link to this live thread.

Parameters:

  • 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

Returns:


69
70
71
# File 'lib/redd/models/live_thread.rb', line 69

def discussions(**params)
  @client.model(:get, "/live/#{get_attribute(:id)}/discussions", params)
end

#invited_contributorsArray<User>

Returns users invited to contribute to this thread.

Returns:

  • (Array<User>)

    users invited to contribute to this thread


55
56
57
58
59
# File 'lib/redd/models/live_thread.rb', line 55

def invited_contributors
  @client.get("/live/#{get_attribute(:id)}/contributors").body[1][:data].map do |user|
    User.new(@client, user)
  end
end

#update(body) ⇒ Object

Add an update to this live event.

Parameters:

  • body (String)

    the update text


43
44
45
# File 'lib/redd/models/live_thread.rb', line 43

def update(body)
  @client.post("/api/live/#{get_attribute(:id)}/update", body: body)
end

#updates(**params) ⇒ Listing

Get the updates from the thread.

Parameters:

  • 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

Returns:


27
28
29
# File 'lib/redd/models/live_thread.rb', line 27

def updates(**params)
  @client.model(:get, "/live/#{get_attribute(:id)}", params)
end