Merge lp:~dpm/ubuntu-weather-app/minor-weather-api-improv into lp:ubuntu-weather-app/obsolete.trunk

Proposed by David Planella
Status: Merged
Approved by: Martin Borho
Approved revision: 193
Merged at revision: 197
Proposed branch: lp:~dpm/ubuntu-weather-app/minor-weather-api-improv
Merge into: lp:ubuntu-weather-app/obsolete.trunk
Prerequisite: lp:~martin-borho/ubuntu-weather-app/weather-channel-client
Diff against target: 103 lines (+34/-14)
1 file modified
components/WeatherApi.js (+34/-14)
To merge this branch: bzr merge lp:~dpm/ubuntu-weather-app/minor-weather-api-improv
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Martin Borho Approve
Review via email: mp+205753@code.launchpad.net

Commit message

Minor improvements on the weather API: added parameterize() function, added locale parameters to TWC calls, used _servicename consistently

Description of the change

Minor improvements on the weather API:

- Added parameterize() function to avoid code duplication
- Added locale parameters to TWC calls
- Used _servicename consistently for openweathermap

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Martin Borho (martin-borho) wrote :

David,

would you mind to add "hours=48" as additional param to the TWC call? Then we would have a hourly focecast for 48 instead of 24 hours. Overlooked it and it misses in the TWC branch.

Cheers
Martin

191. By David Planella

Merged from parent branch

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
192. By David Planella

Made hourly forecast to be 48 hours instead of the default 24

Revision history for this message
David Planella (dpm) wrote :

Done, made hourly forecast to be 48 hours. Let me know if you need any more changes to this branch.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Martin Borho (martin-borho) wrote :

Looks good to me, thanks!

Glad you'Ve found the way through all the callbacks! ;)

review: Approve
193. By David Planella

