Merge lp:~ahayzen/ubuntu-weather-app/fix-1505848-add-owm-key into lp:ubuntu-weather-app

Proposed by Andrew Hayzen
Status: Merged
Approved by: Victor Thompson
Approved revision: 141
Merged at revision: 136
Proposed branch: lp:~ahayzen/ubuntu-weather-app/fix-1505848-add-owm-key
Merge into: lp:ubuntu-weather-app
Diff against target: 159 lines (+33/-10)
6 files modified
app/data/WeatherApi.js (+24/-4)
app/data/keys.js (+1/-0)
app/ubuntu-weather-app.qml (+4/-3)
app/ui/settings/DataProviderPage.qml (+2/-2)
debian/changelog (+1/-0)
po/com.ubuntu.weather.pot (+1/-1)
To merge this branch: bzr merge lp:~ahayzen/ubuntu-weather-app/fix-1505848-add-owm-key
Reviewer Review Type Date Requested Status
Victor Thompson Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+274423@code.launchpad.net

Commit message

* Add support for OWM API keys

Description of the change

* Add support for OWM API keys

Not sure what we should do with the settings page when you have no keys at all (note we currently hide TWC), and not sure what should happen when you load the app with no keys.

To post a comment you must log in.
138. By Andrew Hayzen

* Link to /appid page instead of /faq in code commentary

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Victor Thompson (vthompson) wrote :

Let's please update the key.js file to be called keys.js. Also, let's import that as "Keys".

review: Needs Fixing
139. By Andrew Hayzen

* Rename key to keys

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
140. By Andrew Hayzen

* Trim the OWM API key out of the log files

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
141. By Andrew Hayzen

* Update to include TWC trimming as well as OWM

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Victor Thompson (vthompson) wrote :

