-
Notifications
You must be signed in to change notification settings - Fork 33
/
softlayer_product_package.go
58 lines (46 loc) · 1.96 KB
/
softlayer_product_package.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
package services
import (
"bytes"
"encoding/json"
"fmt"
"strconv"
datatypes "github.com/maximilien/softlayer-go/data_types"
softlayer "github.com/maximilien/softlayer-go/softlayer"
)
type softLayer_Product_Package_Service struct {
client softlayer.Client
}
func NewSoftLayer_Product_Package_Service(client softlayer.Client) *softLayer_Product_Package_Service {
return &softLayer_Product_Package_Service{
client: client,
}
}
func (slpp *softLayer_Product_Package_Service) GetName() string {
return "SoftLayer_Product_Package"
}
func (slpp *softLayer_Product_Package_Service) GetItemPrices(packageId int) ([]datatypes.SoftLayer_Item_Price, error) {
response, err := slpp.client.DoRawHttpRequestWithObjectMask(fmt.Sprintf("%s/%d/getItemPrices.json", slpp.GetName(), packageId), []string{"id", "item.id", "item.description", "item.capacity"}, "GET", new(bytes.Buffer))
if err != nil {
return []datatypes.SoftLayer_Item_Price{}, err
}
itemPrices := []datatypes.SoftLayer_Item_Price{}
err = json.Unmarshal(response, &itemPrices)
if err != nil {
return []datatypes.SoftLayer_Item_Price{}, err
}
return itemPrices, nil
}
func (slpp *softLayer_Product_Package_Service) GetItemPricesBySize(packageId int, size int) ([]datatypes.SoftLayer_Item_Price, error) {
keyName := strconv.Itoa(size) + "_GB_PERFORMANCE_STORAGE_SPACE"
filter := string(`{"itemPrices":{"item":{"keyName":{"operation":"` + keyName + `"}}}}`)
response, err := slpp.client.DoRawHttpRequestWithObjectFilterAndObjectMask(fmt.Sprintf("%s/%d/getItemPrices.json", slpp.GetName(), packageId), []string{"id", "locationGroupId", "item.id", "item.keyName", "item.units", "item.description", "item.capacity"}, fmt.Sprintf(string(filter)), "GET", new(bytes.Buffer))
if err != nil {
return []datatypes.SoftLayer_Item_Price{}, err
}
itemPrices := []datatypes.SoftLayer_Item_Price{}
err = json.Unmarshal(response, &itemPrices)
if err != nil {
return []datatypes.SoftLayer_Item_Price{}, err
}
return itemPrices, nil
}