Skip to content

Commit a28249b

Browse files
committedFeb 1, 2019
first commit 🎉
0 parents  commit a28249b

File tree

6 files changed

+815
-0
lines changed

6 files changed

+815
-0
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

‎LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Copyright (c) 2019 Endel Dreyer
2+
3+
MIT License:
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

‎README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# shields.io for patreon
2+
3+
This endpoint allows you to display your patreon's current number of patrons or
4+
amount of donations per month on the platform.
5+
6+
**Endpoint parameters:**
7+
8+
- `username=...`: Your Patreon username
9+
- `label=...`: Text on the left side
10+
- `message=...`: (optional) additional text on the right side
11+
- `pledges=1`: (optional) show monthly pledges instead of number of patrons
12+
- `color=...`: Color of the badge
13+
14+
encodeURIComponent("http://shieldsio-patreon.herokuapp.com?username=")
15+
16+
Demo: <img
17+
src="https://img.shields.io/badge/endpoint.svg?url=http%3A%2F%2Fshieldsio-patreon.herokuapp.com%3Fusername%3Dendel%26pledges%3D1&style=for-the-badge" />
18+
19+
## Usage
20+
21+
```
22+
https://img.shields.io/badge/endpoint.svg?url=<URL>&style=<STYLE>
23+
```
24+
25+
See [shields.io](https://shields.io/) for full documentation.
26+
27+
28+
## License
29+
30+
MIT

‎index.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const http = require('http');
2+
const querystring = require('querystring');
3+
const httpie = require('httpie');
4+
const JSDOM = require('jsdom').JSDOM;
5+
const port = process.env.PORT || 8888;
6+
7+
const server = http.createServer(async (request, response) => {
8+
const params = querystring.parse(request.url.substr(2));
9+
const username = params.username;
10+
11+
if (!username) {
12+
response.writeHead(500, { 'Content-Type': 'application/json' });
13+
response.write(JSON.stringify({"error": '"username" is required on query string.'}));
14+
return;
15+
}
16+
17+
const { data } = await httpie.get('https://patreon.com/' + username);
18+
const { document } = (new JSDOM(data)).window;
19+
20+
const pledges = document.querySelectorAll('h6.sc-iwsKbI');
21+
const message = (params.pledges)
22+
? pledges[1].innerHTML
23+
: pledges[0].innerHTML;
24+
25+
if (params.message) {
26+
message += " " + params.message;
27+
}
28+
29+
const res = {
30+
"schemaVersion": 1,
31+
"label": params.label || "patreon",
32+
"message": message,
33+
"color": params.color || "ff5441"
34+
}
35+
response.writeHead(200, { 'Content-Type': 'application/json' });
36+
response.write(JSON.stringify(res));
37+
});
38+
39+
server.listen(port);
40+
console.log("Listening on", port);

‎package-lock.json

+695
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "shieldsio-patreon",
3+
"version": "1.0.0",
4+
"description": "displays amount of donations you have on patreon",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "node index.js",
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "git+ssh://git@github.com/endel/shieldsio-patreon.git"
13+
},
14+
"keywords": [
15+
"shieldsio",
16+
"patreon"
17+
],
18+
"author": "Endel Dreyer",
19+
"license": "MIT",
20+
"bugs": {
21+
"url": "https://github.com/endel/shieldsio-patreon/issues"
22+
},
23+
"homepage": "https://github.com/endel/shieldsio-patreon#readme",
24+
"dependencies": {
25+
"httpie": "^1.0.1",
26+
"jsdom": "^13.2.0"
27+
}
28+
}

0 commit comments

Comments
 (0)
Please sign in to comment.