Class: Hallon::User

Inherits:
Base
  • Object
show all
Includes:
Linkable, Loadable
Defined in:
lib/hallon/user.rb

Overview

Users are the entities that interact with the Spotify service.

Methods are available for retrieving metadata and relationship status between users.

Defined Under Namespace

Classes: Post

Instance Attribute Summary

Attributes inherited from Base

#pointer

Instance Method Summary collapse

Methods included from Loadable

#load

Methods included from Linkable

#===, included, #to_str

Methods inherited from Base

#==, from, from_link, #is_linkable?, #session, to_link, #to_pointer, #to_s

Constructor Details

#initialize(link) ⇒ User (private)

Note:

You can also instantiate User with a canonical username

Construct a new instance of User.

Examples:

from a canonical username

Hallon::User.new("burgestrand")

from a spotify URI

Hallon::User.new("spotify:user:burgestrand")

Parameters:

  • link (String, Link, Spotify::User)

90
91
92
93
94
95
96
# File 'lib/hallon/user.rb', line 90

def initialize(link)
  @pointer = to_pointer(link, Spotify::User) do
    if link.is_a?(String) and link !~ /\Aspotify:user:/
      to_pointer("spotify:user:#{link}", Spotify::User)
    end
  end
end

Instance Method Details

#display_nameString (private)

Note:

Unless is true, this will return the same thing as .

Returns display name of the User.

Returns:

  • (String)

    display name of the User.


110
111
112
# File 'lib/hallon/user.rb', line 110

def display_name
  Spotify.user_display_name(pointer)
end

Returns pointer representation of given link.

Parameters:

Returns:

  • (Spotify::Link)

    pointer representation of given link.


74
75
76
# File 'lib/hallon/user.rb', line 74

from_link :profile do |link|
  Spotify.link_as_user(link)
end

#loaded?Boolean (private)

Returns true if the user is loaded.

Returns:

  • (Boolean)

    true if the user is loaded.


99
100
101
# File 'lib/hallon/user.rb', line 99

def loaded?
  Spotify.user_is_loaded(pointer)
end

#nameString (private)

Returns canonical name of the User.

Returns:

  • (String)

    canonical name of the User.


104
105
106
# File 'lib/hallon/user.rb', line 104

def name
  Spotify.user_canonical_name(pointer)
end

#post(message, tracks) ⇒ Post? (private) #post(tracks) ⇒ Post? (private)

Send tracks to this users’ inbox, with an optional message.

Overloads:

Returns:

  • (Post, nil)

    post, or nil if posting failed.


138
139
140
# File 'lib/hallon/user.rb', line 138

def post(message = nil, tracks)
  Post.create(name, message, tracks)
end

#publishedPlaylistContainer? (private)

Note:

Returns nil unless

Returns published playlists of the User.

Returns:


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

def published
  container = Spotify.session_publishedcontainer_for_user_create(session.pointer, name)
  PlaylistContainer.from(container)
end

#starredPlaylist? (private)

Note:

Returns nil unless #loaded?

Returns starred playlist of the User.

Returns:

  • (Playlist, nil)

    starred playlist of the User.


116
117
118
119
# File 'lib/hallon/user.rb', line 116

def starred
  playlist = Spotify.session_starred_for_user_create(session.pointer, name)
  Playlist.from(playlist)
end

Returns Link for the current object.

Returns:


78
# File 'lib/hallon/user.rb', line 78

to_link :from_user