Skip to content

Commit

Permalink
Added articles, shipping methods and variant services
Browse files Browse the repository at this point in the history
  • Loading branch information
imbue committed Nov 7, 2022
1 parent 509e2f3 commit 38ad86c
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 6 deletions.
90 changes: 90 additions & 0 deletions ewhs/articles.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package ewhs

import (
"encoding/json"
"fmt"
)

type ArticlesService service

type Article struct {
Name string `json:"name,omitempty"`
Variants []ArticleVariant `json:"variants,omitempty"`
}
type ArticleVariant struct {
Name string `json:"name,omitempty"`
ArticleCode string `json:"article_code,omitempty"`
Description string `json:"description,omitempty"`
Ean string `json:"ean,omitempty"`
Sku string `json:"sku,omitempty"`
HsTariffCode string `json:"hs_tariff_code,omitempty"`
Height int `json:"height,omitempty"`
Depth int `json:"depth,omitempty"`
Width int `json:"width,omitempty"`
Weight int `json:"weight,omitempty"`
Expirable bool `json:"expirable,omitempty"`
CountryOfOrigin string `json:"country_of_origin,omitempty"`
UsingSerialNumbers bool `json:"using_serial_numbers,omitempty"`
Value float64 `json:"value,omitempty"`
}

type ArticleListOptions struct {
From string `url:"from,omitempty"`
To string `url:"to,omitempty"`
Limit int `url:"limit,omitempty"`
Direction string `url:"direction,omitempty"`
}

func (as *ArticlesService) List(opts *ArticleListOptions) (list *[]Article, res *Response, err error) {
res, err = as.client.get("wms/articles/", opts)
if err != nil {
return
}

if err = json.Unmarshal(res.content, &list); err != nil {
return
}

return
}

func (as *ArticlesService) Get(articleID string) (article *Article, res *Response, err error) {
res, err = as.client.get(fmt.Sprintf("wms/articles/%s/", articleID), nil)
if err != nil {
return
}

if err = json.Unmarshal(res.content, &article); err != nil {
return
}

return
}

func (as *ArticlesService) Create(art Article) (article *Article, res *Response, err error) {
res, err = as.client.post("wms/articles/", art, nil)

if err != nil {
return
}

if err = json.Unmarshal(res.content, &article); err != nil {
return
}

return
}

func (as *ArticlesService) Update(articleID string, art Article) (article *Article, res *Response, err error) {
res, err = as.client.patch(fmt.Sprintf("wms/articles/%s/", articleID), art, nil)

if err != nil {
return
}

if err = json.Unmarshal(res.content, &article); err != nil {
return
}

return
}
16 changes: 10 additions & 6 deletions ewhs/ewhs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ type Client struct {
config *Config

// Services
Inbounds *InboundsService
Orders *OrdersService
Stock *StockService
Shipments *ShipmentsService
Variants *VariantsService
Webhooks *WebhooksService
Articles *ArticlesService
Inbounds *InboundsService
Orders *OrdersService
Stock *StockService
Shipments *ShipmentsService
ShippingMethods *ShippingMethodsService
Variants *VariantsService
Webhooks *WebhooksService
}

type service struct {
Expand Down Expand Up @@ -158,10 +160,12 @@ func NewClient(baseClient *http.Client, c *Config) Client {
ewhs.common.client = &ewhs

// services for resources
ewhs.Articles = (*ArticlesService)(&ewhs.common)
ewhs.Inbounds = (*InboundsService)(&ewhs.common)
ewhs.Orders = (*OrdersService)(&ewhs.common)
ewhs.Stock = (*StockService)(&ewhs.common)
ewhs.Shipments = (*ShipmentsService)(&ewhs.common)
ewhs.ShippingMethods = (*ShippingMethodsService)(&ewhs.common)
ewhs.Variants = (*VariantsService)(&ewhs.common)
ewhs.Webhooks = (*WebhooksService)(&ewhs.common)

Expand Down
50 changes: 50 additions & 0 deletions ewhs/shippingmethods.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package ewhs

import (
"encoding/json"
"fmt"
)

type ShippingMethodsService service

type ShippingMethod struct {
ID string `json:"id,omitempty"`
Shipper string `json:"shipper,omitempty"`
ShipperCode string `json:"shipper_code,omitempty"`
Code string `json:"code,omitempty"`
Description string `json:"description,omitempty"`
ShippingSoftware string `json:"shipping_software,omitempty"`
}

type ShippingMethodListOptions struct {
From string `url:"from,omitempty"`
To string `url:"to,omitempty"`
Limit int `url:"limit,omitempty"`
Direction string `url:"direction,omitempty"`
}

func (ss *ShippingMethodsService) List(opts *ShippingMethodListOptions) (list *[]ShippingMethod, res *Response, err error) {
res, err = ss.client.get("wms/shippingmethods/", opts)
if err != nil {
return
}

if err = json.Unmarshal(res.content, &list); err != nil {
return
}

return
}

func (ss *ShippingMethodsService) Get(shippingMethodID string) (shippingMethod *ShippingMethod, res *Response, err error) {
res, err = ss.client.get(fmt.Sprintf("wms/shippingmethods/%s/", shippingMethodID), nil)
if err != nil {
return
}

if err = json.Unmarshal(res.content, &shippingMethod); err != nil {
return
}

return
}
66 changes: 66 additions & 0 deletions ewhs/variants.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package ewhs

import (
"encoding/json"
"fmt"
)

type VariantsService service

type Variant struct {
Expand All @@ -19,3 +24,64 @@ type Variant struct {
UsingSerialNumbers bool `json:"using_serial_numbers,omitempty"`
Value float64 `json:"value,omitempty"`
}

type VariantListOptions struct {
From string `url:"from,omitempty"`
To string `url:"to,omitempty"`
Limit int `url:"limit,omitempty"`
Direction string `url:"direction,omitempty"`
}

func (vs *VariantsService) List(opts *VariantListOptions) (list *[]Variant, res *Response, err error) {
res, err = vs.client.get("wms/variants/", opts)
if err != nil {
return
}

if err = json.Unmarshal(res.content, &list); err != nil {
return
}

return
}

func (vs *VariantsService) Get(variantID string) (variant *Variant, res *Response, err error) {
res, err = vs.client.get(fmt.Sprintf("wms/variants/%s/", variantID), nil)
if err != nil {
return
}

if err = json.Unmarshal(res.content, &variant); err != nil {
return
}

return
}

func (vs *VariantsService) Create(ord Order) (order *Order, res *Response, err error) {
res, err = vs.client.post("wms/variants/", ord, nil)

if err != nil {
return
}

if err = json.Unmarshal(res.content, &order); err != nil {
return
}

return
}

func (vs *VariantsService) Update(variantID string, vr Variant) (variant *Variant, res *Response, err error) {
res, err = vs.client.patch(fmt.Sprintf("wms/variants/%s/", variantID), vr, nil)

if err != nil {
return
}

if err = json.Unmarshal(res.content, &variant); err != nil {
return
}

return
}

0 comments on commit 38ad86c

Please sign in to comment.