Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inboxPlaylist WIP. Works, but incorrectly follows the User.starredPlaylist pattern. Should be on PlaylistContainer instead? #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/objects/node/NodeSpotify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ Handle<Value> NodeSpotify::getSessionUser(Local<String> property, const Accessor
return scope.Close(nodeUser->getV8Object());
}

Handle<Value> NodeSpotify::getInboxPlaylist(Local<String> property, const AccessorInfo& info) {
HandleScope scope;
NodeSpotify* nodeSpotify = node::ObjectWrap::Unwrap<NodeSpotify>(info.Holder());
NodePlaylist* nodePlaylist = new NodePlaylist(nodeSpotify->spotify->inboxPlaylist());
return scope.Close(nodePlaylist->getV8Object());
}

Handle<Value> NodeSpotify::getConstants(Local<String> property, const AccessorInfo& info) {
HandleScope scope;
Local<Object> constants = Object::New();
Expand Down Expand Up @@ -198,6 +205,7 @@ void NodeSpotify::init() {
constructorTemplate->InstanceTemplate()->SetAccessor(String::NewSymbol("sessionUser"), getSessionUser);
constructorTemplate->InstanceTemplate()->SetAccessor(String::NewSymbol("playlistContainer"), getPlaylistContainer);
constructorTemplate->InstanceTemplate()->SetAccessor(String::NewSymbol("constants"), getConstants);
constructorTemplate->InstanceTemplate()->SetAccessor(String::NewSymbol("inboxPlaylist"), getInboxPlaylist);

constructor = Persistent<Function>::New(constructorTemplate->GetFunction());
scope.Close(Undefined());
Expand Down
1 change: 1 addition & 0 deletions src/objects/node/NodeSpotify.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class NodeSpotify : public NodeWrapped<NodeSpotify> {
static Handle<Value> getPlaylistContainer(Local<String> property, const AccessorInfo& info);
static Handle<Value> getRememberedUser(Local<String> property, const AccessorInfo& info);
static Handle<Value> getSessionUser(Local<String> property, const AccessorInfo& info);
static Handle<Value> getInboxPlaylist(Local<String> property, const AccessorInfo& info);
static Handle<Value> createFromLink(const Arguments& args);
static Handle<Value> getConstants(Local<String> property, const AccessorInfo& info);
static Handle<Value> on(const Arguments& other);
Expand Down
12 changes: 12 additions & 0 deletions src/objects/spotify/InboxPlaylist.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef _INBOX_PLAYLIST_H
#define _INBOX_PLAYLIST_H

#include "Playlist.h"

class InboxPlaylist : public Playlist {
public:
InboxPlaylist(sp_playlist* _playlist) : Playlist(_playlist) {};
std::string name() { return "Inbox"; }
};

#endif
7 changes: 7 additions & 0 deletions src/objects/spotify/Spotify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,11 @@ std::string Spotify::rememberedUser() {
std::shared_ptr<User> Spotify::sessionUser() {
auto user = std::make_shared<User>(sp_session_user(session));
return user;
}

std::shared_ptr<Playlist> Spotify::inboxPlaylist() {
std::shared_ptr<Playlist> playlist;
auto spotifyPlaylist = sp_session_inbox_create(session);
playlist = std::make_shared<InboxPlaylist>(spotifyPlaylist);
return playlist;
}
2 changes: 2 additions & 0 deletions src/objects/spotify/Spotify.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "SpotifyOptions.h"
#include "User.h"
#include "InboxPlaylist.h"

#include <libspotify/api.h>
#include <string>
Expand All @@ -16,6 +17,7 @@ class Spotify {
void logout();
std::string rememberedUser();
std::shared_ptr<User> sessionUser();
std::shared_ptr<Playlist> inboxPlaylist();
private:
sp_session* session;
sp_session* createSession(SpotifyOptions options);
Expand Down