summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleix Pol <[email protected]>2016-10-21 09:18:49 +0200
committerAleix Pol <[email protected]>2016-10-21 09:18:49 +0200
commit80d410ee6fe6693eb1ae566fa0782acb4dcce6c8 (patch)
tree3272c1846d7541f969c36d7097aad8390539de40
parent2ed91525fc5740cf0a96ccfe8a591ffb44fc951c (diff)
Implement some of /v2/changes API
-rw-r--r--libdiscover/backends/SnapBackend/libsnapclient/SnapSocket.cpp15
-rw-r--r--libdiscover/backends/SnapBackend/libsnapclient/SnapSocket.h8
2 files changed, 16 insertions, 7 deletions
diff --git a/libdiscover/backends/SnapBackend/libsnapclient/SnapSocket.cpp b/libdiscover/backends/SnapBackend/libsnapclient/SnapSocket.cpp
index 40b6838..d6f0d03 100644
--- a/libdiscover/backends/SnapBackend/libsnapclient/SnapSocket.cpp
+++ b/libdiscover/backends/SnapBackend/libsnapclient/SnapSocket.cpp
@@ -34,7 +34,7 @@ public:
, m_socket(new QLocalSocket(this))
{
connect(m_socket, &QLocalSocket::connected, this, [this, request](){
- // qDebug() << "connected";
+// qDebug() << "connected" << request;
m_socket->write(request);
});
connect(m_socket, &QLocalSocket::disconnected, this, [](){ qDebug() << "disconnected :("; });
@@ -66,14 +66,15 @@ public:
snapAction.setArguments({ { QStringLiteral("request"), request } });
Q_ASSERT(snapAction.isValid());
m_reply = snapAction.execute();
-// m_reply->start();
+ m_reply->start();
connect(m_reply, &KAuth::ExecuteJob::finished, this, &AuthSnapJob::authJobFinished);
}
bool exec() override
{
- m_reply->exec();
+ Q_UNIMPLEMENTED();
+// m_reply->exec();
return isSuccessful();
}
@@ -170,6 +171,12 @@ SnapJob* SnapSocket::findByName(const QString& name)
return new LocalSnapJob(createRequest("GET", "/v2/find", {{ QStringLiteral("name"), name }}), this);
}
+SnapJob * SnapSocket::changes(const QString& id)
+{
+ Q_ASSERT(!id.isEmpty());
+ return new LocalSnapJob(createRequest("GET", "/v2/changes/"+id.toUtf8()), this);
+}
+
SnapJob * SnapSocket::snapAction(const QString& name, SnapSocket::SnapAction action, const QString& channel)
{
QString actionStr;
@@ -218,7 +225,7 @@ void SnapJob::processReply(QIODevice* device)
{
{
const QByteArray line = device->readLine().trimmed();
- if (!line.endsWith("OK"))
+ if (!line.endsWith("OK") && !line.endsWith("Accepted"))
qWarning() << "error" << line;
}
diff --git a/libdiscover/backends/SnapBackend/libsnapclient/SnapSocket.h b/libdiscover/backends/SnapBackend/libsnapclient/SnapSocket.h
index 820f5d0..1eda15e 100644
--- a/libdiscover/backends/SnapBackend/libsnapclient/SnapSocket.h
+++ b/libdiscover/backends/SnapBackend/libsnapclient/SnapSocket.h
@@ -36,7 +36,8 @@ public:
int statusCode() const { return m_data.value(QLatin1String("status-code")).toInt(); }
QString status() const { return m_data.value(QLatin1String("status")).toString(); }
QString type() const { return m_data.value(QLatin1String("type")).toString(); }
- bool isSuccessful() const { return statusCode()==200; }
+ bool isSuccessful() const { return statusCode()>=200 && statusCode()<300; }
+ QJsonObject data() const { return m_data; }
virtual bool exec() = 0;
@@ -88,11 +89,12 @@ public:
/**
* POST /v2/snaps/@p name
* stable is the default channel
- *
- *
*/
SnapJob* snapAction(const QString &name, SnapAction action, const QString &channel = {});
+ /// GET /v2/changes/@p id
+ SnapJob* changes(const QString &id);
+
Q_SIGNALS:
void loginChanged(bool isLoggedIn);