Merge lp:~diegosarmentero/pay-ui/code-improves into lp:pay-ui

Proposed by Diego Sarmentero
Status: Merged
Approved by: Diego Sarmentero
Approved revision: 10
Merged at revision: 10
Proposed branch: lp:~diegosarmentero/pay-ui/code-improves
Merge into: lp:pay-ui
Diff against target: 273 lines (+42/-47)
6 files modified
backend/modules/payui/network.cpp (+16/-20)
backend/modules/payui/network.h (+6/-4)
backend/modules/payui/purchase.cpp (+12/-15)
backend/tests/test_network.cpp (+5/-5)
manifest.json (+2/-2)
payui.json (+1/-1)
To merge this branch: bzr merge lp:~diegosarmentero/pay-ui/code-improves
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alejandro J. Cura (community) Approve
Review via email: mp+227088@code.launchpad.net

Commit message

- Some code improves
- Update security and framework on manifest

To post a comment you must log in.
Revision history for this message
Alejandro J. Cura (alecu) wrote :

Looks good.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'backend/modules/payui/network.cpp'
2--- backend/modules/payui/network.cpp 2014-07-02 14:51:06 +0000
3+++ backend/modules/payui/network.cpp 2014-07-16 18:53:33 +0000
4@@ -34,7 +34,6 @@
5 #define PAY_BASE_URL "https://sc.ubuntu.com/api/2.0/click/"
6 #define ACCOUNT_CREDS_URL "https://login.ubuntu.com/api/v2/tokens/oauth"
7 #define ADD_PAYMENT_URL "https://sc.ubuntu.com/api/2.0/click/paymentmethods/add/"
8-//<matiasb> gatox: this is the url, in staging: https://sc.staging.ubuntu.com/click/payment-method/add/
9
10 #define PREFERED_PAYMENT_TYPE "0"
11 #define PAYMENT_TYPES "1"
12@@ -50,23 +49,19 @@
13 Network::Network(QObject *parent) :
14 QObject(parent),
15 m_nam(this),
16- m_service(this),
17- m_selectedPaymentId(""),
18- m_selectedBackendId(""),
19- m_selectedAppId(""),
20- m_selectedItemId("")
21+ m_service(this)
22 {
23- QObject::connect(&m_nam, SIGNAL(finished(QNetworkReply*)),
24+ connect(&m_nam, SIGNAL(finished(QNetworkReply*)),
25 this, SLOT(onReply(QNetworkReply*)));
26 // SSO SERVICE
27- QObject::connect(&m_service, &CredentialsService::credentialsFound,
28+ connect(&m_service, &CredentialsService::credentialsFound,
29 this, &Network::handleCredentialsFound);
30- QObject::connect(&m_service, &CredentialsService::credentialsNotFound,
31+ connect(&m_service, &CredentialsService::credentialsNotFound,
32 this, &Network::credentialsNotFound);
33- QObject::connect(&m_service, &CredentialsService::credentialsFound,
34+ connect(&m_service, &CredentialsService::credentialsFound,
35 this, &Network::credentialsFound);
36
37- QObject::connect(this, &Network::credentialsUpdated,
38+ connect(this, &Network::credentialsUpdated,
39 this, &Network::purchaseProcess);
40 }
41
42@@ -80,7 +75,7 @@
43 m_service.setCredentials(token);
44 }
45
46-void Network::updateCredentials(QString& email, QString& password)
47+void Network::updateCredentials(const QString& email, const QString& password)
48 {
49 qDebug() << "Updating Credentials";
50 QNetworkRequest request;
51@@ -132,14 +127,12 @@
52 qDebug() << "Reply state:" << PAYMENT_TYPES;
53 QVariantList listPays;
54 QJsonArray array = document.array();
55- int i;
56- for (i = 0; i < array.size(); i++) {
57+ for (int i = 0; i < array.size(); i++) {
58 QJsonObject object = array.at(i).toObject();
59 QString description = object.value("description").toString();
60 QString backend = object.value("id").toString();
61 QJsonArray choices = object.value("choices").toArray();
62- int j;
63- for (j = 0; j < choices.size(); j++) {
64+ for (int j = 0; j < choices.size(); j++) {
65 QJsonObject choice = choices.at(i).toObject();
66 QString name = choice.value("description").toString();
67 QString paymentId = choice.value("id").toString();
68@@ -202,7 +195,7 @@
69 reply->deleteLater();
70 }
71
72-void Network::getPaymentTypes()
73+void Network::requestPaymentTypes()
74 {
75 QNetworkRequest request;
76 request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
77@@ -216,7 +209,8 @@
78 m_nam.get(request);
79 }
80
81-void Network::buyItemWithPreferredPaymentType(QString email, QString password, QString appid, QString itemid)
82+void Network::buyItemWithPreferredPaymentType(const QString& email, const QString& password,
83+ const QString& appid, const QString& itemid)
84 {
85 m_selectedPaymentId = m_preferred->paymentId();
86 m_selectedBackendId = m_preferred->backendId();
87@@ -225,7 +219,9 @@
88 updateCredentials(email, password);
89 }
90
91-void Network::buyItem(QString email, QString password, QString appid, QString itemid, QString paymentId, QString backendId)
92+void Network::buyItem(const QString& email, const QString& password,
93+ const QString& appid, const QString& itemid,
94+ const QString& paymentId, const QString& backendId)
95 {
96 m_selectedPaymentId = paymentId;
97 m_selectedBackendId = backendId;
98@@ -310,7 +306,7 @@
99 void Network::handleCredentialsFound(Token token)
100 {
101 m_token = token;
102- getPaymentTypes();
103+ requestPaymentTypes();
104 }
105
106 }
107
108=== modified file 'backend/modules/payui/network.h'
109--- backend/modules/payui/network.h 2014-07-02 14:51:06 +0000
110+++ backend/modules/payui/network.h 2014-07-16 18:53:33 +0000
111@@ -53,14 +53,16 @@
112 public:
113 explicit Network(QObject *parent = 0);
114
115- void getPaymentTypes();
116- void buyItem(QString email, QString password, QString appid, QString itemid, QString paymentId, QString backendId);
117- void buyItemWithPreferredPaymentType(QString email, QString password, QString appid, QString itemid);
118+ void requestPaymentTypes();
119+ void buyItem(const QString& email, const QString& password, const QString& appid,
120+ const QString& itemid, const QString& paymentId, const QString& backendId);
121+ void buyItemWithPreferredPaymentType(const QString& email, const QString& password,
122+ const QString& appid, const QString& itemid);
123 void getItemInfo(const QString &packagename);
124
125 void getCredentials();
126 void setCredentials(Token token);
127- void updateCredentials(QString& email, QString& password);
128+ void updateCredentials(const QString& email, const QString& password);
129 QString getAddPaymentUrl();
130
131 Q_SIGNALS:
132
133=== modified file 'backend/modules/payui/purchase.cpp'
134--- backend/modules/payui/purchase.cpp 2014-07-02 20:36:40 +0000
135+++ backend/modules/payui/purchase.cpp 2014-07-16 18:53:33 +0000
136@@ -10,34 +10,31 @@
137
138 Purchase::Purchase(QObject *parent) :
139 QObject(parent),
140- m_network(this),
141- m_appid(""),
142- m_itemid("")
143+ m_network(this)
144 {
145- QObject::connect(&m_network, &Network::itemDetailsObtained,
146+ connect(&m_network, &Network::itemDetailsObtained,
147 this, &Purchase::itemDetailsObtained);
148- QObject::connect(&m_network, &Network::paymentTypesObtained,
149+ connect(&m_network, &Network::paymentTypesObtained,
150 this, &Purchase::paymentTypesObtained);
151- QObject::connect(&m_network, &Network::buyItemSucceeded,
152+ connect(&m_network, &Network::buyItemSucceeded,
153 this, &Purchase::buyItemSucceeded);
154- QObject::connect(&m_network, &Network::buyItemFailed,
155+ connect(&m_network, &Network::buyItemFailed,
156 this, &Purchase::buyItemFailed);
157- QObject::connect(&m_network, &Network::buyInteractionRequired,
158+ connect(&m_network, &Network::buyInteractionRequired,
159 this, &Purchase::buyInterationRequired);
160- QObject::connect(&m_network, &Network::error,
161+ connect(&m_network, &Network::error,
162 this, &Purchase::error);
163- QObject::connect(&m_network, &Network::authenticationError,
164+ connect(&m_network, &Network::authenticationError,
165 this, &Purchase::authenticationError);
166- QObject::connect(&m_network, &Network::credentialsNotFound,
167+ connect(&m_network, &Network::credentialsNotFound,
168 this, &Purchase::credentialsNotFound);
169- QObject::connect(&m_network, &Network::credentialsFound,
170+ connect(&m_network, &Network::credentialsFound,
171 this, &Purchase::credentialsFound);
172
173 QCoreApplication* instance = QCoreApplication::instance();
174 Logger::setupLogging();
175- int i;
176 qCritical() << "Start Pay UI";
177- for (i = 0; i < instance->arguments().size(); i++) {
178+ for (int i = 0; i < instance->arguments().size(); i++) {
179 QString argument = instance->arguments().at(i);
180 if (argument.startsWith("purchase://")) {
181 QUrl data(argument);
182@@ -92,7 +89,7 @@
183
184 void Purchase::getPaymentTypes()
185 {
186- m_network.getPaymentTypes();
187+ m_network.requestPaymentTypes();
188 }
189
190 void Purchase::buyItemWithPreferredPayment(QString email, QString password)
191
192=== modified file 'backend/tests/test_network.cpp'
193--- backend/tests/test_network.cpp 2014-07-02 20:48:48 +0000
194+++ backend/tests/test_network.cpp 2014-07-16 18:53:33 +0000
195@@ -94,7 +94,7 @@
196 {
197 setenv("PAY_BASE_URL", "http://localhost:8000/", 1);
198 QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList)));
199- network.getPaymentTypes();
200+ network.requestPaymentTypes();
201 QTRY_COMPARE(spy.count(), 1);
202 QList<QVariant> arguments = spy.takeFirst();
203 QVERIFY(arguments.at(0).toList().count() == 3);
204@@ -104,7 +104,7 @@
205 {
206 setenv("PAY_BASE_URL", "http://localhost:8000/fail/", 1);
207 QSignalSpy spy(&network, SIGNAL(error(QString)));
208- network.getPaymentTypes();
209+ network.requestPaymentTypes();
210 QTRY_COMPARE(spy.count(), 1);
211 QList<QVariant> arguments = spy.takeFirst();
212 QVERIFY(arguments.at(0).toString() == "404");
213@@ -144,7 +144,7 @@
214 setenv("PAY_BASE_URL", "http://localhost:8000/", 1);
215 setenv("ACCOUNT_CREDS_URL", "http://localhost:8000/creds/", 1);
216 QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList)));
217- network.getPaymentTypes();
218+ network.requestPaymentTypes();
219 QTRY_COMPARE(spy.count(), 1);
220 QSignalSpy spy2(&network, SIGNAL(buyItemSucceeded()));
221 network.buyItemWithPreferredPaymentType("email", "password", "appid", "itemid");
222@@ -156,7 +156,7 @@
223 setenv("PAY_BASE_URL", "http://localhost:8000/", 1);
224 setenv("ACCOUNT_CREDS_URL", "http://localhost:8000/creds/", 1);
225 QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList)));
226- network.getPaymentTypes();
227+ network.requestPaymentTypes();
228 QTRY_COMPARE(spy.count(), 1);
229 setenv("PAY_BASE_URL", "http://localhost:8000/fail/", 1);
230 QSignalSpy spy2(&network, SIGNAL(buyItemFailed()));
231@@ -169,7 +169,7 @@
232 setenv("PAY_BASE_URL", "http://localhost:8000/", 1);
233 setenv("ACCOUNT_CREDS_URL", "http://localhost:8000/creds/", 1);
234 QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList)));
235- network.getPaymentTypes();
236+ network.requestPaymentTypes();
237 QTRY_COMPARE(spy.count(), 1);
238 setenv("PAY_BASE_URL", "http://localhost:8000/interaction/", 1);
239 QSignalSpy spy2(&network, SIGNAL(buyInteractionRequired(QString)));
240
241=== modified file 'manifest.json'
242--- manifest.json 2014-07-15 18:50:54 +0000
243+++ manifest.json 2014-07-16 18:53:33 +0000
244@@ -1,7 +1,7 @@
245 {
246 "name": "com.canonical.payui",
247 "description": "UI for Pay Service",
248- "framework": "ubuntu-sdk-14.04-qml-dev2",
249+ "framework": "ubuntu-sdk-14.10-qml-dev2",
250 "architecture": "armhf",
251 "title": "PayUI",
252 "hooks": {
253@@ -10,6 +10,6 @@
254 "desktop": "payui.desktop"
255 }
256 },
257- "version": "0.2.9",
258+ "version": "0.3",
259 "maintainer": "Sarmentero Diego <diego.sarmentero@canonical.com>"
260 }
261\ No newline at end of file
262
263=== modified file 'payui.json'
264--- payui.json 2014-06-23 18:20:45 +0000
265+++ payui.json 2014-07-16 18:53:33 +0000
266@@ -1,5 +1,5 @@
267 {
268 "policy_groups": [],
269- "policy_version": 1.1,
270+ "policy_version": 1.2,
271 "template": "unconfined"
272 }
273\ No newline at end of file

Subscribers

People subscribed via source and target branches

to all changes: