tiki

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

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

View Source
const DefaultUserAgent = "tiki-cli/0.1.0 (+https://github.com/tamnd/tiki-cli)"

DefaultUserAgent identifies this client to Tiki.

View Source
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 NewClient

func NewClient() *Client

NewClient returns a Client from DefaultConfig.

func NewClientWithConfig

func NewClientWithConfig(cfg Config) *Client

NewClientWithConfig returns a Client built from cfg.

func (*Client) Get

func (c *Client) Get(ctx context.Context, rawURL string) ([]byte, error)

Get fetches rawURL and returns the body bytes, pacing and retrying on transient errors.

func (*Client) GetProduct

func (c *Client) GetProduct(ctx context.Context, id string) (*Product, error)

GetProduct fetches full details for a single product by ID.

func (*Client) ListCategories

func (c *Client) ListCategories(ctx context.Context) ([]*Category, error)

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.

func (*Client) ListReviews

func (c *Client) ListReviews(ctx context.Context, productID string, limit int) ([]*Review, error)

ListReviews fetches customer reviews for a product.

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) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns a Tiki URL or product ID into (type, id).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate returns the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL