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

Handles requests for YouTube resources. More...

Inheritance diagram for QYouTube::ResourcesRequest:
QYouTube::Request

Public Slots

void list (const QString &resourcePath, const QStringList &part, const QVariantMap &filters=QVariantMap(), const QVariantMap &params=QVariantMap())
 Requests a list of YouTube resources from resourcePath.
void insert (const QVariantMap &resource, const QString &resourcePath, const QStringList &part, const QVariantMap &params=QVariantMap())
 Inserts a new YouTube resource.
void update (const QString &resourcePath, const QVariantMap &resource, const QStringList &part)
 Updates the YouTube resource at resourcePath.
void del (const QString &id, const QString &resourcePath)
 Deletes the YouTube resource at resourcePath.
- Public Slots inherited from QYouTube::Request
void cancel ()
 Cancels the current HTTP request.

Additional Inherited Members

- Public Types inherited from QYouTube::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 QYouTube::Request
void apiKeyChanged ()
 Emitted when the apiKey changes.
void clientIdChanged ()
 Emitted when the clientId changes.
void clientSecretChanged ()
 Emitted when the clientSecret changes.
void accessTokenChanged (const QString &token)
 Emitted when the accessToken changes.
void refreshTokenChanged (const QString &token)
 Emitted when the refreshToken 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 QYouTube::Request
void setNetworkAccessManager (QNetworkAccessManager *manager)
 Sets the QNetworkAccessManager instance to be used when making requests to the YouTube API.
- Protected Slots inherited from QYouTube::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 QYouTube::Request
QString apiKey
 The api key used when making requests to the YouTube Data API.
QString clientId
 The client id used when making requests to the YouTube Data API.
QString clientSecret
 The api key used when making requests to the YouTube Data API.
QString accessToken
 The access token used when making requests to the YouTube Data API.
QString refreshToken
 The refresh token used when making requests to the YouTube Data API.
QUrl url
 The url used when making requests to the YouTube Data API.
QVariantMap headers
 The headers used when making requests to the YouTube Data API.
QVariant data
 The data used when making HTTP PUT/POST requests to the YouTube 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 YouTube resources.

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

Example usage:

C++

using namespace QYouTube;
...
ResourcesRequest request;
request.get("/video/VIDEO_ID");
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 QYouTube 1.0
ResourcesRequest {
id: request
onFinished: {
if (status == ResourcesRequest.Ready) {
for (var k in result) {
console.log(att + " = " + result[k]);
}
}
else {
console.log(errorString);
}
}
Component.onCompleted: get("/video/VIDEO_ID")
}

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

Member Function Documentation

void QYouTube::ResourcesRequest::del ( const QString &  id,
const QString &  resourcePath 
)
slot

Deletes the YouTube resource at resourcePath.

For example, to remove a video from the authenticated user's favourites:

ResourcesRequest request;
request.del(FAVOURITE_PLAYLIST_ITEM_ID, "/playlistItems");
void QYouTube::ResourcesRequest::insert ( const QVariantMap &  resource,
const QString &  resourcePath,
const QStringList &  part,
const QVariantMap &  params = QVariantMap() 
)
slot

Inserts a new YouTube resource.

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

ResourcesRequest request;
QVariantMap playlist;
QVariantMap snippet;
QVariantMap status;
snippet["title"] = "My playlist";
snippet["description"] = "Playlist inserted using QYouTube";
status["privacyStatus"] = "public";
playlist["snippet"] = snippet;
playlist["status"] = status;
request.insert(playlist, "/playlists", QStringList() << "snippet" << "status");
void QYouTube::ResourcesRequest::list ( const QString &  resourcePath,
const QStringList &  part,
const QVariantMap &  filters = QVariantMap(),
const QVariantMap &  params = QVariantMap() 
)
slot

Requests a list of YouTube resources from resourcePath.

For example, to search videos:

ResourcesRequest request;
QVariantMap params;
params["maxResults"] = 10;
params["order"] = "date";
params["q"] = "Qt";
params["type"] = "video";
request.list("/videos", QStringList() << "snippet", QVariantMap(), params);
void QYouTube::ResourcesRequest::update ( const QString &  resourcePath,
const QVariantMap &  resource,
const QStringList &  part 
)
slot

Updates the YouTube resource at resourcePath.

For example, to update an existing playlist on behalf of the authenticated user:

ResourcesRequest request;
QVariantMap playlist;
QVariantMap snippet;
snippet["name"] = "My new playlist name";
snippet["description"] = "My new playlist description";
playlist["snippet"] = snippet;
playlist["id"] = PLAYLIST_ID;
request.update("/playlists", playlist, QStringList() << "snippet");