-
-
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
Merged
Merged
Add [Liberapay] #1251
Changes from 5 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
41a508d
Add receiving badge.
mattbk b30329c
Fix invalid.
mattbk eda1c32
Stub out giving vs receiving.
mattbk 6792bf0
Finish gives vs receives.
mattbk b609b08
Fix null check.
mattbk 7131f27
Add more badges.
mattbk b549b84
Simplify.
mattbk d61e174
Start tests.
mattbk 7891d70
Fix minor issues.
mattbk b0589c6
Avoid redeclares.
mattbk 923bb5e
Rm trailing space.
mattbk 48b8dae
Add more tests.
mattbk e3df852
Shelve.
mattbk 850457b
Deal with anonymous values.
mattbk 8cd7e04
Fix no goal/anonymous test.
mattbk d606cfa
Add colorScale.
mattbk 0bbceb9
Make suggested changes.
mattbk 09713a8
Fix tests.
mattbk 7b87230
Merge branch 'master' of https://github.com/badges/shields into add-l…
mattbk 4faadc3
Suggestions, but regex is wrong for values less than 1.00.
mattbk 98ef2f2
Fixed regex. Two tests will fail.
mattbk 9d3f86f
Fix tests.
mattbk 322d71a
Merge branch 'master' of https://github.com/mattbk/shields into add-l…
mattbk 14374f0
Merge branch 'add-liberapay' of https://github.com/mattbk/shields int…
mattbk 47803f7
Replace case statement.
mattbk 66fc147
Use isMetric for npatrons.
mattbk f0a84f7
Limit regex.
mattbk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1066,6 +1066,58 @@ 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 type = match[2] | ||
var format = match[3]; | ||
var apiUrl = 'https://liberapay.com/' + entity + '/public.json'; | ||
if (type == 'gives') { | ||
var badgeData = getBadgeData('gives', data); | ||
} else { | ||
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 | ||
if (type == 'gives') { | ||
var value = data.giving.amount; | ||
} else { | ||
var value = data.receiving.amount; | ||
} | ||
if (value != null) { | ||
badgeData.text[1] = '$' + metric(value) + '/week'; | ||
if (value === 0) { | ||
badgeData.colorscheme = 'red'; | ||
} else if (value < 10) { | ||
badgeData.colorscheme = 'yellow'; | ||
} else if (value < 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] = 'invalid'; | ||
sendBadge(format, badgeData); | ||
} | ||
}); | ||
})); | ||
|
||
// Libscore integration. | ||
camp.route(/^\/libscore\/s\/(.*)\.(svg|png|gif|jpg|json)$/, | ||
cache(function(data, match, sendBadge, request) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I guess there is an indentation problem here. And maybe you could make this part simple with a ternary expression, like:
var value = type === 'gives' ? data.giving.amount : data.receiving.amount
.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.
Yes. Although I may go with a switch since I intend to add more options.