Class: Twitch::V2::User
- Inherits:
-
Object
- Object
- Twitch::V2::User
- Defined in:
- lib/kappa/user.rb
Overview
These are members of the Twitch community who have a Twitch account. If broadcasting, they can own a stream that they can broadcast on their channel. If mainly viewing, they might follow or subscribe to channels.
Instance Attribute Summary collapse
-
#created_at ⇒ Time
readonly
When the user account was created (UTC).
-
#display_name ⇒ String
readonly
User-friendly display name.
-
#id ⇒ Fixnum
readonly
Unique Twitch ID.
-
#logo_url ⇒ String
readonly
URL for the logo image.
-
#name ⇒ String
readonly
Unique Twitch name.
-
#updated_at ⇒ Time
readonly
When the user account was last updated (UTC).
Instance Method Summary collapse
-
#channel ⇒ Channel
Get the
Channel
associated with this user. -
#following(options = {}) {|channel| ... } ⇒ Array<Channel>?
Get the channels the user is currently following.
-
#following?(target) ⇒ Boolean
true
if the user is following the channel,false
otherwise. -
#staff? ⇒ Boolean
true
if the user is a member of the Twitch.tv staff,false
otherwise. -
#stream ⇒ Stream
Get the live stream associated with this user.
-
#streaming? ⇒ Boolean
Is this user currently streaming?.
Instance Attribute Details
#created_at ⇒ Time (readonly)
Returns When the user account was created (UTC).
114 115 116 |
# File 'lib/kappa/user.rb', line 114 def created_at @created_at end |
#display_name ⇒ String (readonly)
Returns User-friendly display name.
124 125 126 |
# File 'lib/kappa/user.rb', line 124 def display_name @display_name end |
#id ⇒ Fixnum (readonly)
Returns Unique Twitch ID.
109 110 111 |
# File 'lib/kappa/user.rb', line 109 def id @id end |
#logo_url ⇒ String (readonly)
Returns URL for the logo image.
129 130 131 |
# File 'lib/kappa/user.rb', line 129 def logo_url @logo_url end |
#name ⇒ String (readonly)
Returns Unique Twitch name.
134 135 136 |
# File 'lib/kappa/user.rb', line 134 def name @name end |
#updated_at ⇒ Time (readonly)
Returns When the user account was last updated (UTC).
119 120 121 |
# File 'lib/kappa/user.rb', line 119 def updated_at @updated_at end |
Instance Method Details
#channel ⇒ Channel
This incurs an additional web request.
Get the Channel
associated with this user.
31 32 33 |
# File 'lib/kappa/user.rb', line 31 def channel @query.channels.get(@name) end |
#following(options = {}) {|channel| ... } ⇒ Array<Channel>?
Get the channels the user is currently following.
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/kappa/user.rb', line 73 def following( = {}, &block) name = CGI.escape(@name) return @query.connection.accumulate( :path => "users/#{name}/follows/channels", :json => 'follows', :sub_json => 'channel', :create => -> hash { Channel.new(hash, @query) }, :limit => [:limit], :offset => [:offset], &block ) end |
#following?(target) ⇒ Boolean
Returns true
if the user is following the channel, false
otherwise.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/kappa/user.rb', line 90 def following?(target) name = if target.respond_to?(:name) target.name else target.to_s end user_name = CGI.escape(@name) channel_name = CGI.escape(name) Twitch::Status.map(404 => false) do @query.connection.get("users/#{user_name}/follows/channels/#{channel_name}") true end end |
#staff? ⇒ Boolean
Returns true
if the user is a member of the Twitch.tv staff, false
otherwise.
52 53 54 |
# File 'lib/kappa/user.rb', line 52 def staff? @staff end |
#stream ⇒ Stream
This incurs an additional web request.
Get the live stream associated with this user.
39 40 41 |
# File 'lib/kappa/user.rb', line 39 def stream @query.streams.get(@name) end |
#streaming? ⇒ Boolean
This makes a separate request to get the user's stream. If you want to actually use the stream object, you should call #stream
instead.
Is this user currently streaming?
47 48 49 |
# File 'lib/kappa/user.rb', line 47 def streaming? !stream.nil? end |