Documentation
¶
Overview ¶
Package lazada provides the client for interacting with the Lazada open platform
Index ¶
- Constants
- Variables
- func SliceString(in []string) string
- type Attributes
- type AuthService
- type Brand
- type CategoryAttributes
- type CategoryOptions
- type CategoryTree
- type Client
- func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*LazadaResponse, error)
- func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)
- func (c *Client) NewTokenClient(token string) *Client
- func (c *Client) SetRegion(region Region)
- func (c *Client) Signature(api string, val url.Values, body io.Reader) string
- type CreateProductResponse
- type ErrorDetails
- type ErrorResponse
- type GetProduct
- type GetProductResponse
- type ImageReq
- type ImageResponse
- type Images
- type LazadaResponse
- type ListOptions
- type Payload
- type Product
- type ProductRequest
- type ProductSKU
- type ProductService
- func (p *ProductService) Brands(ctx context.Context, opts *ListOptions) ([]*Brand, error)
- func (p *ProductService) CategoryAttributes(ctx context.Context, id int) ([]*CategoryAttributes, error)
- func (p *ProductService) CategoryTree(ctx context.Context) ([]*CategoryTree, error)
- func (p *ProductService) Create(ctx context.Context, pReq *Product) (*CreateProductResponse, error)
- func (p *ProductService) Get(ctx context.Context, opts *SearchOptions) (*GetProductResponse, error)
- func (p *ProductService) MigrateImage(ctx context.Context, imgURL string) (*ImageResponse, error)
- func (p *ProductService) Update(ctx context.Context, pReq *Product) error
- type Region
- type SKUItem
- type SearchOptions
- type Sku
- type StringMap
- type Token
Examples ¶
Constants ¶
const ( SriLanka Region = "lk" Philippines = "ph" Bangladesh = "bd" Thailand = "th" Vietnam = "vn" Pakistan = "pk" Singapore = "sg" Nepal = "np" Indonesia = "id" Myanmar = "mm" Malaysia = "my" )
Variables ¶
var DefaultListOptions = ListOptions{
Limit: 100,
Offset: 0,
}
Default list options
Functions ¶
func SliceString ¶
SliceString takes in a slice of strings and returns a string used in query parameters for the open platform
Types ¶
type Attributes ¶
type AuthService ¶
type AuthService service
The Auth Service deals with doing the OAuth flow and exchanging codes for tokens. It also lets you refresh tokens in order to get new credentials.
func (*AuthService) AuthURL ¶
func (a *AuthService) AuthURL(redirect, state string) string
AuthURL returns the URL you should use to start the OAuth flow It takes in the URL that the user should be returned to as redirect and a state variable which should be a random string
type Brand ¶
type Brand struct { Name string `json:"name"` BrandID int `json:"brand_id"` GlobalIdentifier string `json:"global_identifier"` }
A brand object returned from the open platform
type CategoryAttributes ¶
type CategoryOptions ¶
type CategoryOptions struct {
Name string
}
type CategoryTree ¶
type CategoryTree struct { CategoryID int `json:"category_id"` Children []*CategoryTree `json:"children"` Var bool `json:"var"` Name string `json:"name"` Leaf bool `json:"leaf"` }
type Client ¶
type Client struct { BaseURL *url.URL // The product service used for making API calls related to products Products *ProductService // The auth service used for making API calls related to authorization or OAuth Auth *AuthService // contains filtered or unexported fields }
func NewClient ¶
NewClient takes in the application key, secret, and Lazada region and returns a client.
func (*Client) Do ¶
Do runs a http.Request adding in the various required query parameters if they weren't set by the body already. It will marshal the data returned into the provided interface.
func (*Client) NewRequest ¶
NewRequest returns an http request conforming to the open platform Any body supplied will be encoded to XML
func (*Client) NewTokenClient ¶
NewTokenClient takes a client access token and returns a copy of the client with the token set.
type CreateProductResponse ¶
type ErrorDetails ¶
type ErrorResponse ¶
type ErrorResponse struct { Response *http.Response Code string `json:"code"` Type string `json:"type"` Message string `json:"message"` RequestID string `json:"request_id"` Detail []*ErrorDetails `json:"detail,omitempty"` }
Error response is used to return as much data as possible to the calling application to help with dealing with any API issues.
func (*ErrorResponse) Error ¶
func (r *ErrorResponse) Error() string
type GetProduct ¶
type GetProduct struct { ItemID int `json:"item_id"` PrimaryCategory int `json:"primary_category"` Attributes map[string]string `json:"attributes"` SKUs []*ProductSKU `json:"skus"` }
type GetProductResponse ¶
type GetProductResponse struct { TotalProducts int `json:"total_products"` Products []*GetProduct `json:"products"` }
type ImageResponse ¶
type LazadaResponse ¶
type LazadaResponse struct { Code string `json:"code"` Data json.RawMessage `json:"data"` RequestID string `json:"request_id"` Type string `json:"type"` Message string `json:"message"` Detail []*ErrorDetails `json:"detail"` }
func CheckResponse ¶
func CheckResponse(r *http.Response) (*LazadaResponse, error)
CheckResponse makes sure we didn't receive an error from the platform and if we did it returns the error properly.
type ListOptions ¶
type ListOptions struct { // Used to paginate through results Offset int `url:"offset"` // Limit how many items are returned Limit int `url:"limit"` }
ListOptions used for various API calls
type Product ¶
type Product struct { XMLName xml.Name `xml:"Product,omitempty"` Attributes *Attributes `xml:"Attributes,omitempty"` PrimaryCategory string `xml:"PrimaryCategory,omitempty"` Skus []*Sku `xml:"Skus>Sku,omitempty"` }
type ProductRequest ¶
type ProductSKU ¶
type ProductSKU struct { Status string `json:"Status"` Quantity int `json:"quantity"` ProductWeight string `json:"product_weight"` Images []string `json:"Images"` SellerSKU string `json:"SellerSku"` ShopSKU string `json:"ShopSku"` URL string `json:"Url"` PackageWidth string `json:"package_width"` SpecialToTime string `json:"special_to_time"` SpecialFromTime string `json:"special_from_time"` PackageHeight string `json:"package_height"` SpecialPrice decimal.Decimal `json:"special_price"` Price decimal.Decimal `json:"price"` PackageLength string `json:"package_length"` PackageWeight string `json:"package_weight"` Available int `json:"Available"` SkuID int `json:"SkuId"` SpecialToDate string `json:"special_to_date"` }
type ProductService ¶
type ProductService service
The Product Service deals with any methods under the "Product" category of the open platform
func (*ProductService) Brands ¶
func (p *ProductService) Brands(ctx context.Context, opts *ListOptions) ([]*Brand, error)
Brands returns a list of brands in the region set If opts is nil then the default options are used
func (*ProductService) CategoryAttributes ¶
func (p *ProductService) CategoryAttributes(ctx context.Context, id int) ([]*CategoryAttributes, error)
CategoryAttributes returns all the attributes related to the category id provided
func (*ProductService) CategoryTree ¶
func (p *ProductService) CategoryTree(ctx context.Context) ([]*CategoryTree, error)
CategoryTree returns all the categories available in the region set
func (*ProductService) Create ¶
func (p *ProductService) Create(ctx context.Context, pReq *Product) (*CreateProductResponse, error)
Create lets you create a new product on the open platform.
Requires a client access token
Example ¶
client := NewClient("12345", "example", Singapore) userClient := client.NewTokenClient("usertoken") // Set the a token obtained through oauth userClient.SetRegion(Malaysia) // Change the region to Malaysia product := &Product{ PrimaryCategory: "10001958", Attributes: &Attributes{ Attrs: StringMap{ "name": "test product creation", "short_description": "test product highlights", "description": "test product description", "brand": "Kid Basix", "model": "test model", "recommended_gender": "Men", "material": "Cotton", "waterproof": "waterproof", "warranty_type": "Local (Singapore) manufacturer warranty", "warranty": "1 month", "Hazmat": "Battery, Flammable", }}, Skus: []*Sku{ { SellerSku: "test-product-creation-for-api", Images: &Images{Image: []string{"https://sg-live.slatic.net/original/b731a8098df7d606ab2e56efc650afcb.jpg"}}, SkuAttrs: StringMap{ "quantity": "1", "color_family": "Black", "special_price": "0.0", "price": "23.0", "package_length": "1", "package_weight": "1", "package_content": "test whats in the box", "package_width": "1", "package_height": "1", }, }, }, } userClient.Products.Create(context.Background(), product)
Output:
func (*ProductService) Get ¶
func (p *ProductService) Get(ctx context.Context, opts *SearchOptions) (*GetProductResponse, error)
Get lets you retrieve all products in a specific region
func (*ProductService) MigrateImage ¶
func (p *ProductService) MigrateImage(ctx context.Context, imgURL string) (*ImageResponse, error)
MigrateImage lets you move any publicly accessible image into the Lazada platform Requires a client access token
type SearchOptions ¶
type SearchOptions struct { // Filter the product status Filter string `url:"filter"` // Search for products with this name or seller sku Search *string `url:"search,omitempty"` // Set to "1" to get more stock information Options *string `url:"options,omitempty"` // Return only products that have this seller sku SKUSellerList *string `url:"sku_seller_list,omitempty"` // Offset the results by Offset int `url:"offset"` // Limit the amount of returned results Limit int `url:"limit"` }
type StringMap ¶
func (StringMap) MarshalXML ¶
StringMap marshals a map into XML.
type Token ¶
type Token struct { AccountID string `json:"account_id"` Account string `json:"account"` Country string `json:"country"` AccountPlatform string `json:"account_platform"` AccessToken string `json:"access_token"` RefreshToken string `json:"refresh_token"` ExpiresIn int `json:"expires_in"` RefreshExpiresIn int `json:"refresh_expires_in"` // contains filtered or unexported fields }
Token is the data returned when doing an Oauth Flow through the open platform
func (*Token) RefreshExpiresAt ¶
RefreshExpiresAt tells you the point in time when the refresh token will expire