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.


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)


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

def message
  @message
end

#recipient_nameObject (readonly)


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

def recipient_name
  @recipient_name
end

#tracksArray<Track> (readonly)


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

def tracks
  @tracks
end

Class Method Details

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


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


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

def loaded?
  status == :ok
end

#recipientUser


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

def recipient
  User.new(recipient_name)
end

#statusSymbol

Returns 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