Skip to content
Browse files

Minor update.

Ran it through the code formatter apparently. ;-)
  • Loading branch information...
1 parent ffd872d commit 1a2da4579288b4732b85b5f77a8da95b40f65cb6 @mansilladev mansilladev committed
Showing with 37 additions and 42 deletions.
  1. +37 −42 mashery.hotwire/3.4.0/hotwire.js
View
79 mashery.hotwire/3.4.0/hotwire.js
@@ -2,75 +2,70 @@
// ***********************************************************
// Insert your Hotwire API Key here. ReadMe for more info.
-var api_key ='your-API-key-here';
+var api_key = 'your-API-key-here';
// ***********************************************************
// ***********************************************************
// Check if valid API Key
-function check_keys(){
+function check_keys() {
var url = 'http://api.hotwire.com/v1/deal/hotel?limit=1&dest=94103&distance=15&apikey=' + api_key;
- AppMobi.device.getRemoteData(url,"GET","","displayFlashMessage","displayFlashMessage");
+ AppMobi.device.getRemoteData(url, "GET", "", "displayFlashMessage", "displayFlashMessage");
}
-function displayFlashMessage (rawPayload) {
+function displayFlashMessage(rawPayload) {
- var httpStatus = '200';
- var matchString = new RegExp("code: ([0-9]{3})");
- var matchArray = rawPayload.match(matchString);
-
- if (matchArray) {
- httpStatus = matchArray[1];
- }
+ var httpStatus = '200';
+ var matchString = new RegExp("code: ([0-9]{3})");
+ var matchArray = rawPayload.match(matchString);
- $('#flash').show();
- if(httpStatus == '404') {
- AppMobi.notification.alert('Profile Not Found','Oops','OK');
- reset_screen();
- }
- else if(httpStatus == '403') {
- AppMobi.notification.alert('Please check the Readme.md file for instructions','Invalid API Key','OK');
- $('#flash').addClass('red');
- $('#flash').html("<p class='center'><strong>Hotwire API Key Not Found</strong></p><p>Please see <a target='_blank' href='Readme.md'>ReadMe</a> file located in the Project directory for instructions.</p><p>(Hint: To locate your project directory, click on the <img class='middle' style='width:35px;margin-left:-5px;' src='images/project_icon.png'/> icon on the Emulator Toolbar above</p>");
- }
- else if(httpStatus == '202') {
- AppMobi.notification.alert('Profile Not Found','Invalid ID','OK');
- reset_screen();
+ if(matchArray) {
+ httpStatus = matchArray[1];
+ }
+
+ $('#flash').show();
+ if(httpStatus == '404') {
+ AppMobi.notification.alert('Profile Not Found', 'Oops', 'OK');
+ reset_screen();
+ } else if(httpStatus == '403') {
+ AppMobi.notification.alert('Please check the Readme.md file for instructions', 'Invalid API Key', 'OK');
+ $('#flash').addClass('red');
+ $('#flash').html("<p class='center'><strong>Hotwire API Key Not Found</strong></p><p>Please see <a target='_blank' href='Readme.md'>ReadMe</a> file located in the Project directory for instructions.</p><p>(Hint: To locate your project directory, click on the <img class='middle' style='width:35px;margin-left:-5px;' src='images/project_icon.png'/> icon on the Emulator Toolbar above</p>");
+ } else if(httpStatus == '202') {
+ AppMobi.notification.alert('Profile Not Found', 'Invalid ID', 'OK');
+ reset_screen();
+ } else {
+ $('#flash').addClass('green');
+ $('#flash').html("<p class='center green'>Valid API Key Found</p>");
}
- else {
- $('#flash').addClass('green');
- $('#flash').html("<p class='center green'>Valid API Key Found</p>");
- }
}
-function searchDeals(){
+function searchDeals() {
var search = $('#search').val();
- var url = 'http://api.hotwire.com/v1/deal/hotel?format=json&limit=3&distance=5&apikey=' + api_key + '&dest=' + search;
- AppMobi.device.getRemoteData(url,"GET","","searchDealsCB","displayFlashMessage");
+ var url = 'http://api.hotwire.com/v1/deal/hotel?format=json&limit=10&distance=10&apikey=' + api_key + '&dest=' + search;
+ AppMobi.device.getRemoteData(url, "GET", "", "searchDealsCB", "displayFlashMessage");
}
-function searchDealsCB(rawPayload)
-{
+function searchDealsCB(rawPayload) {
var data = $.parseJSON(rawPayload);
reset_screen();
- if (!data.Result[0]) {
+ if(!data.Result[0]) {
alert('No hotel deals could be found there. Sorry!');
return false;
- }
-
+ }
+
$("#hotwire-output").show();
- for (var x in data.Result) {
+ for(var x in data.Result) {
var deal = data.Result[x];
var html = "<span onclick='AppMobi.device.launchExternal(\"" + deal.Url + "\");'>" + deal.Headline + "&nbsp;<img src='images/hwarrow.png' height=/></span><br /><br />";
$("#hotwire-output .deals").append(html);
}
}
-function reset_screen(){
+function reset_screen() {
$(".output-inner").hide();
}
-function errorCB(data)
-{
- console.log ("GRD error "+data);
-}
+function errorCB(data) {
+ console.log("GRD error " + data);
+}

0 comments on commit 1a2da45

Please sign in to comment.
Something went wrong with that request. Please try again.