-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct_image_gallery.go
68 lines (55 loc) · 1.89 KB
/
product_image_gallery.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
package ecwid
import (
"bufio"
"fmt"
"io"
"os"
)
// ProductImageGalleryUpload uploads image to product gallery from stream
func (c *Client) ProductImageGalleryUpload(productID ID, image io.Reader, imageTitle string) (ID, error) {
params := make(map[string]string)
if len(imageTitle) > 0 {
params["fileName"] = imageTitle
}
response, err := c.R().
SetQueryParams(params).
SetHeader("Content-Type", "image/jpeg").
SetBody(image).
Post(fmt.Sprintf("/products/%d/gallery", productID))
return responseAdd(response, err)
}
// ProductImageGalleryUploadFile uploads image to product gallery from local file
func (c *Client) ProductImageGalleryUploadFile(productID ID, filename string, imageTitle string) (ID, error) {
file, err := os.Open(filename)
if err != nil {
return 0, err
}
defer file.Close()
return c.ProductImageGalleryUpload(productID, bufio.NewReader(file), imageTitle)
}
// ProductImageGalleryUploadByURL uploads image to product gallery from external url
func (c *Client) ProductImageGalleryUploadByURL(productID ID, imageURL, imageTitle string) (ID, error) {
params := map[string]string{
"externalUrl": imageURL,
}
if len(imageTitle) > 0 {
params["fileName"] = imageTitle
}
response, err := c.R().
SetQueryParams(params).
Post(fmt.Sprintf("/products/%d/gallery", productID))
return responseAdd(response, err)
}
// ProductImageGalleryDelete deletes image from product gallery by image id
func (c *Client) ProductImageGalleryDelete(productID, fieldID ID) error {
response, err := c.R().
Delete(fmt.Sprintf("/products/%d/gallery/%d", productID, fieldID))
_, err = responseDelete(response, err)
return err
}
// ProductImageGalleryDeleteAll deletes all images from product gallery
func (c *Client) ProductImageGalleryDeleteAll(productID ID) (uint, error) {
response, err := c.R().
Delete(fmt.Sprintf("/products/%d/gallery", productID))
return responseDelete(response, err)
}