-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata.go
59 lines (47 loc) · 1.1 KB
/
metadata.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
package opensea
import (
"encoding/json"
"net/http"
)
type Item struct {
Description string `json:"description,omitempty"`
ExternalURL string `json:"external_url,omitempty"`
Image string `json:"image,omitempty"`
Name string `json:"name,omitempty"`
Attributes []Attribute `json:"attributes,omitempty"`
}
type Attribute struct {
Type string `json:"trait_type,omitempty"`
DisplayType string `json:"display_type,omitempty"`
Value interface{} `json:"value"`
MaxValue float64 `json:"max_value,omitempty"`
}
type API struct {
client *http.Client
}
func New(client *http.Client) *API {
if client == nil {
client = http.DefaultClient
}
return &API{
client: client,
}
}
func (a *API) Get(tokenURI string) (*Item, error) {
req, err := http.NewRequest(http.MethodGet, tokenURI, nil)
if err != nil {
return nil, err
}
res, err := a.client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
dec := json.NewDecoder(res.Body)
var item Item
err = dec.Decode(&item)
if err != nil {
return nil, err
}
return &item, nil
}