Fixed issue where if / was not provided in the host value then it would not send the request. Fixed issue where song records are formatted correctly
This commit is contained in:
@@ -109,7 +109,7 @@ namespace Managers
|
||||
if (flag.size() > 3 || isNumber(flag))
|
||||
{
|
||||
flg.value = flag;
|
||||
cout<<"flag value "<<flg.value<<endl;
|
||||
//cout<<"flag value "<<flg.value<<endl;
|
||||
flags.push_back(flg);
|
||||
flg = Flags{};
|
||||
continue;
|
||||
@@ -121,7 +121,7 @@ namespace Managers
|
||||
return !val.compare(flag);
|
||||
}))
|
||||
{
|
||||
cout<<"flag "<<flag<<endl;
|
||||
//cout<<"flag "<<flag<<endl;
|
||||
flg.flag = flag;
|
||||
}
|
||||
else
|
||||
@@ -140,7 +140,7 @@ namespace Managers
|
||||
for (auto i = 2; true; ++i)
|
||||
{
|
||||
string val{*(params + i)};
|
||||
cout<<"Parsed flag "<<val<<endl;
|
||||
//cout<<"Parsed flag "<<val<<endl;
|
||||
parsed.push_back(val);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,6 @@ namespace Managers
|
||||
|
||||
usrObj["username"] = user.username;
|
||||
usrObj["password"] = user.password;
|
||||
cout<<user.username<<" "<<user.password<<endl;
|
||||
|
||||
cout<<"Sending request for token"<<endl;
|
||||
auto url = api.url + api.endpoint;
|
||||
@@ -49,12 +48,11 @@ namespace Managers
|
||||
cpr::Body{usrObj.dump()},
|
||||
cpr::Header{{"Content-Type", "application/json"}});
|
||||
|
||||
cout<<r.text<<endl;
|
||||
json res = json::parse(r.text);
|
||||
token.accessToken = res["token"];
|
||||
token.tokenType = res["token_type"];
|
||||
|
||||
//cout<<"status code "<<r.status_code<<endl;
|
||||
cout<<"status code "<<r.status_code<<endl;
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
@@ -31,23 +31,17 @@ namespace Parsers
|
||||
auto flags = icaAct.flags;
|
||||
cout<<"Parsing api"<<endl;
|
||||
|
||||
//for (auto flag : flags)
|
||||
for (auto i =0; i < flags.size(); ++i)
|
||||
{
|
||||
auto arg = flags[i].flag;
|
||||
auto value = flags[i].value;
|
||||
|
||||
if (arg.compare("-h") == 0)
|
||||
|
||||
{
|
||||
api.url = value;
|
||||
}
|
||||
if (value.compare("-h") == 0)
|
||||
{
|
||||
api.url = flags[i + 1].value;
|
||||
api.url = (value[value.size()-1 == '/']) ? value : value + "/";
|
||||
break;
|
||||
}
|
||||
|
||||
cout<<"url is "<<api.url<<endl;
|
||||
}
|
||||
|
||||
// TODO: For now I will hard code
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <fstream>
|
||||
|
||||
#include <cpr/cpr.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
@@ -35,7 +36,6 @@ namespace Syncers
|
||||
{
|
||||
cout<<"fetching songs"<<endl;
|
||||
auto url = api.url + "api/" + api.version + "/" + "song";
|
||||
cout<<url<<endl;
|
||||
|
||||
auto auth = token.tokenType;
|
||||
auth.append(" " + token.accessToken);
|
||||
@@ -43,9 +43,11 @@ namespace Syncers
|
||||
cpr::Header{{"authorization", auth},
|
||||
});
|
||||
|
||||
auto songData = nlohmann::json::parse(r.text);
|
||||
|
||||
ofstream writeData{};
|
||||
writeData.open("songs.json");
|
||||
writeData<<r.text;
|
||||
writeData<<songData.dump(4);
|
||||
writeData.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user