-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add [Liberapay] #1251
Add [Liberapay] #1251
Changes from 1 commit
41a508d
b30329c
eda1c32
6792bf0
b609b08
7131f27
b549b84
d61e174
7891d70
b0589c6
923bb5e
48b8dae
e3df852
850457b
8cd7e04
d606cfa
0bbceb9
09713a8
7b87230
4faadc3
98ef2f2
9d3f86f
322d71a
14374f0
47803f7
66fc147
f0a84f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1066,6 +1066,49 @@ cache(function(data, match, sendBadge, request) { | |
}); | ||
})); | ||
|
||
// Liberapay integration. | ||
camp.route(/^\/liberapay\/(.*)\.(svg|png|gif|jpg|json)$/, | ||
cache(function(data, match, sendBadge, request) { | ||
var entity = match[1]; // eg, 'Changaco' | ||
var format = match[2]; | ||
var apiUrl = 'https://liberapay.com/' + entity + '/public.json'; | ||
var badgeData = getBadgeData('receives', data); | ||
if (badgeData.template === 'social') { | ||
badgeData.logo = getLogo('liberapay', data); | ||
} | ||
request(apiUrl, function dealWithData(err, res, buffer) { | ||
if (err != null) { | ||
badgeData.text[1] = 'inaccessible'; | ||
sendBadge(format, badgeData); | ||
return; | ||
} | ||
try { | ||
var data = JSON.parse(buffer); | ||
// Avoid falsey checks because amounts may be 0 | ||
var receiving = data.receiving.amount; | ||
if (!isNaN(receiving)) { | ||
badgeData.text[1] = '$' + metric(receiving) + '/week'; | ||
if (receiving === 0) { | ||
badgeData.colorscheme = 'red'; | ||
} else if (receiving < 10) { | ||
badgeData.colorscheme = 'yellow'; | ||
} else if (receiving < 100) { | ||
badgeData.colorscheme = 'green'; | ||
} else { | ||
badgeData.colorscheme = 'brightgreen'; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should be able to accomplish this using colorScale([0, 10, 100])(receiving) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how to implement that, is there an example somewhere? |
||
sendBadge(format, badgeData); | ||
} else { | ||
badgeData.text[1] = 'anonymous'; | ||
sendBadge(format, badgeData); | ||
} | ||
} catch(e) { | ||
badgeData.text[1] = apiUrl; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this put the API URL on the badge? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a testing mistake, looks like I didn't push my latest change. |
||
sendBadge(format, badgeData); | ||
} | ||
}); | ||
})); | ||
|
||
// Libscore integration. | ||
camp.route(/^\/libscore\/s\/(.*)\.(svg|png|gif|jpg|json)$/, | ||
cache(function(data, match, sendBadge, request) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit odd to use
isNaN
on a JSON value. Can you invert this and testreceiving === null
instead?