Added feature to retrieve song records in json format. One issue is that the json file is in one line
This commit is contained in:
@@ -50,6 +50,7 @@ set(SOURCES
|
|||||||
src/Parsers/APIParser.cpp
|
src/Parsers/APIParser.cpp
|
||||||
src/Syncers/Delete.cpp
|
src/Syncers/Delete.cpp
|
||||||
src/Syncers/Download.cpp
|
src/Syncers/Download.cpp
|
||||||
|
src/Syncers/RetrieveRecords.cpp
|
||||||
src/Syncers/Upload.cpp
|
src/Syncers/Upload.cpp
|
||||||
src/Utilities/Conversions.cpp
|
src/Utilities/Conversions.cpp
|
||||||
)
|
)
|
||||||
@@ -69,6 +70,7 @@ set(HEADERS
|
|||||||
include/Parsers/APIParser.h
|
include/Parsers/APIParser.h
|
||||||
include/Syncers/Delete.h
|
include/Syncers/Delete.h
|
||||||
include/Syncers/Download.h
|
include/Syncers/Download.h
|
||||||
|
include/Syncers/RetrieveRecords.h
|
||||||
include/Syncers/SyncerBase.h
|
include/Syncers/SyncerBase.h
|
||||||
include/Syncers/Upload.h
|
include/Syncers/Upload.h
|
||||||
include/Utilities/Conversions.h
|
include/Utilities/Conversions.h
|
||||||
|
|||||||
@@ -16,12 +16,19 @@ namespace Managers
|
|||||||
CommitManager(Models::IcarusAction);
|
CommitManager(Models::IcarusAction);
|
||||||
|
|
||||||
void commitAction();
|
void commitAction();
|
||||||
|
|
||||||
|
enum RetrieveTypes
|
||||||
|
{
|
||||||
|
songs
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Models::Token parseToken(Models::API);
|
Models::Token parseToken(Models::API);
|
||||||
|
|
||||||
void initializeMapActions();
|
void initializeMapActions();
|
||||||
void deleteSong();
|
void deleteSong();
|
||||||
void downloadSong();
|
void downloadSong();
|
||||||
|
void retrieveObjects();
|
||||||
void uploadSong();
|
void uploadSong();
|
||||||
|
|
||||||
enum ActionValues
|
enum ActionValues
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef RETRIEVERECORDS_H_
|
||||||
|
#define RETRIEVERECORDS_H_
|
||||||
|
|
||||||
|
#include "Managers/CommitManager.h"
|
||||||
|
#include "Models/API.h"
|
||||||
|
#include "Models/Token.h"
|
||||||
|
|
||||||
|
namespace Syncers
|
||||||
|
{
|
||||||
|
class RetrieveRecords
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RetrieveRecords();
|
||||||
|
RetrieveRecords(Models::API, Models::Token);
|
||||||
|
|
||||||
|
void retrieve(Managers::CommitManager::RetrieveTypes);
|
||||||
|
private:
|
||||||
|
void fetchSongs();
|
||||||
|
|
||||||
|
Models::API api;
|
||||||
|
Models::Token token;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
+10
-10
@@ -14,17 +14,17 @@ using Managers::CommitManager;
|
|||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
{
|
{
|
||||||
cout<<"No actions provided"<<endl;
|
cout<<"No actions provided"<<endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ActionManager actMgr{argv};
|
ActionManager actMgr{argv};
|
||||||
auto chosenAction = actMgr.retrieveIcarusAction();
|
auto chosenAction = actMgr.retrieveIcarusAction();
|
||||||
|
|
||||||
CommitManager commitMgr{chosenAction};
|
CommitManager commitMgr{chosenAction};
|
||||||
commitMgr.commitAction();
|
commitMgr.commitAction();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ namespace Managers
|
|||||||
{
|
{
|
||||||
supportedFlags = vector<string>{
|
supportedFlags = vector<string>{
|
||||||
"-u", "-p", "-t", "-h", "-s",
|
"-u", "-p", "-t", "-h", "-s",
|
||||||
"-d", "-D", "-b"
|
"-d", "-D", "-b", "-rt"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
void ActionManager::validateAction()
|
void ActionManager::validateAction()
|
||||||
@@ -109,7 +109,7 @@ namespace Managers
|
|||||||
if (flag.size() > 3 || isNumber(flag))
|
if (flag.size() > 3 || isNumber(flag))
|
||||||
{
|
{
|
||||||
flg.value = flag;
|
flg.value = flag;
|
||||||
//cout<<"flag value "<<flg.value<<endl;
|
cout<<"flag value "<<flg.value<<endl;
|
||||||
flags.push_back(flg);
|
flags.push_back(flg);
|
||||||
flg = Flags{};
|
flg = Flags{};
|
||||||
continue;
|
continue;
|
||||||
@@ -121,7 +121,7 @@ namespace Managers
|
|||||||
return !val.compare(flag);
|
return !val.compare(flag);
|
||||||
}))
|
}))
|
||||||
{
|
{
|
||||||
//cout<<"flag "<<flag<<endl;
|
cout<<"flag "<<flag<<endl;
|
||||||
flg.flag = flag;
|
flg.flag = flag;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include"Parsers/APIParser.h"
|
#include"Parsers/APIParser.h"
|
||||||
#include"Syncers/Delete.h"
|
#include"Syncers/Delete.h"
|
||||||
#include"Syncers/Download.h"
|
#include"Syncers/Download.h"
|
||||||
|
#include"Syncers/RetrieveRecords.h"
|
||||||
#include"Syncers/Upload.h"
|
#include"Syncers/Upload.h"
|
||||||
|
|
||||||
#include"Managers/TokenManager.h"
|
#include"Managers/TokenManager.h"
|
||||||
@@ -27,6 +28,7 @@ using Parsers::APIParser;
|
|||||||
using Models::IcarusAction;
|
using Models::IcarusAction;
|
||||||
using Syncers::Delete;
|
using Syncers::Delete;
|
||||||
using Syncers::Download;
|
using Syncers::Download;
|
||||||
|
using Syncers::RetrieveRecords;
|
||||||
using Syncers::Upload;
|
using Syncers::Upload;
|
||||||
|
|
||||||
namespace Managers
|
namespace Managers
|
||||||
@@ -54,6 +56,7 @@ namespace Managers
|
|||||||
downloadSong();
|
downloadSong();
|
||||||
break;
|
break;
|
||||||
case retrieveAct: // No plans to imeplement
|
case retrieveAct: // No plans to imeplement
|
||||||
|
retrieveObjects();
|
||||||
break;
|
break;
|
||||||
case uploadAct:
|
case uploadAct:
|
||||||
uploadSong();
|
uploadSong();
|
||||||
@@ -134,6 +137,35 @@ namespace Managers
|
|||||||
cout<<"downloading song"<<endl;
|
cout<<"downloading song"<<endl;
|
||||||
dnld.downloadSong(token, song);
|
dnld.downloadSong(token, song);
|
||||||
}
|
}
|
||||||
|
void CommitManager::retrieveObjects()
|
||||||
|
{
|
||||||
|
cout<<"Starting retrieve process..."<<endl;
|
||||||
|
|
||||||
|
APIParser apiPrs{icaAction};
|
||||||
|
auto api = apiPrs.retrieveAPI();
|
||||||
|
|
||||||
|
auto token = parseToken(api);
|
||||||
|
RetrieveTypes retrieveType;
|
||||||
|
|
||||||
|
for (auto arg : icaAction.flags)
|
||||||
|
{
|
||||||
|
auto flag = arg.flag;
|
||||||
|
auto value = arg.value;
|
||||||
|
|
||||||
|
if (flag.compare("-rt") == 0)
|
||||||
|
{
|
||||||
|
if (value.compare("songs") == 0)
|
||||||
|
{
|
||||||
|
retrieveType = RetrieveTypes::songs;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RetrieveRecords songs{api, token};
|
||||||
|
songs.retrieve(retrieveType);
|
||||||
|
|
||||||
|
}
|
||||||
void CommitManager::uploadSong()
|
void CommitManager::uploadSong()
|
||||||
{
|
{
|
||||||
APIParser apiPrs{icaAction};
|
APIParser apiPrs{icaAction};
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
#include "Syncers/RetrieveRecords.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include <cpr/cpr.h>
|
||||||
|
|
||||||
|
using std::cout;
|
||||||
|
using std::endl;
|
||||||
|
using std::ofstream;
|
||||||
|
|
||||||
|
using Managers::CommitManager;
|
||||||
|
using Models::API;
|
||||||
|
using Models::Token;
|
||||||
|
|
||||||
|
namespace Syncers
|
||||||
|
{
|
||||||
|
|
||||||
|
RetrieveRecords::RetrieveRecords() { }
|
||||||
|
RetrieveRecords::RetrieveRecords(API api, Token token)
|
||||||
|
: token(token), api(api) { }
|
||||||
|
|
||||||
|
void RetrieveRecords::retrieve(CommitManager::RetrieveTypes type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case CommitManager::RetrieveTypes::songs:
|
||||||
|
fetchSongs();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void RetrieveRecords::fetchSongs()
|
||||||
|
{
|
||||||
|
cout<<"fetching songs"<<endl;
|
||||||
|
auto url = api.url + "api/" + api.version + "/" + "song";
|
||||||
|
cout<<url<<endl;
|
||||||
|
|
||||||
|
auto auth = token.tokenType;
|
||||||
|
auth.append(" " + token.accessToken);
|
||||||
|
auto r = cpr::Get(cpr::Url{url},
|
||||||
|
cpr::Header{{"authorization", auth},
|
||||||
|
});
|
||||||
|
|
||||||
|
ofstream writeData{};
|
||||||
|
writeData.open("songs.json");
|
||||||
|
writeData<<r.text;
|
||||||
|
writeData.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user