Skip to content

Instantly share code, notes, and snippets.

@cheesinglee
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cheesinglee/df4320f45686f53e0874 to your computer and use it in GitHub Desktop.
Save cheesinglee/df4320f45686f53e0874 to your computer and use it in GitHub Desktop.
function makeStatusIndicator(loan_id){
// this function executes the Kiva API query for a particular loan id, feeds the result through
// the actionable model, and returns a green light or red light icon depending on the result.
// create DOM object for icon
var img = $('<img class="indicator">') ;
// Kiva API call
var url = "http://api.kivaws.org/v1/loans/" + loan_id + ".json" ;
$.get(url,function(data){
// pass response to actionable model
var data = data.loans[0] ;
var status = predictStatus(data.funded_amount,data.location.country,data.loan_amount,data.sector) ;
// create the indicator. use chrome.extension.getURL to resolve path to image resource
if (status == "paid"){
img.attr("src",chrome.extension.getURL("images/green_light.png")) ;
}else{
img.attr("src",chrome.extension.getURL("images/red_light.png")) ;
}
img.attr("title","The predicted status for this loan is: " + status.toUpperCase()) ;
})
return img ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment