Merge lp:~dobey/unity-scope-click/fix-fallback into lp:unity-scope-click/devel

Proposed by dobey
Status: Merged
Approved by: Paweł Stołowski
Approved revision: 271
Merged at revision: 271
Proposed branch: lp:~dobey/unity-scope-click/fix-fallback
Merge into: lp:unity-scope-click/devel
Diff against target: 83 lines (+19/-6)
3 files modified
scope/click/package.cpp (+4/-1)
scope/click/package.h (+3/-1)
scope/tests/fake_json.h (+12/-4)
To merge this branch: bzr merge lp:~dobey/unity-scope-click/fix-fallback
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Paweł Stołowski (community) Approve
Review via email: mp+220813@code.launchpad.net

Commit message

Use the "self" sub-object for getting the resoruce url under hal+json.
Handle falling back to plain resource_url for when parsing plain json.

Description of the change

The parsing code for hal+json is currently using {"_links": {"href": "https://..."}} to get the URL, but the structure is actually {"_links": {"self": {"href": "https://..."}}} when getting hal+json from the server.
Also, we were not falling back to using "resource_url" from the plain json, and so were getting failures with the new scopes-api as we were getting an empty url for the package. We need to handle this fallback correctly here, to get a valid URL.

To post a comment you must log in.
Revision history for this message
Paweł Stołowski (stolowski) wrote :

Ah, my bad :/. Looks fine, thanks.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'scope/click/package.cpp'
2--- scope/click/package.cpp 2014-05-16 17:53:39 +0000
3+++ scope/click/package.cpp 2014-05-23 14:24:18 +0000
4@@ -73,7 +73,10 @@
5 p.title = item[Package::JsonKeys::title].asString();
6 p.price = item[Package::JsonKeys::price].asDouble();
7 p.icon_url = item[Package::JsonKeys::icon_url].asString();
8- p.url = item[Package::JsonKeys::links][Package::JsonKeys::resource_url].asString();
9+ p.url = item[Package::JsonKeys::links][Package::JsonKeys::self][Package::JsonKeys::href].asString();
10+ if (p.url.empty()) {
11+ p.url = item[Package::JsonKeys::resource_url].asString();
12+ }
13 return p;
14 }
15
16
17=== modified file 'scope/click/package.h'
18--- scope/click/package.h 2014-05-16 17:53:39 +0000
19+++ scope/click/package.h 2014-05-23 14:24:18 +0000
20@@ -48,12 +48,14 @@
21
22 constexpr static const char* embedded {"_embedded"};
23 constexpr static const char* links{"_links"};
24+ constexpr static const char* self{"self"};
25+ constexpr static const char* href{"href"};
26 constexpr static const char* ci_package {"clickindex:package"};
27 constexpr static const char* name{"name"};
28 constexpr static const char* title{"title"};
29 constexpr static const char* price{"price"};
30 constexpr static const char* icon_url{"icon_url"};
31- constexpr static const char* resource_url{"href"};
32+ constexpr static const char* resource_url{"resource_url"};
33 };
34
35 Package() = default;
36
37=== modified file 'scope/tests/fake_json.h'
38--- scope/tests/fake_json.h 2014-05-14 18:34:20 +0000
39+++ scope/tests/fake_json.h 2014-05-23 14:24:18 +0000
40@@ -64,7 +64,9 @@
41 "price": 1.99,
42 "icon_url": "http://software-center.ubuntu.com/site_media/appmedia/2012/09/SPAZ.png",
43 "_links": {
44- "href": "http://search.apps.ubuntu.com/api/v1/package/org.example.awesomelauncher"
45+ "self": {
46+ "href": "http://search.apps.ubuntu.com/api/v1/package/org.example.awesomelauncher"
47+ }
48 }
49 }
50 ]
51@@ -82,7 +84,9 @@
52 "price": 1.99,
53 "icon_url": "http://software-center.ubuntu.com/site_media/appmedia/2012/09/SPAZ.png",
54 "_links": {
55- "href": "http://search.apps.ubuntu.com/api/v1/package/org.example.awesomelauncher"
56+ "self": {
57+ "href": "http://search.apps.ubuntu.com/api/v1/package/org.example.awesomelauncher"
58+ }
59 }
60 },
61 {
62@@ -92,7 +96,9 @@
63 "price": 0.0,
64 "icon_url": "http://assets.ubuntu.com/sites/ubuntu/504/u/img/ubuntu/features/icon-find-more-apps-64x64.png",
65 "_links": {
66- "href": "http://search.apps.ubuntu.com/api/v1/package/org.example.fantasticapp"
67+ "self": {
68+ "href": "http://search.apps.ubuntu.com/api/v1/package/org.example.fantasticapp"
69+ }
70 }
71 },
72 {
73@@ -102,7 +108,9 @@
74 "price": 1.99,
75 "icon_url": "http://assets.ubuntu.com/sites/ubuntu/504/u/img/ubuntu/features/icon-photos-and-videos-64x64.png",
76 "_links": {
77- "href": "http://search.apps.ubuntu.com/api/v1/package/org.example.awesomewidget"
78+ "self": {
79+ "href": "http://search.apps.ubuntu.com/api/v1/package/org.example.awesomewidget"
80+ }
81 }
82 }
83 ]

Subscribers

People subscribed via source and target branches

to all changes: