lastfm: rework service architecture a bit and implement getting full artist info

This commit is contained in:
Andrzej Rybczak
2013-07-10 17:20:09 +02:00
parent 0092dfe044
commit 1710f892c5
8 changed files with 188 additions and 299 deletions

View File

@@ -30,42 +30,51 @@
#include "scrollpad.h"
struct LastfmService
namespace LastFm {
struct Service
{
typedef std::map<std::string, std::string> Args;
typedef std::map<std::string, std::string> Arguments;
typedef std::pair<bool, std::string> Result;
virtual const char *name() = 0;
virtual Result fetch(Args &args);
Service(Arguments args) : m_arguments(args) { }
virtual bool checkArgs(const Args &args) = 0;
virtual void colorizeOutput(NC::Scrollpad &w) = 0;
virtual const char *name() = 0;
virtual Result fetch();
virtual void beautifyOutput(NC::Scrollpad &w) = 0;
protected:
virtual bool argumentsOk() = 0;
virtual bool actionFailed(const std::string &data);
virtual bool parse(std::string &data) = 0;
virtual void postProcess(std::string &data);
virtual Result processData(const std::string &data) = 0;
virtual const char *methodName() = 0;
static const char *baseURL;
static const char *msgParseFailed;
Arguments m_arguments;
};
struct ArtistInfo : public LastfmService
struct ArtistInfo : public Service
{
ArtistInfo(std::string artist, std::string lang)
: Service({{"artist", artist}, {"lang", lang}}) { }
virtual const char *name() { return "Artist info"; }
virtual bool checkArgs(const Args &args);
virtual void colorizeOutput(NC::Scrollpad &w);
virtual void beautifyOutput(NC::Scrollpad &w);
bool operator==(const ArtistInfo &ai) const { return m_arguments == ai.m_arguments; }
protected:
virtual bool parse(std::string &data);
virtual bool argumentsOk();
virtual Result processData(const std::string &data);
virtual const char *methodName() { return "artist.getinfo"; }
};
}
#endif // HAVE_CURL_CURL_H
#endif // NCMPCPP_LASTFM_SERVICE_H