-
Notifications
You must be signed in to change notification settings - Fork 3
/
Product.go
85 lines (65 loc) · 2.11 KB
/
Product.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
package HologramGo
import (
"fmt"
"os"
"strconv"
)
// Product implements the Product type returned in the response.
type Product map[string]interface{}
// Products is just a list of Product(s).
type Products []interface{}
// GetProducts returns product details.
func GetProducts() Products {
req := createGetRequest("/products/")
resp, err := sendRequest(req)
if err != nil {
fmt.Printf("Could not send request: %v\n", err)
os.Exit(1)
}
return unmarshallIntoArrayObject(resp)
}
// GetProduct returns product details response.
func GetProduct(id int) Product {
req := createGetRequest("/products/" + strconv.Itoa(id))
resp, err := sendRequest(req)
if err != nil {
fmt.Printf("Could not send request: %v\n", err)
os.Exit(1)
}
return unmarshallIntoObject(resp)
}
///////////////////////////////////////////////////
// GENERIC PRODUCT GETTER FUNCTIONS
///////////////////////////////////////////////////
// GetProductId returns the id of the product.
func (product Product) GetProductId() float64 {
return product["id"].(float64)
}
// GetProductSku returns the sku of the product.
func (product Product) GetProductSku() string {
return product["sku"].(string)
}
// GetProductName returns the name of the product.
func (product Product) GetProductName() string {
return product["name"].(string)
}
// GetProductDescription returns the description of the product.
func (product Product) GetProductDescription() string {
return product["description"].(string)
}
// GetProductPrice returns the price of the product.
func (product Product) GetProductPrice() string {
return product["price"].(string)
}
// GetProductImageUrl returns the sku of the product.
func (product Product) GetProductImageUrl() string {
return product["imageurl"].(string)
}
// GetProductInvoiceDescription returns the invoice description of the product.
func (product Product) GetProductInvoiceDescription() string {
return product["invoice_description"].(string)
}
// GetProductPreorderDetails returns the invoice description of the product.
func (product Product) GetProductPreorderDetails() string {
return product["preorder_details"].(string)
}