service.cpp 961 Bytes
Newer Older
1
#include "service.h"
camilo higuita's avatar
camilo higuita committed
2
#include "downloader.h"
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

Service::Service(QObject *parent) : QObject(parent)
{

}

void Service::set(const PULPO::REQUEST &request)
{
    this->request = request;
}

void Service::parse(const QByteArray &array)
{
    switch(this->request.ontology)
    {
    case PULPO::ONTOLOGY::ALBUM:
        this->parseAlbum(array);
        break;
    case PULPO::ONTOLOGY::ARTIST:
        this->parseArtist(array);
        break;
    case PULPO::ONTOLOGY::TRACK:
        this->parseTrack(array);
        break;
    }
}

void Service::retrieve(const QString &url, const QMap<QString, QString> &headers)
{
    if(!url.isEmpty())
    {
        auto downloader = new FMH::Downloader;
35
        connect(downloader, &FMH::Downloader::dataReady, [&, _downloader = std::move(downloader)](QByteArray array)
36 37
        {
            emit this->arrayReady(array);
38
            _downloader->deleteLater();
39 40 41 42
        });
        downloader->getArray(url, headers);
    }
}