Class: Hallon::User::Post

Inherits:
Base
  • Object
show all
Extended by:
Observable::Post
Includes:
Loadable
Defined in:
lib/hallon/user.rb

Overview

A Post is created upon sending tracks (with an optional message) to a user.

Instance Attribute Summary collapse

Attributes inherited from Base

#pointer

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Observable::Post

complete_callback, extended, initialize_callbacks

Methods included from Loadable

#load

Methods inherited from Base

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

Constructor Details

#initialize(recipient_name, message, tracks) ⇒ Post

Send a list of tracks to another users’ inbox.

Parameters:

  • recipient_name (String)

    username of person to send post to

  • message (String, nil)
  • tracks (Track, Array<Track>)


41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/hallon/user.rb', line 41

def initialize(recipient_name, message, tracks)
  tracks = Array(tracks)
  ary = FFI::MemoryPointer.new(:pointer, tracks.length)
  ary.write_array_of_pointer tracks.map(&:pointer)

  subscribe_for_callbacks do |callback|
    @tracks  = tracks
    @message = message
    @recipient_name = recipient_name
    @pointer = Spotify.inbox_post_tracks(session.pointer, @recipient_name, ary, tracks.length, @message, callback, nil)
  end
end

Instance Attribute Details

#messageObject (readonly)

Parameters:

  • message (String, nil)

    together with the post.



31
32
33
# File 'lib/hallon/user.rb', line 31

def message
  @message
end

#recipient_nameObject (readonly)

Parameters:

  • the (String)

    username of the post’s recipient.



34
35
36
# File 'lib/hallon/user.rb', line 34

def recipient_name
  @recipient_name
end

#tracksArray<Track> (readonly)

Returns an array of tracks posted.

Returns:

  • (Array<Track>)

    an array of tracks posted.



28
29
30
# File 'lib/hallon/user.rb', line 28

def tracks
  @tracks
end

Class Method Details

.create(recipient_name, message, tracks) ⇒ Post?

Returns post, or nil if posting failed.

Parameters:

  • recipient_name (String)

    username of person to send post to

  • message (String, nil)
  • tracks (Track, Array<Track>)

Returns:

  • (Post, nil)

    post, or nil if posting failed.



22
23
24
25
# File 'lib/hallon/user.rb', line 22

def self.create(recipient_name, message, tracks)
  post = new(recipient_name, message, tracks)
  post unless post.pointer.null?
end

Instance Method Details

#loaded?Boolean

Returns true if the post has been successfully sent.

Returns:

  • (Boolean)

    true if the post has been successfully sent.



60
61
62
# File 'lib/hallon/user.rb', line 60

def loaded?
  status == :ok
end

#recipientUser

Returns the user named #recipient_name.

Returns:



55
56
57
# File 'lib/hallon/user.rb', line 55

def recipient
  User.new(recipient_name)
end

#statusSymbol

Returns error status of inbox post.

Returns:

  • (Symbol)

    error status of inbox post

See Also:

  • Error.explain


66
67
68
# File 'lib/hallon/user.rb', line 66

def status
  Spotify.inbox_error(pointer)
end