/
templates.go
122 lines (100 loc) · 3.69 KB
/
templates.go
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package atomicassets
import (
"fmt"
"strconv"
urljoin "github.com/TheBoringDude/go-urljoin"
"github.com/google/go-querystring/query"
)
const TEMPLATES_API = "templates"
type GetTemplatesQuery struct {
CollectionName string `url:"collection_name,omitempty"`
SchemaName string `url:"schema_name,omitempty"`
IssuedSupply int `url:"issued_supply,omitempty"`
MinIssuedSupply int `url:"min_issued_supply,omitempty"`
MaxIssuedSupply int `url:"max_issued_supply,omitempty"`
HasAssets bool `url:"has_assets,omitempty"`
MaxSupply int `url:"max_supply,omitempty"`
IsBurnable bool `url:"is_burnable,omitempty"`
IsTransferable bool `url:"is_transferable,omitempty"`
AuthorizedAccount string `url:"authorized_account,omitempty"`
Match string `url:"match,omitempty"`
CollectionBlacklist []string `url:"collection_blacklist,omitempty" del:","`
CollectionWhitelist []string `url:"collection_whitelist,omitempty" del:","`
IDs []string `url:"ids,omitempty" del:","`
LowerBound string `url:"lower_bound,omitempty"`
UpperBound string `url:"upper_bound,omitempty"`
Before int64 `url:"before,omitempty"`
After int64 `url:"after,omitempty"`
Page int `url:"page,omitempty"`
Limit int `url:"limit,omitempty"`
Order string `url:"order,omitempty"`
Sort string `url:"sort,omitempty"`
}
// GetTemplates fetches templates.
func (a *AtomicAssets) GetTemplates(options *GetTemplatesQuery) (*TemplatesProps, error) {
var u string
if options != nil {
v, _ := query.Values(options)
u = urljoin.UrlJoin(a.apiUrl, TEMPLATES_API, fmt.Sprintf("?%s", v.Encode()))
} else {
u = urljoin.UrlJoin(a.apiUrl, TEMPLATES_API)
}
fmt.Println(u)
var result = &TemplatesProps{}
if err := a._requester(u, result); err != nil {
return nil, err
}
return result, nil
}
// GetTemplateID gets the template by its id.
func (a *AtomicAssets) GetTemplateID(collectionName string, templateID int) (*TemplateIDProps, error) {
u := urljoin.UrlJoin(a.apiUrl, TEMPLATES_API, collectionName, strconv.Itoa(templateID))
var result = &TemplateIDProps{}
if err := a._requester(u, result); err != nil {
return nil, err
}
return result, nil
}
// GetTemplateIDStats gets the collection's stats.
func (a *AtomicAssets) GetTemplateIDStats(collectionName string, templateID int) (*TemplateIDStatsProps, error) {
u := urljoin.UrlJoin(a.apiUrl, TEMPLATES_API, collectionName, strconv.Itoa(templateID), "stats")
var result = &TemplateIDStatsProps{}
if err := a._requester(u, result); err != nil {
return nil, err
}
return result, nil
}
type GetTemplateIDLogs GetAssetLogsQuery
// GetTemplateIDLogs gets the collection's logs.
func (a *AtomicAssets) GetTemplateIDLogs(collectionName string, templateID int, options *GetTemplateIDLogs) (*TemplateIDLogsProps, error) {
var opts = &GetTemplateIDLogs{
Limit: 100,
Page: 1,
Order: "desc",
}
if options != nil {
opts = &GetTemplateIDLogs{
ActionWhitelist: options.ActionWhitelist,
ActionBlacklist: options.ActionBlacklist,
}
if options.Limit < 1 {
opts.Limit = 100
}
if options.Page < 1 {
opts.Page = 1
}
if options.Order == "desc" || options.Order == "asc" {
opts.Order = options.Order
} else {
// default to `desc`
opts.Order = "desc"
}
}
v, _ := query.Values(opts)
u := urljoin.UrlJoin(a.apiUrl, SCHEMAS_API, collectionName, strconv.Itoa(templateID), "logs", fmt.Sprintf("?%s", v.Encode()))
var result = &TemplateIDLogsProps{}
if err := a._requester(u, result); err != nil {
return nil, err
}
return result, nil
}