Class: Turntabler::User

Inherits:
Resource show all
Defined in:
lib/turntabler/user.rb

Overview

Represents an unauthorized user on Turntable

Direct Known Subclasses

AuthorizedUser

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#==, attribute, #attributes=, #hash, #initialize, #loaded?, #pretty_print, #pretty_print_instance_variables

Methods included from Assertions

#assert_valid_keys, #assert_valid_values

Methods included from DigestHelpers

#digest

Constructor Details

This class inherits a constructor from Turntabler::Resource

Instance Attribute Details

#aboutString (readonly)

A brief description about the user



53
# File 'lib/turntabler/user.rb', line 53

attribute :about

#aclFixnum (readonly)

The access control determining what is authorized



31
# File 'lib/turntabler/user.rb', line 31

attribute :acl

#avatarTurntabler::Avatar (readonly)

The user's currently active avatar



65
66
67
# File 'lib/turntabler/user.rb', line 65

attribute :avatar, :avatarid do |value|
  Avatar.new(client, :_id => value)
end

#facebook_urlString (readonly)

Note:

This is only available if the user is connected to the authorized user through Facebook

The user's unique identifier on Facebook



40
# File 'lib/turntabler/user.rb', line 40

attribute :facebook_url, :facebook

#fans_countFixnum (readonly)

The number of fans this user has



35
# File 'lib/turntabler/user.rb', line 35

attribute :fans_count, :fans

#hangoutString (readonly)

A description of the rooms on Turntable the user likes to hang out



61
# File 'lib/turntabler/user.rb', line 61

attribute :hangout

#idString (readonly)

Allow the id to be set via the “userid” attribute



11
# File 'lib/turntabler/user.rb', line 11

attribute :id, :userid, :load => false

#laptop_nameString (readonly)

The name of the laptop the DJ uses



19
# File 'lib/turntabler/user.rb', line 19

attribute :laptop_name, :laptop

#laptop_versionString (readonly)

The version # for the laptop



23
# File 'lib/turntabler/user.rb', line 23

attribute :laptop_version

#nameString (readonly)

The DJ name for this user



15
# File 'lib/turntabler/user.rb', line 15

attribute :name, :name, :username

#pointsFixnum (readonly)

The total number of points accumulated all-time



27
# File 'lib/turntabler/user.rb', line 27

attribute :points

#sticker_placements(reload = false) ⇒ Array<Turntabler::StickerPlacement> (readonly)

Gets the stickers that are currently placed on the user's laptop.

Examples:

user.sticker_placements   # => [#<Turntabler::StickerPlacement ...>, ...]

Raises:



71
72
73
74
# File 'lib/turntabler/user.rb', line 71

attribute :sticker_placements, :sticker_placements, :placements do |placements|
  placements = placements.keys if placements.is_a?(Hash)
  placements.map {|attrs| StickerPlacement.new(client, attrs)}
end

#top_artistsString (readonly)

The user's favorite artists



57
# File 'lib/turntabler/user.rb', line 57

attribute :top_artists, :topartists

#twitter_idString (readonly)

Note:

This is only available if the user is connected to the authorized user through Twitter

The user's unique identifier on Twitter



45
# File 'lib/turntabler/user.rb', line 45

attribute :twitter_id, :twitter, :twitterid_lower

#websiteString (readonly)

The user's personal website



49
# File 'lib/turntabler/user.rb', line 49

attribute :website

Instance Method Details

#add_as_moderatorObject

Adds the user as a moderator in the current room.

user.add_as_moderator   # => true


199
200
201
202
# File 'lib/turntabler/user.rb', line 199

def add_as_moderator
  api('room.add_moderator', :roomid => room.id, :section => room.section, :target_userid => id)
  true
end

#become_fantrue

Marks the current user as a fan of this user.

Examples:

user.become_fan   # => true

Raises:



119
120
121
122
# File 'lib/turntabler/user.rb', line 119

def become_fan
  api('user.become_fan', :djid => id)
  true
end

#blocktrue

Blocks this user from being able to send private messages.

Examples:

user.block    # => true

Raises:



235
236
237
238
# File 'lib/turntabler/user.rb', line 235

def block
  api('block.add', :blockedid => id)
  true
end

#boot(reason = '') ⇒ true

Boots the user for the specified reason.

Examples:

user.boot('Broke rules')    # => true

Raises:



258
259
260
261
# File 'lib/turntabler/user.rb', line 258

def boot(reason = '')
  api('room.boot_user', :roomid => room.id, :section => room.section, :target_userid => id, :reason => reason)
  true
end

#dj?Boolean

Is the user currently DJing in the room?

Examples:

user.dj?    # => false


172
173
174
# File 'lib/turntabler/user.rb', line 172

def dj?
  !room.dj(id).nil?
end

#listener?Boolean

Is the user currently a listener in the room?

Examples:

user.listener?    # => false


163
164
165
# File 'lib/turntabler/user.rb', line 163

def listener?
  !room.listener(id).nil?
end

#loadtrue

Loads the attributes for this user. Attributes will automatically load when accessed, but this allows data to be forcefully loaded upfront.

Examples:

user.load         # => true
user.laptop_name  # => "chrome"

Raises:



84
85
86
87
88
# File 'lib/turntabler/user.rb', line 84

def load
  data = api('user.get_profile', :profileid => id)
  self.attributes = data
  super
end

#messagesArray<Turntabler::Message>

Gets the private conversation history with this user.

Examples:

user.messages   # => [#<Turntabler::Message ...>, ...]

Raises:



153
154
155
156
# File 'lib/turntabler/user.rb', line 153

def messages
  data = api('pm.history', :receiverid => id)
  data['history'].map {|attrs| Message.new(client, attrs)}
end

#moderator?Boolean

Is the user currently a moderator for the room?

Examples:

user.moderator?   # => false


192
193
194
# File 'lib/turntabler/user.rb', line 192

def moderator?
  !room.moderator(id).nil?
end

#presenceString

Gets the availability status for this user.

Examples:

user.presence   # => "available"

Raises:



96
97
98
99
# File 'lib/turntabler/user.rb', line 96

def presence
  data = api('presence.get', :uid => id)
  data['presence']['status']
end

#remove_as_djtrue

Stops the user from DJing.

Examples:

user.remove_as_dj   # => true

Raises:



182
183
184
185
# File 'lib/turntabler/user.rb', line 182

def remove_as_dj
  api('room.rem_dj', :roomid => room.id, :section => room.section, :djid => id)
  true
end

#remove_as_moderatortrue

Removes the user from being a moderator in the current room.

Examples:

user.remove_as_moderator    # => true

Raises:



210
211
212
213
# File 'lib/turntabler/user.rb', line 210

def remove_as_moderator
  api('room.rem_moderator', :roomid => room.id, :section => room.section, :target_userid => id)
  true
end

#report(reason = '') ⇒ true

Reports abuse by a user.

Examples:

user.report('Verbal abuse ...')  # => true

Raises:



270
271
272
273
# File 'lib/turntabler/user.rb', line 270

def report(reason = '')
  api('room.report_user', :roomid => room.id, :section => room.section, :reported => id, :reason => reason)
  true
end

#say(content) ⇒ true

Sends a private message to this user.

Examples:

user.say("Hey what's up?")    # => true

Raises:



142
143
144
145
# File 'lib/turntabler/user.rb', line 142

def say(content)
  api('pm.send', :receiverid => id, :text => content)
  true
end

#stalkTurntabler::Room

Note:

This will make the current user a fan of this user

Gets the location of the user.

Examples:

user.stalk    # => #<Turntabler::Room ...>

Raises:



222
223
224
225
226
227
# File 'lib/turntabler/user.rb', line 222

def stalk
  become_fan unless client.user.fan_of.include?(self)
  client.rooms.with_friends.detect do |room|
    room.listener(id)
  end
end

#unblocktrue

Unblocks this user from being able to send private messages.

Examples:

user.unblock    # => true

Raises:



246
247
248
249
# File 'lib/turntabler/user.rb', line 246

def unblock
  api('block.remove', :blockedid => id)
  true
end

#unfantrue

Marks the current user no longer as a fan of this user.

Examples:

user.unfan    # => true

Raises:



130
131
132
133
# File 'lib/turntabler/user.rb', line 130

def unfan
  api('user.remove_fan', :djid => id)
  true
end