diff --git a/example_get_order.go b/example_get_order.go new file mode 100644 index 0000000..200011a --- /dev/null +++ b/example_get_order.go @@ -0,0 +1,33 @@ +package main + +import ( + "encoding/json" + "flag" + "fmt" + "log" + + "github.com/debyltech/go-snipcart/snipcart" +) + +func main() { + snipcartApiKey := flag.String("key", "", "Snipcart API Key") + flag.Parse() + + if *snipcartApiKey == "" { + log.Fatal("missing -key flag") + } + + snipcartProvider := snipcart.NewSnipcartProvider(*snipcartApiKey) + + response, err := snipcartProvider.GetOrder("b35990df-c0ca-4014-94de-1caa7bd7bb51") + if err != nil { + log.Fatal(err) + } + + byteResponse, err := json.Marshal(response) + if err != nil { + log.Fatal(err) + } + + fmt.Println(string(byteResponse)) +} diff --git a/example_update_order.go b/example_update_order.go new file mode 100644 index 0000000..48ce018 --- /dev/null +++ b/example_update_order.go @@ -0,0 +1,32 @@ +package main + +import ( + "flag" + "log" + + "github.com/debyltech/go-snipcart/snipcart" +) + +func main() { + snipcartApiKey := flag.String("key", "", "Snipcart API Key") + flag.Parse() + + if *snipcartApiKey == "" { + log.Fatal("missing -key flag") + } + + snipcartProvider := snipcart.NewSnipcartProvider(*snipcartApiKey) + + updateOrder := snipcart.SnipcartOrderUpdate{ + Status: snipcart.Delivered, + } + + response, err := snipcartProvider.UpdateOrder("b35990df-c0ca-4014-94de-1caa7bd7bb51", &updateOrder) + if err != nil { + log.Fatal(err) + } + + for k, v := range response.Items { + log.Printf("%v: %v\n", k, v) + } +} diff --git a/snipcart/snipcart.go b/snipcart/snipcart.go index e7846bb..3546a54 100644 --- a/snipcart/snipcart.go +++ b/snipcart/snipcart.go @@ -26,18 +26,23 @@ type SnipcartProvider struct { Limit int } +type SnipcartCustomField struct { + Name string `json:"name"` + Value string `json:"value"` +} + type SnipcartItem struct { - UUID string `json:"uniqueId"` - ID string `json:"id"` - Name string `json:"name"` - Quantity int `json:"quantity"` - TotalWeight float64 `json:"totalWeight,omitempty"` - CustomFieldsJSON string `json:"customFieldsJson"` - Length float64 `json:"length,omitempty"` - Width float64 `json:"width,omitempty"` - Height float64 `json:"height,omitempty"` - Weight float64 `json:"weight,omitempty"` - Shippable bool `json:"shippable,omitempty"` + UUID string `json:"uniqueId"` + ID string `json:"id"` + Name string `json:"name"` + Quantity int `json:"quantity"` + TotalWeight float64 `json:"totalWeight,omitempty"` + CustomFields []SnipcartCustomField `json:"customFields"` + Length float64 `json:"length,omitempty"` + Width float64 `json:"width,omitempty"` + Height float64 `json:"height,omitempty"` + Weight float64 `json:"weight,omitempty"` + Shippable bool `json:"shippable,omitempty"` } type SnipcartOrder struct {