-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproducts.go
63 lines (55 loc) · 2.07 KB
/
products.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
package vgmdb
import (
"fmt"
"net/http"
)
// ProductsService handles communication with the products related methods
// of the VGMdb API.
type ProductsService struct {
client *Client
}
// Product represents a VGMdb product.
//
// VGMdb API schema: /~https://github.com/hufman/vgmdb/blob/80a491cb2eae0dd8da2c9a81de4777a812e1bf10/schema/product.json#L21
type Product struct {
Link string `json:"link"`
Type ProductType `json:"type"`
Name string `json:"name"`
NameReal string `json:"name_real,omitempty"`
Description string `json:"description"`
ReleaseDate string `json:"release_date,omitempty"`
Meta *Meta `json:"meta"`
Albums []*ProductAlbum `json:"albums"`
Franchises []*NamedItem `json:"franchises,omitempty"`
Superproduct *NamedItem `json:"superproduct,omitempty"`
Superproducts [][]*ProductTitle `json:"superproducts,omitempty"`
Titles []*ProductTitle `json:"titles,omitempty"`
Organizations []*NamedItem `json:"organizations,omitempty"`
VgmdbLink string `json:"vgmdb_link"`
Websites *ItemWebsites `json:"websites"`
}
// ProductTitle represents a sub product in a franchise.
//
// VGMdb API schema: /~https://github.com/hufman/vgmdb/blob/80a491cb2eae0dd8da2c9a81de4777a812e1bf10/schema/product.json#L8
type ProductTitle struct {
Date string `json:"date,omitempty"`
Link string `json:"link,omitempty"`
Names Names `json:"names"`
Type ProductType `json:"type,omitempty"`
}
// GetProduct gets a specific product, identified by product ID.
//
// VGMdb API docs: /~https://github.com/hufman/vgmdb/blob/80a491cb2eae0dd8da2c9a81de4777a812e1bf10/raml/api.raml#L171
func (s *ProductsService) GetProduct(id int) (*Product, *http.Response, error) {
u := fmt.Sprintf("product/%d", id)
req, err := s.client.NewRequest(http.MethodGet, u)
if err != nil {
return nil, nil, err
}
p := new(Product)
resp, err := s.client.Do(req, p)
if err != nil {
return nil, resp, err
}
return p, resp, err
}