forked from ewarehousing-solutions/bigcommerce-api-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
49 lines (44 loc) · 1.28 KB
/
app.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
package bigcommerce
import (
"io"
"net/http"
"time"
)
type HTTPClient interface {
Do(req *http.Request) (res *http.Response, err error)
Get(url string) (res *http.Response, err error)
Post(urstring, bodyType string, body io.Reader) (res *http.Response, err error)
}
// BigCommerce is the BigCommerce API client object for BigCommerce Apps
// holds no client specific information
type App struct {
Hostname string
AppClientID string
AppClientSecret string
HTTPClient HTTPClient
MaxRetries int
ChannelID int
}
// New returns a new BigCommerce API object with the given hostname, client ID, and client secret
// The client ID and secret are the App's client ID and secret from the BigCommerce My Apps dashboard
// The hostname is the domain name of the app from the same page (e.g. app.exampledomain.com)
func NewApp(hostname, appClientID, appClientSecret string) *App {
return &App{
Hostname: hostname,
AppClientID: appClientID,
AppClientSecret: appClientSecret,
MaxRetries: 1,
HTTPClient: &http.Client{
Timeout: time.Second * 10,
},
}
}
func (a *App) NewClient(storeHash, xAuthToken string) *Client {
return &Client{
StoreHash: storeHash,
XAuthToken: xAuthToken,
MaxRetries: 1,
HTTPClient: a.HTTPClient,
ChannelID: 1,
}
}