Class: Twitch::V2::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/kappa/channel.rb

Overview

Channels serve as the home location for a user's content. Channels have a stream, can run commercials, store videos, display information and status, and have a customized page including banners and backgrounds.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#background_urlString (readonly)

Returns URL for background image.

Examples:

"http://static-cdn.jtvnw.net/jtv_user_pictures/lethalfrag-channel_background_image-833a4324bc698c9b.jpeg"

Returns:

  • (String)

    URL for background image.



132
133
134
# File 'lib/kappa/channel.rb', line 132

def background_url
  @background_url
end

Returns URL for banner image.

Examples:

"http://static-cdn.jtvnw.net/jtv_user_pictures/lethalfrag-channel_header_image-463a4670c91c2b61-640x125.jpeg"

Returns:

  • (String)

    URL for banner image.



137
138
139
# File 'lib/kappa/channel.rb', line 137

def banner_url
  @banner_url
end

#created_atTime (readonly)

Returns When the channel was created (UTC).

Examples:

2011-07-15 07:53:58 UTC

Returns:

  • (Time)

    When the channel was created (UTC).



142
143
144
# File 'lib/kappa/channel.rb', line 142

def created_at
  @created_at
end

#display_nameString (readonly)

Returns User-friendly display name. This name is used for the channel's page title.

Examples:

"Lethalfrag"

Returns:

  • (String)

    User-friendly display name. This name is used for the channel's page title.

See Also:



148
149
150
# File 'lib/kappa/channel.rb', line 148

def display_name
  @display_name
end

#game_nameString (readonly)

Returns Name of the primary game for this channel.

Examples:

"Super Meat Boy"

Returns:

  • (String)

    Name of the primary game for this channel.



153
154
155
# File 'lib/kappa/channel.rb', line 153

def game_name
  @game_name
end

#idFixnum (readonly)

Returns Unique Twitch ID.

Examples:

23460970

Returns:

  • (Fixnum)

    Unique Twitch ID.



127
128
129
# File 'lib/kappa/channel.rb', line 127

def id
  @id
end

#logo_urlString (readonly)

Returns URL for the logo image.

Examples:

"http://static-cdn.jtvnw.net/jtv_user_pictures/lethalfrag-profile_image-050adf252718823b-300x300.png"

Returns:

  • (String)

    URL for the logo image.



158
159
160
# File 'lib/kappa/channel.rb', line 158

def logo_url
  @logo_url
end

#nameString (readonly)

Returns Unique Twitch name.

Examples:

"lethalfrag"

Returns:

  • (String)

    Unique Twitch name.

See Also:



164
165
166
# File 'lib/kappa/channel.rb', line 164

def name
  @name
end

#statusString (readonly)

Returns Current status set by the channel's owner.

Examples:

"(Day 563/731) | Dinner and a Game (Cooking at http://twitch.tv/lookatmychicken)"

Returns:

  • (String)

    Current status set by the channel's owner.



169
170
171
# File 'lib/kappa/channel.rb', line 169

def status
  @status
end

#teamsArray<Team> (readonly)

Returns The list of teams that this channel is associated with. Not all channels have associated teams.

Returns:

  • (Array<Team>)

    The list of teams that this channel is associated with. Not all channels have associated teams.

See Also:



188
189
190
# File 'lib/kappa/channel.rb', line 188

def teams
  @teams
end

#updated_atTime (readonly)

Returns When the channel was last updated (UTC). For example, when a stream is started or a channel's status is changed, the channel is updated.

Examples:

2013-07-21 05:27:58 UTC

Returns:

  • (Time)

    When the channel was last updated (UTC). For example, when a stream is started or a channel's status is changed, the channel is updated.



174
175
176
# File 'lib/kappa/channel.rb', line 174

def updated_at
  @updated_at
end

#urlString (readonly)

Returns The URL for the channel's main page.

Examples:

"http://www.twitch.tv/lethalfrag"

Returns:

  • (String)

    The URL for the channel's main page.



179
180
181
# File 'lib/kappa/channel.rb', line 179

def url
  @url
end

#video_banner_urlString (readonly)

