Documentation
¶
Overview ¶
Package tiki is the library behind the tiki command line: the HTTP client, JSON API parsing, and typed data models for Tiki (tiki.vn), Vietnam's leading e-commerce marketplace.
Tiki exposes a public JSON REST API for product listings, product details, customer reviews, and the category tree. No API key is required. Product URLs follow the pattern: https://tiki.vn/{url_key}/p{id}.html.
Index ¶
- Constants
- type Category
- type Client
- func (c *Client) Get(ctx context.Context, rawURL string) ([]byte, error)
- func (c *Client) GetProduct(ctx context.Context, id string) (*Product, error)
- func (c *Client) ListCategories(ctx context.Context) ([]*Category, error)
- func (c *Client) ListProducts(ctx context.Context, categoryID string, sort string, limit int) ([]*Product, error)
- func (c *Client) ListReviews(ctx context.Context, productID string, limit int) ([]*Review, error)
- type Config
- type Domain
- type Product
- type Review
Constants ¶
const DefaultUserAgent = "tiki-cli/0.1.0 (+https://github.com/tamnd/tiki-cli)"
DefaultUserAgent identifies this client to Tiki.
const Host = "tiki.vn"
Host is the canonical site hostname.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Category ¶
type Category struct {
ID string `json:"id" kit:"id" table:"id"`
Name string `json:"name" table:"name"`
URLKey string `json:"url_key" table:"url_key"`
URL string `json:"url" table:"url,url"`
}
Category is one node in the Tiki category tree.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the Tiki API over HTTP.
func NewClientWithConfig ¶
NewClientWithConfig returns a Client built from cfg.
func (*Client) Get ¶
Get fetches rawURL and returns the body bytes, pacing and retrying on transient errors.
func (*Client) GetProduct ¶
GetProduct fetches full details for a single product by ID.
func (*Client) ListCategories ¶
ListCategories fetches the top-level Tiki category tree.
func (*Client) ListProducts ¶
func (c *Client) ListProducts(ctx context.Context, categoryID string, sort string, limit int) ([]*Product, error)
ListProducts fetches products for a category, sorted by the given field. sort is one of "top_seller", "newest", "price_asc", "price_desc". Empty uses default.
type Config ¶
type Config struct {
BaseURL string
APIBase string
Rate time.Duration
Retries int
Timeout time.Duration
UserAgent string
}
Config holds the tunable knobs for the HTTP client.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns sensible production defaults.
type Domain ¶
type Domain struct{}
Domain is the Tiki driver.
func (Domain) Info ¶
func (Domain) Info() kit.DomainInfo
type Product ¶
type Product struct {
ID string `json:"id" kit:"id" table:"id"`
SKU string `json:"sku,omitempty" table:"sku"`
Name string `json:"name" table:"name"`
URL string `json:"url,omitempty" table:"url,url"`
ShortDesc string `json:"short_description,omitempty" table:"-"`
Price float64 `json:"price" table:"price"`
ListPrice float64 `json:"list_price,omitempty" table:"list_price"`
DiscountRate int `json:"discount_rate,omitempty" table:"discount_rate"`
BrandName string `json:"brand_name,omitempty" table:"brand_name"`
SellerName string `json:"seller_name,omitempty" table:"seller_name"`
IsOfficialStore bool `json:"is_official_store,omitempty" table:"official_store"`
IsTikiTrading bool `json:"is_tiki_trading,omitempty" table:"tiki_trading"`
RatingAverage float64 `json:"rating_average,omitempty" table:"rating"`
ReviewCount int `json:"review_count,omitempty" table:"reviews"`
SoldCount int64 `json:"sold_count,omitempty" table:"sold"`
FulfillmentType string `json:"fulfillment_type,omitempty" table:"fulfillment"`
WarrantyPeriod string `json:"warranty_period,omitempty" table:"warranty"`
FetchedAt string `json:"fetched_at,omitempty" table:"fetched_at"`
}
Product is one Tiki product from the API.
type Review ¶
type Review struct {
ID string `json:"id" kit:"id" table:"id"`
ProductID string `json:"product_id" table:"product_id"`
Rating int `json:"rating" table:"rating"`
Title string `json:"title,omitempty" table:"title"`
Content string `json:"content,omitempty" table:"-"`
CustomerName string `json:"customer_name,omitempty" table:"customer_name"`
CreatedAt string `json:"created_at,omitempty" table:"created_at"`
HelpfulCount int `json:"helpful_count,omitempty" table:"helpful"`
FetchedAt string `json:"fetched_at,omitempty" table:"fetched_at"`
}
Review is one customer review for a Tiki product.