-
Notifications
You must be signed in to change notification settings - Fork 0
/
selling_partner.go
70 lines (61 loc) · 1.67 KB
/
selling_partner.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
package sp_api
import (
"net/http"
"github.com/fond-of-vertigo/amazon-sp-api/apis/feeds"
"github.com/fond-of-vertigo/amazon-sp-api/apis/finances"
"github.com/fond-of-vertigo/amazon-sp-api/apis/orders"
"github.com/fond-of-vertigo/amazon-sp-api/apis/reports"
"github.com/fond-of-vertigo/amazon-sp-api/apis/tokens"
"github.com/fond-of-vertigo/amazon-sp-api/constants"
"github.com/fond-of-vertigo/amazon-sp-api/httpx"
"github.com/fond-of-vertigo/logger"
)
type Config struct {
ClientID string
ClientSecret string
RefreshToken string
Endpoint constants.Endpoint
Log logger.Logger
HTTPClient *http.Client
}
type Client struct {
httpClient *httpx.Client
FinancesAPI *finances.API
FeedsAPI *feeds.API
OrdersAPI *orders.API
ReportsAPI *reports.API
TokenAPI *tokens.API
}
// Close stops the TokenUpdater thread
func (s *Client) Close() {
s.httpClient.Close()
}
func NewClient(config Config) (*Client, error) {
hc := config.HTTPClient
if config.HTTPClient == nil {
hc = http.DefaultClient
}
clientConfig := httpx.ClientConfig{
HTTPClient: hc,
Endpoint: config.Endpoint,
TokenUpdaterConfig: httpx.TokenUpdaterConfig{
RefreshToken: config.RefreshToken,
ClientID: config.ClientID,
ClientSecret: config.ClientSecret,
HTTPClient: hc,
Logger: config.Log,
},
}
httpxClient, err := httpx.NewClient(clientConfig)
if err != nil {
return nil, err
}
return &Client{
httpClient: httpxClient,
FinancesAPI: finances.NewAPI(httpxClient),
FeedsAPI: feeds.NewAPI(httpxClient),
OrdersAPI: orders.NewAPI(httpxClient),
ReportsAPI: reports.NewAPI(httpxClient),
TokenAPI: tokens.NewAPI(httpxClient),
}, nil
}