Merged from the latest changes in the TWC client branch

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'components/WeatherApi.js'
--- components/WeatherApi.js 2014-02-15 10:47:52 +0000
+++ components/WeatherApi.js 2014-02-15 10:47:52 +0000
@@ -83,6 +83,17 @@
83 minutes: locTime.getUTCMinutes()83 minutes: locTime.getUTCMinutes()
84 }84 }
85}85}
86// Serialize a JavaScript object to URL parameters
87// E.g. {param1: value1, param2: value2} to "param1=value&param2=value"
88// TODO: it'd be nice to make it work with either passing a single object
89// or several at once
90function parameterize(obj) {
91 var str = [];
92 for(var param in obj) {
93 str.push(encodeURIComponent(param) + "=" + encodeURIComponent(obj[param]));
94 }
95 return str.join("&");
96}
8697
87var GeoipApi = (function() {98var GeoipApi = (function() {
88 var _baseUrl = "http://geoip.ubuntu.com/lookup";99 var _baseUrl = "http://geoip.ubuntu.com/lookup";
@@ -174,6 +185,8 @@
174 */185 */
175 var _baseUrl = "http://api.openweathermap.org/data/2.5/";186 var _baseUrl = "http://api.openweathermap.org/data/2.5/";
176 //187 //
188 var _serviceName = "openweathermap";
189 //
177 var _icon_map = {190 var _icon_map = {
178 "01d": "clear_day",191 "01d": "clear_day",
179 "01n": "clear_night",192 "01n": "clear_night",
@@ -219,7 +232,7 @@
219 condition: data.weather[0]232 condition: data.weather[0]
220 };233 };
221 if(data.id !== undefined) {234 if(data.id !== undefined) {
222 result["service"] = "openweathermap";235 result["service"] = _serviceName;
223 result["service_id"] = data.id;236 result["service_id"] = data.id;
224 }237 }
225 return result;238 return result;
@@ -263,8 +276,8 @@
263 todayDate; 276 todayDate;
264 print("["+location.name+"] "+JSON.stringify(localNow))277 print("["+location.name+"] "+JSON.stringify(localNow))
265 // add openweathermap id for faster responses278 // add openweathermap id for faster responses
266 if(location.services && !location.services["openweathermap"] && data["current"].id) {279 if(location.services && !location.services[_serviceName] && data["current"].id) {
267 location.services["openweathermap"] = data["current"].id280 location.services[_serviceName] = data["current"].id
268 }281 }
269 //282 //
270 data["daily"]["list"].forEach(function(dayData) {283 data["daily"]["list"].forEach(function(dayData) {
@@ -306,10 +319,10 @@
306 },319 },
307 latLongParams = "&lat="+encodeURIComponent(params.location.coord.lat)320 latLongParams = "&lat="+encodeURIComponent(params.location.coord.lat)
308 + "&lon="+encodeURIComponent(params.location.coord.lon);321 + "&lon="+encodeURIComponent(params.location.coord.lon);
309 if(params.location.services && params.location.services["openweathermap"]) {322 if(params.location.services && params.location.services[_serviceName]) {
310 urls.current = _baseUrl + "weather?units="+params.units+"&id="+params.location.services["openweathermap"];323 urls.current = _baseUrl + "weather?units="+params.units+"&id="+params.location.services[_serviceName];
311 urls.daily = _baseUrl + "forecast/daily?id="+params.location.services["openweathermap"]+"&cnt=10&units="+params.units324 urls.daily = _baseUrl + "forecast/daily?id="+params.location.services[_serviceName]+"&cnt=10&units="+params.units
312 urls.forecast = _baseUrl + "forecast?id="+params.location.services["openweathermap"]+"&units="+params.units325 urls.forecast = _baseUrl + "forecast?id="+params.location.services[_serviceName]+"&units="+params.units
313326
314 } else if (params.location.coord) {327 } else if (params.location.coord) {
315 urls.current = _baseUrl + "weather?units="+params.units+latLongParams;328 urls.current = _baseUrl + "weather?units="+params.units+latLongParams;
@@ -534,15 +547,22 @@
534 //547 //
535 function _getUrl(params) {548 function _getUrl(params) {
536 var url, serviceId,549 var url, serviceId,
537 units = (params.units === "metric") ? "m" : "e",550 baseParams = {
538 baseParams = "key="+params.api_key+"&units="+units;551 key: params.api_key,
552 units: (params.units === "metric") ? "m" : "e",
553 locale: Qt.locale().name,
554 hours: "48",
555 },
556 commands = {
557 "mobileaggregation": "mobile/mobagg/",
558 };
539 if(params.location.services && params.location.services[_serviceName]) {559 if(params.location.services && params.location.services[_serviceName]) {
540 serviceId = encodeURIComponent(params.location.services[_serviceName]);560 serviceId = encodeURIComponent(params.location.services[_serviceName]);
541 url = _baseUrl+"mobile/mobagg/"+serviceId+".js?"+baseParams;561 url = _baseUrl+commands["mobileaggregation"]+serviceId+".js?"+parameterize(baseParams);
542 } else if (params.location.coord) {562 } else if (params.location.coord) {
543 url = _baseUrl+"mobile/mobagg/get.js?"+baseParams+563 var coord = {lat: params.location.coord.lat, lng: params.location.coord.lon};
544 "&lat="+encodeURIComponent(params.location.coord.lat)+564 url = _baseUrl+commands["mobileaggregation"]+"get.js?"+parameterize(baseParams)+"&"+
545 "&lng="+encodeURIComponent(params.location.coord.lon);565 parameterize(coord);
546 }566 }
547 return url;567 return url;
548 }568 }
@@ -592,7 +612,7 @@
592 function _sendRequest(request, onSuccess, onError) {612 function _sendRequest(request, onSuccess, onError) {
593 var xmlHttp = new XMLHttpRequest();613 var xmlHttp = new XMLHttpRequest();
594 if (xmlHttp) {614 if (xmlHttp) {
595 console.log(request.url);615 console.log("Sent request URL: " + request.url);
596 xmlHttp.open('GET', request.url, true);616 xmlHttp.open('GET', request.url, true);
597 xmlHttp.onreadystatechange = function () {617 xmlHttp.onreadystatechange = function () {
598 try {618 try {

Subscribers

People subscribed via source and target branches