Class: Hallon::User::Post
Overview
A Post is created upon sending tracks (with an optional message) to a user.
Instance Attribute Summary collapse
- #message ⇒ Object readonly
- #recipient_name ⇒ Object readonly
-
#tracks ⇒ Array<Track>
readonly
An array of tracks posted.
Attributes inherited from Base
Class Method Summary collapse
-
.create(recipient_name, message, tracks) ⇒ Post?
Post, or nil if posting failed.
Instance Method Summary collapse
-
#initialize(recipient_name, message, tracks) ⇒ Post
constructor
Send a list of tracks to another users’ inbox.
-
#loaded? ⇒ Boolean
True if the post has been successfully sent.
-
#recipient ⇒ User
The user named #recipient_name.
-
#status ⇒ Symbol
Error status of inbox post.
Methods included from Observable::Post
complete_callback, extended, initialize_callbacks
Methods included from Loadable
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, , 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 = @recipient_name = recipient_name @pointer = Spotify.inbox_post_tracks(session.pointer, @recipient_name, ary, tracks.length, @message, callback, nil) end end |
Instance Attribute Details
#message ⇒ Object (readonly)
31 32 33 |
# File 'lib/hallon/user.rb', line 31 def @message end |
#recipient_name ⇒ Object (readonly)
34 35 36 |
# File 'lib/hallon/user.rb', line 34 def recipient_name @recipient_name end |
#tracks ⇒ Array<Track> (readonly)
Returns 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.
22 23 24 25 |
# File 'lib/hallon/user.rb', line 22 def self.create(recipient_name, , tracks) post = new(recipient_name, , tracks) post unless post.pointer.null? end |
Instance Method Details
#loaded? ⇒ Boolean
Returns true if the post has been successfully sent.
60 61 62 |
# File 'lib/hallon/user.rb', line 60 def loaded? status == :ok end |
#recipient ⇒ User
Returns the user named #recipient_name.
55 56 57 |
# File 'lib/hallon/user.rb', line 55 def recipient User.new(recipient_name) end |
#status ⇒ Symbol
Returns error status of inbox post.
66 67 68 |
# File 'lib/hallon/user.rb', line 66 def status Spotify.inbox_error(pointer) end |