-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathcommerce.js
94 lines (82 loc) · 2.18 KB
/
commerce.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const AbstractEndpoint = require('../endpoint')
module.exports = class CommerceEndpoint extends AbstractEndpoint {
// Current things to grab in the delivery box
delivery () {
return new DeliveryEndpoint(this)
}
// Current gem/coin exchange rates
exchange () {
return new ExchangeEndpoint(this)
}
// Current tradingpost listings
listings () {
return new ListingsEndpoint(this)
}
// Current tradingpost prices
prices () {
return new PricesEndpoint(this)
}
// Current and completed transactions
transactions () {
return {
current: () => ({
buys: () => new TransactionsEndpoint(this, 'current', 'buys'),
sells: () => new TransactionsEndpoint(this, 'current', 'sells')
}),
history: () => ({
buys: () => new TransactionsEndpoint(this, 'history', 'buys'),
sells: () => new TransactionsEndpoint(this, 'history', 'sells')
})
}
}
}
class DeliveryEndpoint extends AbstractEndpoint {
constructor (client) {
super(client)
this.url = `/v2/commerce/delivery`
this.isAuthenticated = true
this.cacheTime = 5 * 60
}
}
class ExchangeEndpoint extends AbstractEndpoint {
constructor (client) {
super(client)
this.url = '/v2/commerce/exchange'
this.cacheTime = 10 * 60
}
gems (quantity) {
return super.get(`/gems?quantity=${quantity}`, true)
}
coins (quantity) {
return super.get(`/coins?quantity=${quantity}`, true)
}
}
class ListingsEndpoint extends AbstractEndpoint {
constructor (client) {
super(client)
this.url = '/v2/commerce/listings'
this.isPaginated = true
this.isBulk = true
this.supportsBulkAll = false
this.cacheTime = 2 * 60
}
}
class PricesEndpoint extends AbstractEndpoint {
constructor (client) {
super(client)
this.url = '/v2/commerce/prices'
this.isPaginated = true
this.isBulk = true
this.supportsBulkAll = false
this.cacheTime = 60
}
}
class TransactionsEndpoint extends AbstractEndpoint {
constructor (client, type, list) {
super(client)
this.url = `/v2/commerce/transactions/${type}/${list}`
this.isPaginated = true
this.isAuthenticated = true
this.cacheTime = 10 * 60
}
}