libcuteradio
A Qt/C++ library and QML module to access the cuteRadio Data API.
 All Classes Functions Enumerations Properties Groups Pages
Public Slots | List of all members
CuteRadio::ResourcesRequest Class Reference

Handles requests for cuteRadio resources. More...

Inheritance diagram for CuteRadio::ResourcesRequest:
CuteRadio::Request

Public Slots

void get (const QString &resourcePath, const QVariantMap &filters=QVariantMap())
 Requests cuteRadio resource(s) from resourcePath.
void insert (const QVariantMap &resource, const QString &resourcePath)
 Inserts a new cuteRadio resource.
void update (const QString &resourcePath, const QVariantMap &resource)
 Updates the cuteRadio resource at resourcePath.
void del (const QString &resourcePath)
 Deletes the cuteRadio resource at resourcePath.
- Public Slots inherited from CuteRadio::Request
void cancel ()
 Cancels the current HTTP request.

Additional Inherited Members

- Public Types inherited from CuteRadio::Request
enum  Operation
 The operation type of the last HTTP request. More...
enum  Status
 The status of the last HTTP request. More...
enum  Error
 The error resulting from the last HTTP request. More...
- Signals inherited from CuteRadio::Request
void accessTokenChanged ()
 Emitted when the accessToken changes.
void urlChanged ()
 Emitted when the url changes.
void dataChanged ()
 Emitted when the data changes.
void headersChanged ()
 Emitted when the headers change.
void operationChanged ()
 Emitted when the operation changes.
void statusChanged (Status s)
 Emitted when the status changes.
void finished ()
 Emitted when the request is completed.
- Public Member Functions inherited from CuteRadio::Request
void setNetworkAccessManager (QNetworkAccessManager *manager)
 Sets the QNetworkAccessManager instance to be used when making requests to the cuteRadio API.
- Protected Slots inherited from CuteRadio::Request
void head (bool authRequired=true)
 Performs a HTTP HEAD request.
void get (bool authRequired=true)
 Performs a HTTP GET request.
void post (bool authRequired=true)
 Performs a HTTP POST request.
void put (bool authRequired=true)
 Performs a HTTP PUT request.
void deleteResource (bool authRequired=true)
 Performs a HTTP DELETE request.
- Properties inherited from CuteRadio::Request
QString accessToken
 The access token used when making requests to the cuteRadio Data API.
QUrl url
 The url used when making requests to the cuteRadio Data API.
QVariantMap headers
 The headers used when making requests to the cuteRadio Data API.
QVariant data
 The data used when making HTTP PUT/POST requests to the cuteRadio Data API.
Operation operation
 The last HTTP operation type.
Status status
 The status of the last request.
QVariant result
 The result of the last HTTP request.
Error error
 The error resulting from the last HTTP request.
QString errorString
 A description of the error resulting from the last HTTP request.

Detailed Description

Handles requests for cuteRadio resources.

The ResourcesRequest class is used for making requests to the cuteRadio Data API that concern cuteRadio resources.

Example usage:

C++

using namespace CuteRadio;
...
ResourcesRequest request;
request.get("/stations");
connect(&request, SIGNAL(finished()), this, SLOT(onRequestFinished()));
...
void MyClass::onRequestFinished() {
if (request.status() == ResourcesRequest::Ready) {
QMapIterator<QString, QVariant> iterator(request.result().toMap());
while (iterator.hasNext()) {
iterator.next();
qDebug() << iterator.key() << "=" << iterator.value();
}
}
else {
qDebug() << request.errorString();
}
}

QML

import QtQuick 1.0
import CuteRadio 1.0
ResourcesRequest {
id: request
onFinished: {
if (status == ResourcesRequest.Ready) {
for (var att in result) {
console.log(att + " = " + result[att]);
}
}
else {
console.log(errorString);
}
}
Component.onCompleted: get("/stations")
}

For more details about cuteRadio resources, see the cuteRadio reference documentation here.

Member Function Documentation

void CuteRadio::ResourcesRequest::del ( const QString &  resourcePath)
slot

Deletes the cuteRadio resource at resourcePath.

For example, to delete a favourite station on behalf of the authenticated user:

ResourcesRequest request;
request.setAccessToken(USER_ACCESS_TOKEN);
request.del("/favourites/EXISTING_STATION_ID");
void CuteRadio::ResourcesRequest::get ( const QString &  resourcePath,
const QVariantMap &  filters = QVariantMap() 
)
slot

Requests cuteRadio resource(s) from resourcePath.

For example, to search tracks:

ResourcesRequest request;
QVariantMap filters;
filters["limit"] = 10;
filters["search"] = "Radio";
request.get("/stations", filters);
void CuteRadio::ResourcesRequest::insert ( const QVariantMap &  resource,
const QString &  resourcePath 
)
slot

Inserts a new cuteRadio resource.

For example, to insert a new favourite station on behalf of the authenticated user:

ResourcesRequest request;
QVariantMap favourite;
favourite["stationId"] = 1001;
request.setAccessToken(USER_ACCESS_TOKEN);
request.insert(favourite, "/favourites");
void CuteRadio::ResourcesRequest::update ( const QString &  resourcePath,
const QVariantMap &  resource 
)
slot

Updates the cuteRadio resource at resourcePath.

For example, to update an existing station owned by the authenticated user:

ResourcesRequest request;
QVariantMap station;
station["title"] = "New station title";
station["description"] = "New station description";
request.setAccessToken(USER_ACCESS_TOKEN);
request.update("/stations/EXISTING_STATION_ID", station);