lgtm! Thanks for the quick fix!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/data/WeatherApi.js'
2--- app/data/WeatherApi.js 2015-08-22 23:17:02 +0000
3+++ app/data/WeatherApi.js 2015-10-14 23:53:33 +0000
4@@ -99,6 +99,21 @@
5 return str.join("&");
6 }
7
8+
9+// Remove anything including and after APPID in the given term
10+function trimAPIKey(data) {
11+ var owm = data.indexOf("&APPID=");
12+ var twc = data.indexOf("&key=");
13+
14+ if (owm > -1) {
15+ data = data.substr(0, owm);
16+ } else if (twc > -1) {
17+ data = data.substr(0, twc);
18+ }
19+
20+ return data;
21+}
22+
23 var GeoipApi = (function() {
24 var _baseUrl = "http://geoip.ubuntu.com/lookup";
25 return {
26@@ -333,6 +348,10 @@
27 urls.daily = _baseUrl+"forecast/daily?cnt=10&units="+params.units+latLongParams+"&lang="+Qt.locale().name.split("_")[0];
28 urls.forecast = _baseUrl+"forecast?units="+params.units+latLongParams+"&lang="+Qt.locale().name.split("_")[0];
29 }
30+ urls.current += "&APPID="+params.owm_api_key;
31+ urls.daily += "&APPID="+params.owm_api_key;
32+ urls.forecast += "&APPID="+params.owm_api_key;
33+
34 return urls;
35 }
36 //
37@@ -364,7 +383,7 @@
38 onError(err);
39 }),
40 retryHandler = (function(err) {
41- console.log("retry of "+err.request.url);
42+ console.log("retry of "+trimAPIKey(err.request.url));
43 var retryFunc = handlerMap[err.request.type];
44 apiCaller(retryFunc, addDataToResponse, onErrorHandler);
45 });
46@@ -572,7 +591,7 @@
47 function _getUrl(params) {
48 var url, serviceId,
49 baseParams = {
50- key: params.api_key,
51+ key: params.twc_api_key,
52 units: (params.units === "metric") ? "m" : "e",
53 locale: Qt.locale().name,
54 hours: "48",
55@@ -630,7 +649,7 @@
56 function _sendRequest(request, onSuccess, onError) {
57 var xmlHttp = new XMLHttpRequest();
58 if (xmlHttp) {
59- console.log("Sent request URL: " + request.url);
60+ console.log("Sent request URL: " + trimAPIKey(request.url));
61 xmlHttp.open('GET', request.url, true);
62 xmlHttp.onreadystatechange = function () {
63 try {
64@@ -741,7 +760,8 @@
65 db: loc.db,
66 units: 'metric',
67 service: message.params.service,
68- api_key: message.params.api_key,
69+ twc_api_key: message.params.twc_api_key,
70+ owm_api_key: message.params.owm_api_key,
71 interval: message.params.interval
72 },
73 secsFromLastFetch = (now-loc.updated)/1000;
74
75=== renamed file 'app/data/key.js' => 'app/data/keys.js'
76--- app/data/key.js 2015-06-11 00:22:03 +0000
77+++ app/data/keys.js 2015-10-14 23:53:33 +0000
78@@ -1,1 +1,2 @@
79 var twcKey = "";
80+var owmKey = ""; // goto http://openweathermap.org/appid to get a personal API key
81
82=== modified file 'app/ubuntu-weather-app.qml'
83--- app/ubuntu-weather-app.qml 2015-09-03 22:55:17 +0000
84+++ app/ubuntu-weather-app.qml 2015-10-14 23:53:33 +0000
85@@ -22,7 +22,7 @@
86 import "components"
87 import "data" as Data
88 import "data/WeatherApi.js" as WeatherApi
89-import "data/key.js" as Key
90+import "data/keys.js" as Keys
91 import "ui"
92
93 MainView {
94@@ -118,7 +118,8 @@
95 locations: locations,
96 force: force_refresh,
97 service: settings.service,
98- api_key: Key.twcKey,
99+ twc_api_key: Keys.twcKey,
100+ owm_api_key: Keys.owmKey,
101 interval: settings.refreshInterval
102 }
103 }, responseDataHandler)
104@@ -172,7 +173,7 @@
105 windUnits = metric ? "kph" : "mph"
106 }
107
108- if (Key.twcKey === "") { // No API key for TWC, so use OWM
109+ if (Keys.twcKey === "") { // No API key for TWC, so use OWM
110 service = "openweathermap"
111 }
112 }
113
114=== modified file 'app/ui/settings/DataProviderPage.qml'
115--- app/ui/settings/DataProviderPage.qml 2015-07-24 21:27:14 +0000
116+++ app/ui/settings/DataProviderPage.qml 2015-10-14 23:53:33 +0000
117@@ -19,7 +19,7 @@
118 import QtQuick 2.4
119 import Ubuntu.Components 1.2
120 import "../../components"
121-import "../../data/key.js" as Key
122+import "../../data/keys.js" as Keys
123
124 Page {
125 title: i18n.tr("Data Provider")
126@@ -54,7 +54,7 @@
127
128 Component.onCompleted: {
129 // If the key file for TWC is not blank, add the service to the model
130- if (Key.twcKey !== "") {
131+ if (Keys.twcKey !== "") {
132 dataProviderModel.append({ text: "The Weather Channel" })
133 }
134 }
135
136=== modified file 'debian/changelog'
137--- debian/changelog 2015-10-07 18:56:07 +0000
138+++ debian/changelog 2015-10-14 23:53:33 +0000
139@@ -49,6 +49,7 @@
140 * Various tidy ups to improve readability and code commentary of autopilot code
141 * ListItem transparent and PageWithBottomEdge colour correct so that they don't appear white on the LocationsPage
142 * When expanding day delegates ensure that extra info is visible by animating it into view (LP: #1496425)
143+ * Add support for OWM API keys (LP: #1505848)
144
145 [ Carla Sella ]
146 * Create autopilot test which shows the day delegate (LP: #1452491)
147
148=== modified file 'po/com.ubuntu.weather.pot'
149--- po/com.ubuntu.weather.pot 2015-10-07 18:56:07 +0000
150+++ po/com.ubuntu.weather.pot 2015-10-14 23:53:33 +0000
151@@ -8,7 +8,7 @@
152 msgstr ""
153 "Project-Id-Version: ubuntu-weather-app\n"
154 "Report-Msgid-Bugs-To: \n"
155-"POT-Creation-Date: 2015-10-07 19:53+0100\n"
156+"POT-Creation-Date: 2015-10-15 00:45+0100\n"
157 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
158 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
159 "Language-Team: LANGUAGE <LL@li.org>\n"

Subscribers

People subscribed via source and target branches

to all changes: