| 4 | |
| 5 | class Widget { |
| 6 | constructor(options = {}) { |
| 7 | this.options = options; |
| 8 | this.el = this.options.el || document.querySelector(options.selector || '.gitcoin-widget'); |
| 9 | this.options.organization = this.el.dataset.organization || this.options.organization; |
| 10 | this.options.repository = this.el.dataset.repository || this.options.repository; |
| 11 | this.options.orderBy = this.el.dataset['order-by'] || this.options.orderBy; |
| 12 | this.options.limit = this.el.dataset['limit'] || this.options.limit; |
| 13 | fetch(`https://gitcoin.co/api/v0.1/bounties/?raw_data=${this.options.repository}&org=${this.options.organization}&network=mainnet&coinbase=unknown&order_by=${this.orderBy()}&limit=${this.limit()}`) |
| 14 | .then(response => response.json()) |
| 15 | .then(json => { |
| 16 | this.data = json; |
| 17 | this.render(); |
| 18 | }); |
| 19 | } |
| 20 | orderBy() { |
| 21 | return this.options.orderBy ? this.options.orderBy : '-expires_date'; |
| 22 | } |