Class: Turntabler::AuthorizedUser
- Defined in:
- lib/turntabler/authorized_user.rb
Overview
Represents a user who has authorized with the Turntable service
Instance Attribute Summary collapse
-
#auth ⇒ String
readonly
Gets the authentication token associated with this user for use with API services.
-
#email ⇒ String
readonly
The e-mail address the user registered with on Turntable.
-
#facebook_id ⇒ String
readonly
The user’s unique identifier on Facebook.
-
#password ⇒ String
readonly
The password associated with the e-mail address registered with on Turntable.
-
#playlists ⇒ Turntabler::PlaylistDirectory
readonly
The user’s custom playlists.
-
#preferences ⇒ Turntabler::Preferences
readonly
The user’s current Turntable preferences.
-
#status ⇒ String
readonly
The current availability status of the user (“available”, “unavailable”, or “away”).
-
#twitter_id ⇒ String
readonly
The user’s unique identifier on Twitter.
Attributes inherited from User
#about, #acl, #avatar, #facebook_url, #fans_count, #hangout, #laptop_name, #laptop_version, #name, #points, #sticker_placements, #top_artists, #website
Instance Method Summary collapse
-
#authenticate ⇒ true
private
Authenticates the current user with turntable.
-
#avatars ⇒ Array<Turntabler::Avatar>
Gets the avatars that can be set by this user.
-
#blocks ⇒ Array<Turntabler::User>
Gets the users that have been blocked by this user.
-
#buddies ⇒ Array<Turntabler::User>
Loads the list of users that are connected to the current user through a social network like Facebook or Twitter.
-
#fan_of ⇒ Array<Turntabler::User>
Loads the list of users that the current user is a fan of.
-
#fans ⇒ Array<Turntabler::User>
Loads the list of users that are a fan of the current user.
-
#id ⇒ String
Gets the Turntable id associated with this user for use with API services.
-
#initialize(client) ⇒ AuthorizedUser
constructor
private
A new instance of AuthorizedUser.
-
#load ⇒ true
Loads the attributes for this user.
-
#login ⇒ true
private
Logs the user in using the associated e-mail address / password.
-
#playlist(id = 'default') ⇒ Turntabler::Playlist
Gets the playlist with the given id.
-
#stickers_purchased ⇒ Array<Turntabler::Sticker>
Gets the stickers that have been purchased by this user.
-
#update(attributes = {}) ⇒ true
Updates this user’s profile information.
Methods inherited from User
#add_as_moderator, #become_fan, #block, #boot, #dj?, #listener?, #messages, #moderator?, #presence, #remove_as_dj, #remove_as_moderator, #report, #say, #stalk, #unblock, #unfan
Methods inherited from Resource
#==, attribute, #attributes=, #hash, #loaded?, #pretty_print, #pretty_print_instance_variables
Methods included from Assertions
#assert_valid_keys, #assert_valid_values
Methods included from DigestHelpers
Constructor Details
#initialize(client) ⇒ AuthorizedUser
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of AuthorizedUser.
44 45 46 47 48 49 |
# File 'lib/turntabler/authorized_user.rb', line 44 def initialize(client, *) @status = 'available' @playlists = PlaylistDirectory.new(client) @preferences = Preferences.new(client) super end |
Instance Attribute Details
#auth ⇒ String (readonly)
Gets the authentication token associated with this user for use with API services. This will log the user in via email / password if it’s not already set.
11 |
# File 'lib/turntabler/authorized_user.rb', line 11 attribute :auth, :userauth |
#email ⇒ String (readonly)
The e-mail address the user registered with on Turntable. This is typically only set if the user didn’t log in via Facebook or Twitter.
28 |
# File 'lib/turntabler/authorized_user.rb', line 28 attribute :email |
#facebook_id ⇒ String (readonly)
The user’s unique identifier on Facebook
19 |
# File 'lib/turntabler/authorized_user.rb', line 19 attribute :facebook_id, :fbid |
#password ⇒ String (readonly)
The password associated with the e-mail address registered with on Turntable. This is typically only set if the user didn’t log in via Facebook or Twitter.
33 |
# File 'lib/turntabler/authorized_user.rb', line 33 attribute :password |
#playlists ⇒ Turntabler::PlaylistDirectory (readonly)
The user’s custom playlists
37 38 39 |
# File 'lib/turntabler/authorized_user.rb', line 37 def playlists @playlists end |
#preferences ⇒ Turntabler::Preferences (readonly)
The user’s current Turntable preferences
41 42 43 |
# File 'lib/turntabler/authorized_user.rb', line 41 def preferences @preferences end |
#status ⇒ String (readonly)
The current availability status of the user (“available”, “unavailable”, or “away”)
15 |
# File 'lib/turntabler/authorized_user.rb', line 15 attribute :status |
#twitter_id ⇒ String (readonly)
The user’s unique identifier on Twitter
23 |
# File 'lib/turntabler/authorized_user.rb', line 23 attribute :twitter_id, :twitterid |
Instance Method Details
#authenticate ⇒ true
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Authenticates the current user with turntable.
92 93 94 95 |
# File 'lib/turntabler/authorized_user.rb', line 92 def authenticate api('user.authenticate') true end |
#avatars ⇒ Array<Turntabler::Avatar>
This may load the user’s data in order to get the ACL if it’s not available already
Gets the avatars that can be set by this user.
188 189 190 |
# File 'lib/turntabler/authorized_user.rb', line 188 def avatars client.avatars.select {|avatar| avatar.available?} end |
#blocks ⇒ Array<Turntabler::User>
Gets the users that have been blocked by this user.
220 221 222 223 |
# File 'lib/turntabler/authorized_user.rb', line 220 def blocks data = api('block.list_all') data['blocks'].map {|attrs| User.new(client, attrs['block']['blocked'])} end |
#buddies ⇒ Array<Turntabler::User>
Loads the list of users that are connected to the current user through a social network like Facebook or Twitter.
154 155 156 157 |
# File 'lib/turntabler/authorized_user.rb', line 154 def buddies data = api('user.get_buddies') data['buddies'].map {|id| User.new(client, :_id => id)} end |
#fan_of ⇒ Array<Turntabler::User>
Loads the list of users that the current user is a fan of.
165 166 167 168 |
# File 'lib/turntabler/authorized_user.rb', line 165 def fan_of data = api('user.get_fan_of') data['fanof'].map {|id| User.new(client, :_id => id)} end |
#fans ⇒ Array<Turntabler::User>
Loads the list of users that are a fan of the current user.
176 177 178 179 |
# File 'lib/turntabler/authorized_user.rb', line 176 def fans data = api('user.get_fans') data['fans'].map {|id| User.new(client, :_id => id)} end |
#id ⇒ String
Gets the Turntable id associated with this user for use with API services. This will log the user in via email / password if it’s not already set.
56 57 58 59 |
# File 'lib/turntabler/authorized_user.rb', line 56 def id login unless @id @id end |
#load ⇒ true
Loads the attributes for this user. Attributes will automatically load when accessed, but this allows data to be forcefully loaded upfront.
105 106 107 108 109 |
# File 'lib/turntabler/authorized_user.rb', line 105 def load data = api('user.info') self.attributes = data super end |
#login ⇒ true
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Logs the user in using the associated e-mail address / password. This will generate a user id / auth token for authentication with the API services.
78 79 80 81 82 83 84 85 |
# File 'lib/turntabler/authorized_user.rb', line 78 def login response = EventMachine::HttpRequest.new('https://turntable.fm/api/user.email_login').get(:query => {:email => email, :password => password, :client => client.id}).response success, data = response.empty? ? [nil, {}] : JSON.parse(response) raise(ConnectionError, data['err']) unless success self.attributes = data true end |
#playlist(id = 'default') ⇒ Turntabler::Playlist
Gets the playlist with the given id.
199 200 201 |
# File 'lib/turntabler/authorized_user.rb', line 199 def playlist(id = 'default') playlists.build(:_id => id) end |
#stickers_purchased ⇒ Array<Turntabler::Sticker>
Gets the stickers that have been purchased by this user.
209 210 211 212 |
# File 'lib/turntabler/authorized_user.rb', line 209 def stickers_purchased data = api('sticker.get_purchased_stickers') data['stickers'].map {|sticker_id| Sticker.new(client, :_id => sticker_id)} end |
#update(attributes = {}) ⇒ true
Updates this user’s profile information.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/turntabler/authorized_user.rb', line 130 def update(attributes = {}) assert_valid_keys(attributes, :name, :status, :laptop_name, :twitter_id, :facebook_url, :website, :about, :top_artists, :hangout) # Update status status = attributes.delete(:status) update_status(status) if status # Update laptop laptop_name = attributes.delete(:laptop_name) update_laptop(laptop_name) if laptop_name # Update profile with remaining data update_profile(attributes) if attributes.any? true end |