Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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