-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Render sponsors from Open Collective REST API #3972
Conversation
var sponsors = function() { | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open('GET', 'https://opencollective.com/typelevel/members/all.json', true); | ||
xhr.responseType = 'json'; | ||
xhr.onload = function() { | ||
var status = xhr.status; | ||
if (status === 200) { | ||
for(i = 0; i < xhr.response.length; i++) { | ||
var member = xhr.response[i]; | ||
if (member.isActive) { | ||
switch (member.tier) { | ||
case 'Platinum Sponsor': | ||
addSponsor('platinum-sponsors', member, PlatinumSize); | ||
case 'Gold Sponsor': | ||
addSponsor('gold-sponsors', member, GoldSize); | ||
case 'Silver Sponsor': | ||
addSponsor('silver-sponsors', member, SilverSize); | ||
case 'backer': | ||
addSponsor('backers', member, BackerSize); | ||
break; | ||
default: | ||
if (member.totalAmountDonated > 0) { | ||
addSponsor('other-contributors', member, ContributorSize); | ||
} | ||
} | ||
}; | ||
} | ||
} | ||
}; | ||
xhr.send(); | ||
}; |
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.
NBD, but fetch is the modern way. Something like this I think:
var sponsors = function() { | |
var xhr = new XMLHttpRequest(); | |
xhr.open('GET', 'https://opencollective.com/typelevel/members/all.json', true); | |
xhr.responseType = 'json'; | |
xhr.onload = function() { | |
var status = xhr.status; | |
if (status === 200) { | |
for(i = 0; i < xhr.response.length; i++) { | |
var member = xhr.response[i]; | |
if (member.isActive) { | |
switch (member.tier) { | |
case 'Platinum Sponsor': | |
addSponsor('platinum-sponsors', member, PlatinumSize); | |
case 'Gold Sponsor': | |
addSponsor('gold-sponsors', member, GoldSize); | |
case 'Silver Sponsor': | |
addSponsor('silver-sponsors', member, SilverSize); | |
case 'backer': | |
addSponsor('backers', member, BackerSize); | |
break; | |
default: | |
if (member.totalAmountDonated > 0) { | |
addSponsor('other-contributors', member, ContributorSize); | |
} | |
} | |
}; | |
} | |
} | |
}; | |
xhr.send(); | |
}; | |
var sponsors = async function() { | |
var response = await fetch('https://opencollective.com/typelevel/members/all.json'); | |
if (response.ok) { | |
var members = await response.json(); | |
for(i = 0; i < members.length; i++) { | |
var member = members[i]; | |
if (member.isActive) { | |
switch (member.tier) { | |
case 'Platinum Sponsor': | |
addSponsor('platinum-sponsors', member, PlatinumSize); | |
case 'Gold Sponsor': | |
addSponsor('gold-sponsors', member, GoldSize); | |
case 'Silver Sponsor': | |
addSponsor('silver-sponsors', member, SilverSize); | |
case 'backer': | |
addSponsor('backers', member, BackerSize); | |
break; | |
default: | |
if (member.totalAmountDonated > 0) { | |
addSponsor('other-contributors', member, ContributorSize); | |
} | |
} | |
} | |
} | |
} | |
}; |
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.
Thanks. I don't know and I don't have time to retest it, but if a knowledgeable reviewer agrees, please feel free to commit it!
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.
If it ain't broke don't fix it! 😆
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.
Lets move forward with this, and then we can PR this. We want to fix whats here most importantly.
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.
👍 My CSS is dated and my JS was never competent, and would be delighted to see either improved once the fire is out.
Co-authored-by: Arman Bilge <armanbilge@gmail.com>
I worry the missing avatar SVG isn't very gender neutral. Or also that it represents companies. It's what I found on Wikimedia. Better ideas welcome there too, if people make a second pass. |
This didn't work and in fact made things worse because that endpoint doesn't add CORS headers. Only the static ones rendered. 😡 |
Apparently it needs to be converted to GraphQL, which I haven't the slightest idea how to do. |
I'll give this a try! |
This reveals three statuses: This one doesn't seem to sort by amount like the old endpoint did. That was nice, but not critical. |
Just got this: |
Ok, but that one I posted is missing cors :( |
I think this is the only way to go. Using the GraphQL API would require an API key which is not worth the trouble. I'll take your suggestions and PR. |
Instead I created a PR at opencollective to add cors to the endpoint. They seem active on that repo and responsive on slack, so if you're willing to wait a day and see how this plays out? Otherwise we'll fallback to exactly what @rossabaker proposed in his comment above. |
The one I posted has CORS, but has the more complex GraphQL response, which I think is still not too hard to traverse as pure JSON. |
Sorry, when I responded, it hadn't shown the most recent comments. I saw on another issue that the /v1 is no longer maintained, so I think we're going to need to go ahead with the /v2. |
The code for |
Makes sponsors appear automatically on the site, at the expense of appearing in the README.
Issues:
Local rendering below: