init opencollective
This commit is contained in:
parent
9c8be1a264
commit
40b843f0c9
3 changed files with 35 additions and 44 deletions
|
@ -4,10 +4,11 @@ import '../css/tripledot.css';
|
||||||
|
|
||||||
import { MyIP } from './plugins/myip.js';
|
import { MyIP } from './plugins/myip.js';
|
||||||
import { Time } from './plugins/time.js';
|
import { Time } from './plugins/time.js';
|
||||||
|
import { OpenCollective } from './plugins/opencollective.js';
|
||||||
|
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var time = new Time();
|
var time = new Time();
|
||||||
var myip = new MyIP();
|
var myip = new MyIP();
|
||||||
|
var opencollective = new OpenCollective("zutto");
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { html } from '../html.js';
|
import { vhtml } from './vhtml.js';
|
||||||
export class shield extends vhtml {
|
export class shield extends vhtml {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
@ -11,26 +11,11 @@ export class shield extends vhtml {
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
/*
|
async render(element, content, user) {
|
||||||
async loadingStart(element){
|
|
||||||
if (this.loader !== undefined) this.loader.loadingEnd(element);
|
|
||||||
this.loader = new loader();
|
|
||||||
this.loader.loadingStart(element);
|
|
||||||
return super.loadingStart(element);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async loadingEnd(element){
|
|
||||||
if (this.loader !== undefined)
|
|
||||||
this.loader.loadingEnd(element);
|
|
||||||
|
|
||||||
return super.loadingEnd(element);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
async render(element, content) {
|
|
||||||
content = encodeURIComponent(content);
|
content = encodeURIComponent(content);
|
||||||
return super.render(element, `
|
if (user === undefined) {
|
||||||
<img alt="Static Badge of opencollective contributions" src="https://img.shields.io/badge/${content}-${this.colour}?style=${this.style}&logo=${this.logo}&logoColor=${this.logoColour}&label=${this.label}">
|
user = ""
|
||||||
`);
|
}
|
||||||
|
return super.render(element, `<a href="https://opencollective.com/${user}"><img alt="Static Badge of opencollective contributions" src="https://img.shields.io/badge/${content}-${this.colour}?style=${this.style}&logo=${this.logo}&logoColor=${this.logoColour}&label=${this.label}"></a>`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,18 +3,30 @@ import { shield } from "../components/shield.js";
|
||||||
import { fetcher } from "../fetch.js";
|
import { fetcher } from "../fetch.js";
|
||||||
|
|
||||||
export class OpenCollective extends shield {
|
export class OpenCollective extends shield {
|
||||||
constructor() {
|
constructor(user) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this._ip = "";
|
this._ip = "";
|
||||||
this._source = "https://ip.zutto.fi/"
|
this._source = `https://rest.opencollective.com/v2/${user}/transactions/debit/contribution.json`;
|
||||||
|
//this.total = {};
|
||||||
|
this.total = new Map();
|
||||||
|
this._user = user;
|
||||||
|
|
||||||
vj.watcher.watch('[content="myip"]', (element) => {
|
vj.watcher.watch('[content="opencollective"]', (element) => {
|
||||||
this.loadingStart(element);
|
this.loadingStart(element);
|
||||||
this.ip().then((data) => {
|
this.transactions().then((data) => {
|
||||||
try {
|
try {
|
||||||
this._ip = data.trim();
|
this.json = JSON.parse(data);
|
||||||
vj.ps.publish("ip", {"ip": this._ip});
|
this.json.nodes.forEach((item) => {
|
||||||
|
if (item.kind === "CONTRIBUTION" && item.order.frequency === "MONTHLY") {
|
||||||
|
if (this.total[item.amount.currency] !== undefined) {
|
||||||
|
this.total[item.amount.currency] += (item.amount.value * -1);
|
||||||
|
} else {
|
||||||
|
this.total[item.amount.currency] = (item.amount.value * -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
this.render(element);
|
this.render(element);
|
||||||
this.loadingEnd(element);
|
this.loadingEnd(element);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -25,31 +37,24 @@ export class OpenCollective extends shield {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async ip() {
|
async transactions() {
|
||||||
try {
|
try {
|
||||||
const fetch = new fetcher();
|
const fetch = new fetcher();
|
||||||
console.log("ok");
|
return fetch.go({"url": `${this._source}` });
|
||||||
return fetch.go({"url": `${this._source}/ip` });
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async loadingStart(element) {
|
|
||||||
vj.ps.publish("ip.load.start", {"element": element});
|
|
||||||
return super.loadingStart(element);
|
|
||||||
}
|
|
||||||
|
|
||||||
async loadingEnd(element) {
|
|
||||||
vj.ps.publish("ip.load.end", {"element": element});
|
|
||||||
return super.loadingEnd(element);
|
|
||||||
}
|
|
||||||
|
|
||||||
async render(element) {
|
async render(element) {
|
||||||
try {
|
try {
|
||||||
const rendered = await super.render(element, "4.00 USD/Month");
|
var totalText = "";
|
||||||
vj.ps.publish("ip.rendered", { "element": element, "rendered": rendered });
|
if (Object.keys(this.total).length > 0) {
|
||||||
|
for (var currency in this.total) {
|
||||||
|
totalText += `${this.total[currency]} ${currency}/month`;
|
||||||
|
}
|
||||||
|
const rendered = await super.render(element, `${totalText}`, this._user);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue