/
prestaShop.go
74 lines (63 loc) · 1.62 KB
/
prestaShop.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
package prestashopApi
import (
"crypto/tls"
"net/http"
"net/url"
"time"
)
var (
apiVersion = "1.7.8.8"
)
const (
UserAgent = "prestashopApi/1.0.0"
defaultHttpTimeout = 30
defaultApiPathPrefix = "/api"
defaultVersion = "1.7.8.8"
)
type PrestaShop struct {
AppName string
BaseURL *url.URL
Resource ResourceService
Product ProductService
ProductVariant ProductVariantService
ProductOption ProductOptionService
ProductOptionValue ProductOptionValueService
ProductStock ProductStockAvailableService
ProductSupplier ProductSupplierService
Image ImageService
}
func NewPrestaShop(appName, urlStr, apiKey string) *PrestaShop {
baseURL, err := url.Parse(urlStr)
if err != nil {
panic(err)
}
ps := PrestaShop{
AppName: appName,
BaseURL: baseURL,
}
client := ps.newClient(apiKey)
ps.Resource = newResourceService(client)
ps.Product = newProductService(client)
ps.ProductVariant = newProductVariantService(client)
ps.ProductOption = newProductOptionService(client)
ps.ProductOptionValue = newProductOptionValueService(client)
ps.ProductStock = newProductStockAvailableService(client)
ps.ProductSupplier = newProductSupplierService(client)
ps.Image = newImageService(client)
return &ps
}
func (ps *PrestaShop) newClient(apiKey string) *Client {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := Client{
version: apiVersion,
baseURL: ps.BaseURL,
apiKey: apiKey,
client: &http.Client{
Transport: tr,
Timeout: time.Second * defaultHttpTimeout,
},
}
return &client
}