/
manufacturers.go
94 lines (80 loc) · 2.52 KB
/
manufacturers.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
package skroutz
import (
"encoding/json"
"strconv"
)
// Manufacturers client.
type Manufacturers struct {
*Client
}
// NewManufacturers client.
func NewManufacturers(config *Config) *Manufacturers {
return &Manufacturers{
Client: &Client{
Config: config,
},
}
}
// GetManufacturerOutput request output.
type GetManufacturerOutput struct {
ID float64 `json:"id"`
Name string `json:"name"`
ImageURL string `json:"image_url"`
}
// GetSingleManufacturerOutput request output.
type GetSingleManufacturerOutput struct {
Manufacturer GetManufacturerOutput `json:"manufacturer"`
}
// GetManufacturersCollectionOutput request output.
type GetManufacturersCollectionOutput struct {
Manufacturers []GetSpecificationOutput `json:"manufacturers"`
Meta GetMetaOutput `json:"meta"`
}
// GetManufacturers list manufacturers.
// https://developer.skroutz.gr/api/v3/manufacturer/#list-manufacturers
func (c *Manufacturers) GetManufacturers() (out *GetManufacturersCollectionOutput, err error) {
u := "/manufacturers"
body, err := c.call("GET", u, nil)
if err != nil {
return
}
defer body.Close()
err = json.NewDecoder(body).Decode(&out)
return
}
// GetSingleManufacturer retrieve a single manufacturer.
// https://developer.skroutz.gr/api/v3/manufacturer/#retrieve-a-single-manufacturer
func (c *Manufacturers) GetSingleManufacturer(manufacturerID int) (out *GetSingleManufacturerOutput, err error) {
u := "/manufacturers/" + strconv.Itoa(manufacturerID)
body, err := c.call("GET", u, nil)
if err != nil {
return
}
defer body.Close()
err = json.NewDecoder(body).Decode(&out)
return
}
// GetManufacturersCategories retrieve a manufacturer's categories.
// https://developer.skroutz.gr/api/v3/manufacturer/#retrieve-a-manufacturers-categories
func (c *Manufacturers) GetManufacturersCategories(manufacturerID int) (out *GetCategoriesCollectionOutput, err error) {
u := "/manufacturers/" + strconv.Itoa(manufacturerID) + "/categories"
body, err := c.call("GET", u, nil)
if err != nil {
return
}
defer body.Close()
err = json.NewDecoder(body).Decode(&out)
return
}
// GetManufacturersSKUS retrieve a manufacturer's SKUs.
// https://developer.skroutz.gr/api/v3/manufacturer/#retrieve-a-manufacturers-skus
func (c *Manufacturers) GetManufacturersSKUS(manufacturerID int) (out *GetSKUSCollectionOutput, err error) {
u := "/manufacturers/" + strconv.Itoa(manufacturerID) + "/skus"
body, err := c.call("GET", u, nil)
if err != nil {
return
}
defer body.Close()
err = json.NewDecoder(body).Decode(&out)
return
}