-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added articles, shipping methods and variant services
- Loading branch information
Showing
4 changed files
with
216 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters