-
-
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
Update Gratipay badge for API change #533
Conversation
As discussed here, Given that, it may be more future-proof to have |
Yea, I was thinking about that, and it seems like when they finally finalize their API to distinguish teams/people, perhaps Shields wouldn't even support I was actually thinking we should just change the API URL to |
I won't deny I was leaning on the separation of user and team as well! However, I feel we should only separate them if they live on separate namespaces, that is, if we can theoretically have a team with the exact same name as a user. I currently believe that is not possible, so I'd wait to separate them until it becomes possible. Until then, checking for |
Gotcha. My understanding of their discussions in their issues was that it would be possible, which is why they added the |
In that case, let's separate them! Given what is currently implemented, we can set the old shields URL to the behavior of users. What do you think about something like that? diff --git a/server.js b/server.js
index 04f9a4f..4856f99 100644
--- a/server.js
+++ b/server.js
@@ -819,10 +819,10 @@ cache(function(data, match, sendBadge, request) {
}));
// Gratipay integration.
-camp.route(/^\/(gittip|gratipay)\/(.*)\.(svg|png|gif|jpg|json)$/,
+camp.route(/^\/(?:gittip|gratipay)(?:\/user)?\/(.*)\.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {
- var user = match[2]; // eg, `JSFiddle`.
- var format = match[3];
+ var user = match[1]; // eg, `dougwilson`.
+ var format = match[2];
var apiUrl = 'https://www.gratipay.com/' + user + '/public.json';
var badgeData = getBadgeData('tips', data);
if (badgeData.template === 'social') {
@@ -836,8 +836,9 @@ cache(function(data, match, sendBadge, request) {
}
try {
var data = JSON.parse(buffer);
- if (data.receiving) {
- var money = parseInt(data.receiving);
+ var receiving = data.receiving || data.taking;
+ if (receiving) {
+ var money = parseInt(receiving);
badgeData.text[1] = '$' + metric(money) + '/week';
if (money === 0) {
badgeData.colorscheme = 'red'; |
Awesome, let's iterate! So what I did was took your patch there and altered it a bit as well. My additions were the following:
diff --git a/server.js b/server.js
index aa97ebf..a1f181b 100644
--- a/server.js
+++ b/server.js
@@ -819,11 +819,11 @@ cache(function(data, match, sendBadge, request) {
}));
// Gratipay integration.
-camp.route(/^\/(gittip|gratipay)\/(.*)\.(svg|png|gif|jpg|json)$/,
+camp.route(/^\/(?:gittip|gratipay(?:\/user)?)\/(.*)\.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {
- var user = match[2]; // eg, `JSFiddle`.
- var format = match[3];
- var apiUrl = 'https://www.gratipay.com/' + user + '/public.json';
+ var user = match[1]; // eg, `dougwilson`.
+ var format = match[2];
+ var apiUrl = 'https://www.gratipay.com/~' + user + '/public.json';
var badgeData = getBadgeData('tips', data);
if (badgeData.template === 'social') {
badgeData.logo = badgeData.logo || logos.gratipay;
@@ -836,8 +836,9 @@ cache(function(data, match, sendBadge, request) {
}
try {
var data = JSON.parse(buffer);
- if (data.receiving) {
- var money = parseInt(data.receiving);
+ var receiving = data.receiving || data.taking;
+ if (receiving) {
+ var money = parseInt(receiving);
badgeData.text[1] = '$' + metric(money) + '/week';
if (money === 0) {
badgeData.colorscheme = 'red'; Thoughts? |
My thoughts are that it is great! ☺ |
Awesome :) I'm really looking forward to Gratipay having an API for the teams soon :) |
This updates the logic for the Gratipay badge for a change in the Gratipay API where the "receiving" field was renamed to "taking" as part of their migration to teams.