From d826f51d58f498bb176fa3341e184f77bfd8fd3a Mon Sep 17 00:00:00 2001 From: Noah Zoschke Date: Fri, 20 Jun 2014 17:57:24 -0700 Subject: [PATCH] Implement sp_session_inbox_create API via spotify.inboxPlaylist accessor. --- src/objects/node/NodeSpotify.cc | 8 ++++++++ src/objects/node/NodeSpotify.h | 1 + src/objects/spotify/InboxPlaylist.h | 12 ++++++++++++ src/objects/spotify/Spotify.cc | 7 +++++++ src/objects/spotify/Spotify.h | 2 ++ 5 files changed, 30 insertions(+) create mode 100644 src/objects/spotify/InboxPlaylist.h diff --git a/src/objects/node/NodeSpotify.cc b/src/objects/node/NodeSpotify.cc index 14f5087..ef20b14 100644 --- a/src/objects/node/NodeSpotify.cc +++ b/src/objects/node/NodeSpotify.cc @@ -158,6 +158,13 @@ Handle NodeSpotify::getSessionUser(Local property, const Accessor return scope.Close(nodeUser->getV8Object()); } +Handle NodeSpotify::getInboxPlaylist(Local property, const AccessorInfo& info) { + HandleScope scope; + NodeSpotify* nodeSpotify = node::ObjectWrap::Unwrap(info.Holder()); + NodePlaylist* nodePlaylist = new NodePlaylist(nodeSpotify->spotify->inboxPlaylist()); + return scope.Close(nodePlaylist->getV8Object()); +} + Handle NodeSpotify::getConstants(Local property, const AccessorInfo& info) { HandleScope scope; Local constants = Object::New(); @@ -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::New(constructorTemplate->GetFunction()); scope.Close(Undefined()); diff --git a/src/objects/node/NodeSpotify.h b/src/objects/node/NodeSpotify.h index 37c4a14..d4cbc8a 100644 --- a/src/objects/node/NodeSpotify.h +++ b/src/objects/node/NodeSpotify.h @@ -18,6 +18,7 @@ class NodeSpotify : public NodeWrapped { static Handle getPlaylistContainer(Local property, const AccessorInfo& info); static Handle getRememberedUser(Local property, const AccessorInfo& info); static Handle getSessionUser(Local property, const AccessorInfo& info); + static Handle getInboxPlaylist(Local property, const AccessorInfo& info); static Handle createFromLink(const Arguments& args); static Handle getConstants(Local property, const AccessorInfo& info); static Handle on(const Arguments& other); diff --git a/src/objects/spotify/InboxPlaylist.h b/src/objects/spotify/InboxPlaylist.h new file mode 100644 index 0000000..556d76a --- /dev/null +++ b/src/objects/spotify/InboxPlaylist.h @@ -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 \ No newline at end of file diff --git a/src/objects/spotify/Spotify.cc b/src/objects/spotify/Spotify.cc index b905984..311d2cd 100644 --- a/src/objects/spotify/Spotify.cc +++ b/src/objects/spotify/Spotify.cc @@ -84,4 +84,11 @@ std::string Spotify::rememberedUser() { std::shared_ptr Spotify::sessionUser() { auto user = std::make_shared(sp_session_user(session)); return user; +} + +std::shared_ptr Spotify::inboxPlaylist() { + std::shared_ptr playlist; + auto spotifyPlaylist = sp_session_inbox_create(session); + playlist = std::make_shared(spotifyPlaylist); + return playlist; } \ No newline at end of file diff --git a/src/objects/spotify/Spotify.h b/src/objects/spotify/Spotify.h index abccdb9..15a936e 100644 --- a/src/objects/spotify/Spotify.h +++ b/src/objects/spotify/Spotify.h @@ -3,6 +3,7 @@ #include "SpotifyOptions.h" #include "User.h" +#include "InboxPlaylist.h" #include #include @@ -16,6 +17,7 @@ class Spotify { void logout(); std::string rememberedUser(); std::shared_ptr sessionUser(); + std::shared_ptr inboxPlaylist(); private: sp_session* session; sp_session* createSession(SpotifyOptions options);