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
=== modified file 'app/data/WeatherApi.js'
--- app/data/WeatherApi.js 2015-08-22 23:17:02 +0000
+++ app/data/WeatherApi.js 2015-10-14 23:53:33 +0000
@@ -99,6 +99,21 @@
99 return str.join("&");99 return str.join("&");
100}100}
101101
102
103// Remove anything including and after APPID in the given term
104function trimAPIKey(data) {
105 var owm = data.indexOf("&APPID=");
106 var twc = data.indexOf("&key=");
107
108 if (owm > -1) {
109 data = data.substr(0, owm);
110 } else if (twc > -1) {
111 data = data.substr(0, twc);
112 }
113
114 return data;
115}
116
102var GeoipApi = (function() {117var GeoipApi = (function() {
103 var _baseUrl = "http://geoip.ubuntu.com/lookup";118 var _baseUrl = "http://geoip.ubuntu.com/lookup";
104 return {119 return {
@@ -333,6 +348,10 @@
333 urls.daily = _baseUrl+"forecast/daily?cnt=10&units="+params.units+latLongParams+"&lang="+Qt.locale().name.split("_")[0];348 urls.daily = _baseUrl+"forecast/daily?cnt=10&units="+params.units+latLongParams+"&lang="+Qt.locale().name.split("_")[0];
334 urls.forecast = _baseUrl+"forecast?units="+params.units+latLongParams+"&lang="+Qt.locale().name.split("_")[0];349 urls.forecast = _baseUrl+"forecast?units="+params.units+latLongParams+"&lang="+Qt.locale().name.split("_")[0];
335 }350 }
351 urls.current += "&APPID="+params.owm_api_key;
352 urls.daily += "&APPID="+params.owm_api_key;
353 urls.forecast += "&APPID="+params.owm_api_key;
354
336 return urls;355 return urls;
337 }356 }
338 //357 //
@@ -364,7 +383,7 @@
364 onError(err);383 onError(err);
365 }),384 }),
366 retryHandler = (function(err) {385 retryHandler = (function(err) {
367 console.log("retry of "+err.request.url);386 console.log("retry of "+trimAPIKey(err.request.url));
368 var retryFunc = handlerMap[err.request.type];387 var retryFunc = handlerMap[err.request.type];
369 apiCaller(retryFunc, addDataToResponse, onErrorHandler);388 apiCaller(retryFunc, addDataToResponse, onErrorHandler);
370 });389 });
@@ -572,7 +591,7 @@
572 function _getUrl(params) {591 function _getUrl(params) {
573 var url, serviceId,592 var url, serviceId,
574 baseParams = {593 baseParams = {
575 key: params.api_key,594 key: params.twc_api_key,
576 units: (params.units === "metric") ? "m" : "e",595 units: (params.units === "metric") ? "m" : "e",
577 locale: Qt.locale().name,596 locale: Qt.locale().name,
578 hours: "48",597 hours: "48",
@@ -630,7 +649,7 @@
630 function _sendRequest(request, onSuccess, onError) {649 function _sendRequest(request, onSuccess, onError) {
631 var xmlHttp = new XMLHttpRequest();650 var xmlHttp = new XMLHttpRequest();
632 if (xmlHttp) {651 if (xmlHttp) {
633 console.log("Sent request URL: " + request.url);652 console.log("Sent request URL: " + trimAPIKey(request.url));
634 xmlHttp.open('GET', request.url, true);653 xmlHttp.open('GET', request.url, true);
635 xmlHttp.onreadystatechange = function () {654 xmlHttp.onreadystatechange = function () {
636 try {655 try {
@@ -741,7 +760,8 @@
741 db: loc.db,760 db: loc.db,
742 units: 'metric',761 units: 'metric',
743 service: message.params.service,762 service: message.params.service,
744 api_key: message.params.api_key,763 twc_api_key: message.params.twc_api_key,
764 owm_api_key: message.params.owm_api_key,
745 interval: message.params.interval765 interval: message.params.interval
746 },766 },
747 secsFromLastFetch = (now-loc.updated)/1000;767 secsFromLastFetch = (now-loc.updated)/1000;
748768
=== renamed file 'app/data/key.js' => 'app/data/keys.js'
--- app/data/key.js 2015-06-11 00:22:03 +0000
+++ app/data/keys.js 2015-10-14 23:53:33 +0000
@@ -1,1 +1,2 @@
1var twcKey = "";1var twcKey = "";
2var owmKey = ""; // goto http://openweathermap.org/appid to get a personal API key
23
=== modified file 'app/ubuntu-weather-app.qml'
--- app/ubuntu-weather-app.qml 2015-09-03 22:55:17 +0000
+++ app/ubuntu-weather-app.qml 2015-10-14 23:53:33 +0000
@@ -22,7 +22,7 @@
22import "components"22import "components"
23import "data" as Data23import "data" as Data
24import "data/WeatherApi.js" as WeatherApi24import "data/WeatherApi.js" as WeatherApi
25import "data/key.js" as Key25import "data/keys.js" as Keys
26import "ui"26import "ui"
2727
28MainView {28MainView {
@@ -118,7 +118,8 @@
118 locations: locations,118 locations: locations,
119 force: force_refresh,119 force: force_refresh,
120 service: settings.service,120 service: settings.service,
121 api_key: Key.twcKey,121 twc_api_key: Keys.twcKey,
122 owm_api_key: Keys.owmKey,
122 interval: settings.refreshInterval123 interval: settings.refreshInterval
123 }124 }
124 }, responseDataHandler)125 }, responseDataHandler)
@@ -172,7 +173,7 @@
172 windUnits = metric ? "kph" : "mph"173 windUnits = metric ? "kph" : "mph"
173 }174 }
174175
175 if (Key.twcKey === "") { // No API key for TWC, so use OWM176 if (Keys.twcKey === "") { // No API key for TWC, so use OWM
176 service = "openweathermap"177 service = "openweathermap"
177 }178 }
178 }179 }
179180
=== modified file 'app/ui/settings/DataProviderPage.qml'
--- app/ui/settings/DataProviderPage.qml 2015-07-24 21:27:14 +0000
+++ app/ui/settings/DataProviderPage.qml 2015-10-14 23:53:33 +0000
@@ -19,7 +19,7 @@
19import QtQuick 2.419import QtQuick 2.4
20import Ubuntu.Components 1.220import Ubuntu.Components 1.2
21import "../../components"21import "../../components"
22import "../../data/key.js" as Key22import "../../data/keys.js" as Keys
2323
24Page {24Page {
25 title: i18n.tr("Data Provider")25 title: i18n.tr("Data Provider")
@@ -54,7 +54,7 @@
5454
55 Component.onCompleted: {55 Component.onCompleted: {
56 // If the key file for TWC is not blank, add the service to the model56 // If the key file for TWC is not blank, add the service to the model
57 if (Key.twcKey !== "") {57 if (Keys.twcKey !== "") {
58 dataProviderModel.append({ text: "The Weather Channel" })58 dataProviderModel.append({ text: "The Weather Channel" })
59 }59 }
60 }60 }
6161
=== modified file 'debian/changelog'
--- debian/changelog 2015-10-07 18:56:07 +0000
+++ debian/changelog 2015-10-14 23:53:33 +0000
@@ -49,6 +49,7 @@
49 * Various tidy ups to improve readability and code commentary of autopilot code49 * Various tidy ups to improve readability and code commentary of autopilot code
50 * ListItem transparent and PageWithBottomEdge colour correct so that they don't appear white on the LocationsPage50 * ListItem transparent and PageWithBottomEdge colour correct so that they don't appear white on the LocationsPage
51 * When expanding day delegates ensure that extra info is visible by animating it into view (LP: #1496425)51 * When expanding day delegates ensure that extra info is visible by animating it into view (LP: #1496425)
52 * Add support for OWM API keys (LP: #1505848)
5253
53 [ Carla Sella ]54 [ Carla Sella ]
54 * Create autopilot test which shows the day delegate (LP: #1452491)55 * Create autopilot test which shows the day delegate (LP: #1452491)
5556
=== modified file 'po/com.ubuntu.weather.pot'
--- po/com.ubuntu.weather.pot 2015-10-07 18:56:07 +0000
+++ po/com.ubuntu.weather.pot 2015-10-14 23:53:33 +0000
@@ -8,7 +8,7 @@
8msgstr ""8msgstr ""
9"Project-Id-Version: ubuntu-weather-app\n"9"Project-Id-Version: ubuntu-weather-app\n"
10"Report-Msgid-Bugs-To: \n"10"Report-Msgid-Bugs-To: \n"
11"POT-Creation-Date: 2015-10-07 19:53+0100\n"11"POT-Creation-Date: 2015-10-15 00:45+0100\n"
12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14"Language-Team: LANGUAGE <LL@li.org>\n"14"Language-Team: LANGUAGE <LL@li.org>\n"

Subscribers

People subscribed via source and target branches

to all changes: