Class: Twitch::V2::User

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

Instance Method Summary collapse

Instance Attribute Details

#created_atTime (readonly)

Returns When the user account was created (UTC).

Examples:

2011-08-08 21:03:44 UTC

Returns:

  • (Time)

    When the user account was created (UTC).



114
115
116
# File 'lib/kappa/user.rb', line 114

def created_at
  @created_at
end

#display_nameString (readonly)

Returns User-friendly display name.

Examples:

"LAGTVMaximusBlack"

Returns:

  • (String)

    User-friendly display name.



124
125
126
# File 'lib/kappa/user.rb', line 124

def display_name
  @display_name
end

#idFixnum (readonly)

Returns Unique Twitch ID.

Examples:

23945610 

Returns:

  • (Fixnum)

    Unique Twitch ID.



109
110
111
# File 'lib/kappa/user.rb', line 109

def id
  @id
end

#logo_urlString (readonly)

Returns URL for the logo image.

Examples:

"http://static-cdn.jtvnw.net/jtv_user_pictures/lagtvmaximusblack-profile_image-4b77a2305f5d85c8-300x300.png"

Returns:

  • (String)

    URL for the logo image.



129
130
131
# File 'lib/kappa/user.rb', line 129

def logo_url
  @logo_url
end

#nameString (readonly)

Returns Unique Twitch name.

Examples:

"lagtvmaximusblack"

Returns:

  • (String)

    Unique Twitch name.



134
135
136
# File 'lib/kappa/user.rb', line 134

def name
  @name
end

#updated_atTime (readonly)

Returns When the user account was last updated (UTC).

Examples:

2013-07-19 23:51:43 UTC

Returns:

  • (Time)

    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

#channelChannel

Note:

This incurs an additional web request.

Get the Channel associated with this user.

Returns:

  • (Channel)

    The Channel associated with this user, or nil if this is a Justin.tv account.

See Also:

  • Channel#get


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.

Examples:

user.following(:limit => 10)
user.following do |channel|
  next if channel.game_name !~ /starcraft/i
  puts channel.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 followed channel is yielded.

Yield Parameters:

  • channel (Channel)

    Current channel.

Returns:

  • (Array<Channel>)

    Channels the user is currently following, if no block is given.

  • (nil)

    If a block is given.

See Also:



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/kappa/user.rb', line 73

def following(options = {}, &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 => options[:limit],
    :offset => options[:offset],
    &block
  )
end

#following?(target) ⇒ Boolean

Returns true if the user is following the channel, false otherwise.

Parameters:

Returns:

  • (Boolean)

    true if the user is following the channel, false otherwise.

See Also:



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.

Returns:

  • (Boolean)

    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

#streamStream

Note:

This incurs an additional web request.

Get the live stream associated with this user.

Returns:

  • (Stream)

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

See Also:



39
40
41
# File 'lib/kappa/user.rb', line 39

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

#streaming?Boolean

Note:

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?

Returns:

  • (Boolean)

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

See Also:



47
48
49
# File 'lib/kappa/user.rb', line 47

def streaming?
  !stream.nil?
end