Global Lender
A Pebble app for finding new and interesting loans on kiva.org
Functions | Variables
app.js File Reference

Functions

function callKivaApiAsync (url, parseFxn, maxResults)
 
function getLenderInfo ()
 
function getLoansForLender ()
 
function getKivaActiveFieldPartners ()
 
function getPreferredLoans (prefCC, maxResults)
 
Pebble addEventListener ('appmessage', function(e){console.log("AppMessage received: "+JSON.stringify(e.payload));var dict=e.payload;if('KEY_GET_LENDER_INFO'in dict){getLenderInfo();getLoansForLender();}else if('KEY_GET_PREFERRED_LOANS'in dict){var prefCC=dict['KEY_GET_PREFERRED_LOANS'];var maxResults=10;getPreferredLoans(prefCC, maxResults);}else{console.log("Unrecognized app message: "+JSON.stringify(dict));}})
 Listen for when an AppMessage is received. More...
 

Variables

var kivaCC = {}
 
var baseKivaUrl = "http://api.kivaws.org/v1/"
 
var jsonExt = ".json"
 
var kivaAppId = 'com.magnosity.global-lender'
 
var kivaAppIdParam = "appId=" + kivaAppId
 
var lenderId = 'jdb'
 
var pageArray = []
 
Array prototype unique
 Array extension to return the unique values of an array. More...
 
var xhrRequest
 

Function Documentation

Pebble addEventListener ( 'ready'  ,
function(e){console.log("PebbleKit JS ready!");Pebble.sendAppMessage({"KEY_PEBKIT_READY":1});getKivaActiveFieldPartners();}   
)

Listen for when an AppMessage is received.

Listen for when the watch opens communication and inform the watch that the PebbleKit end of the channel is ready.

function callKivaApiAsync (   url,
  parseFxn,
  maxResults 
)

Calls the Kiva API web service, parsing results by calling the function passed in as parseFxn.

Parameters
[in]urlURL of the webservice
[in]parseFxnFunction that returns a dictionary of key/value pairs that represent the information that must be passed back to the Pebble watch. Function should expect to receive an array of JSON objects (range = [0 .. n-1 pages]), one value for each page.
[in]maxResultsPredetermined limit to the number of results we need to fetch from the webservice. If maxResults is zero, then all results will be fetched. (If zero results is really desired, then don't call this function!)
function getKivaActiveFieldPartners ( )
function getLenderInfo ( )
function getLoansForLender ( )
function getPreferredLoans (   prefCC,
  maxResults 
)

Variable Documentation

var baseKivaUrl = "http://api.kivaws.org/v1/"
var jsonExt = ".json"
var kivaAppId = 'com.magnosity.global-lender'
var kivaAppIdParam = "appId=" + kivaAppId
var kivaCC = {}
var lenderId = 'jdb'
var pageArray = []
Array prototype unique
Initial value:
= function() {
var a = [], l = this.length;
for(var i=0; i<l; i++) {
for(var j=i+1; j<l; j++)
if (this[i] === this[j]) j = ++i;
a.push(this[i]);
}
return a;
}

Array extension to return the unique values of an array.

var xhrRequest
Initial value:
= function (method, url, callback) {
var xhr = new XMLHttpRequest();
xhr.onload = function () {
callback(this.responseText);
};
xhr.onerror = function() {
console.log("HTTP " + xhr.status + " ERROR: " + xhr.statusText);
};
xhr.ontimeout = function() {
console.log("HTTP TIMEOUT for " + url);
};
xhr.timeout = 10000;
xhr.open(method, url);
xhr.send();
}