Returns URL for the image shown when the stream is offline.

Examples:

"http://static-cdn.jtvnw.net/jtv_user_pictures/lethalfrag-channel_offline_image-3b801b2ccc11830b-640x360.jpeg"

Returns:

  • (String)

    URL for the image shown when the stream is offline.



184
185
186
# File 'lib/kappa/channel.rb', line 184

def video_banner_url
  @video_banner_url
end

Instance Method Details

#followers(options = {}) {|follower| ... } ⇒ Array<User>?

Note:

The number of followers is potentially very large, so it's recommended that you specify a :limit.

Get the users following this channel.

Examples:

channel.followers(:limit => 20)
channel.followers do |follower|
  puts follower.display_name
end

Parameters:

  • options (Hash) (defaults to: {})

    Filter criteria.

Options Hash (options):

  • :limit (Fixnum) — default: nil

    Limit on the number of results returned.

  • :offset (Fixnum) — default: 0

    Offset into the result set to begin enumeration.

Yields:

  • Optional. If a block is given, each follower is yielded.

Yield Parameters:

  • follower (User)

    Current follower.

Returns:

  • (Array<User>)

    Users following this channel, if no block is given.

  • (nil)

    If a block is given.

See Also:



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/kappa/channel.rb', line 85

def followers(options = {}, &block)
  name = CGI.escape(@name)
  return @query.connection.accumulate(
    :path => "channels/#{name}/follows",
    :json => 'follows',
    :sub_json => 'user',
    :create => -> hash { User.new(hash, @query) },
    :limit => options[:limit],
    :offset => options[:offset],
    &block
  )
end

#mature?Boolean

Does this channel have mature content? This flag is specified by the owner of the channel.

Returns:

  • (Boolean)

    true if the channel has mature content, false otherwise.



41
42
43
# File 'lib/kappa/channel.rb', line 41

def mature?
  @mature
end

#streamStream

Note:

This incurs an additional web request.

Get the live stream associated with this channel.

Returns:

  • (Stream)

    Live stream object for this channel, or nil if the channel is not currently streaming.

See Also:



49
50
51
# File 'lib/kappa/channel.rb', line 49

def stream
  @query.streams.get(@name)
end

#streaming?Boolean

Note:

This makes a separate request to get the channel's stream. If you want to actually use the stream object, you should call #stream instead.

Does this channel currently have a live stream?

Returns:

  • (Boolean)

    true if the channel currently has a live stream, false otherwise.

See Also:



57
58
59
# File 'lib/kappa/channel.rb', line 57

def streaming?
  !stream.nil?
end

#userUser

Note:

This incurs an additional web request.

Get the owner of this channel.

Returns:

  • (User)

    The user that owns this channel.



64
65
66
# File 'lib/kappa/channel.rb', line 64

def user
  @query.users.get(@name)
end

#videos(options = {}) {|video| ... } ⇒ Array<Video>?

Note:

This incurs additional web requests.

Note:

You can get videos directly from a channel name via Videos#for_channel.

Get the videos for a channel, most recently created first.

Examples:

v = channel.videos(:type => :broadcasts)
channel.videos(:type => :highlights) do |video|
  next if video.view_count < 10000
  puts video.url
end 

Parameters:

  • options (Hash) (defaults to: {})

    Filter criteria.

Options Hash (options):

  • :type (Symbol) — default: :highlights

    The type of videos to return. Valid values are :broadcasts, :highlights.

  • :limit (Fixnum) — default: nil

    Limit on the number of results returned.

  • :offset (Fixnum) — default: 0

    Offset into the result set to begin enumeration.

Yields:

  • Optional. If a block is given, each video is yielded.

Yield Parameters:

  • video (Video)

    Current video.

Returns:

  • (Array<Video>)

    Videos for the channel, if no block is given.

  • (nil)

    If a block is given.

Raises:

  • (ArgumentError)

    If :type is not one of :broadcasts or :highlights.

See Also:



120
121
122
# File 'lib/kappa/channel.rb', line 120

def videos(options = {}, &block)
  @query.videos.for_channel(@name, options, &block)
end