Documentation
¶
Overview ¶
Package dummyjson is the library behind the dummyjson command line: the HTTP client, request shaping, and typed data models for the DummyJSON API (https://dummyjson.com/).
No API key is required. The Client paces requests, sets a real User-Agent, and retries transient failures (429 and 5xx).
Index ¶
- Constants
- type Category
- type Client
- func (c *Client) ListCategories(ctx context.Context) ([]Category, error)
- func (c *Client) ListPosts(ctx context.Context, limit int) ([]Post, int, error)
- func (c *Client) ListProducts(ctx context.Context, category string, limit int) ([]Product, int, error)
- func (c *Client) ListQuotes(ctx context.Context, limit int) ([]Quote, int, error)
- func (c *Client) ListRecipes(ctx context.Context, limit int) ([]Recipe, int, error)
- func (c *Client) ListUsers(ctx context.Context, limit int) ([]User, int, error)
- func (c *Client) SearchProducts(ctx context.Context, q string, limit int) ([]Product, int, error)
- type Config
- type Domain
- type Post
- type Product
- type Quote
- type Recipe
- type User
Constants ¶
const BaseURL = "https://" + Host
BaseURL is the root every API request is built from.
const DefaultUserAgent = "dummyjson-cli/0.1 (tamnd87@gmail.com)"
DefaultUserAgent identifies the client to DummyJSON.
const Host = "dummyjson.com"
Host is the API hostname.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the DummyJSON API.
func (*Client) ListCategories ¶ added in v0.1.1
ListCategories fetches the list of product categories.
func (*Client) ListProducts ¶ added in v0.1.1
func (c *Client) ListProducts(ctx context.Context, category string, limit int) ([]Product, int, error)
ListProducts fetches products, optionally filtered by category.
func (*Client) ListQuotes ¶ added in v0.1.1
ListQuotes fetches a page of quotes.
func (*Client) ListRecipes ¶ added in v0.1.1
ListRecipes fetches a page of recipes.
type Config ¶ added in v0.1.1
type Config struct {
BaseURL string
UserAgent string
Rate time.Duration
Timeout time.Duration
Retries int
}
Config holds all tunable parameters for the Client.
func DefaultConfig ¶ added in v0.1.1
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults.
type Domain ¶
type Domain struct{}
Domain is the dummyjson driver.
func (Domain) Classify ¶
Classify turns an identifier into (type, id). Numeric input -> ("product", input); otherwise -> ("query", input).
func (Domain) Info ¶
func (Domain) Info() kit.DomainInfo
Info describes the scheme, hostnames, and binary identity.
type Post ¶ added in v0.1.1
type Post struct {
ID int `kit:"id" json:"id"`
Title string `json:"title"`
Tags string `json:"tags"`
Views int `json:"views"`
Likes int `json:"likes"`
UserID int `json:"user_id"`
}
Post is a DummyJSON post record.
type Product ¶ added in v0.1.1
type Product struct {
ID int `kit:"id" json:"id"`
Title string `json:"title"`
Category string `json:"category"`
Brand string `json:"brand"`
Price float64 `json:"price"`
Rating float64 `json:"rating"`
Stock int `json:"stock"`
}
Product is a DummyJSON product record.
type Quote ¶ added in v0.1.1
type Quote struct {
ID int `kit:"id" json:"id"`
Quote string `json:"quote"`
Author string `json:"author"`
}
Quote is a DummyJSON quote record.
type Recipe ¶ added in v0.1.1
type Recipe struct {
ID int `kit:"id" json:"id"`
Name string `json:"name"`
Cuisine string `json:"cuisine"`
Difficulty string `json:"difficulty"`
PrepTime int `json:"prep_time"`
CookTime int `json:"cook_time"`
Servings int `json:"servings"`
Calories int `json:"calories"`
}
Recipe is a DummyJSON recipe record.
type User ¶ added in v0.1.1
type User struct {
ID int `kit:"id" json:"id"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Email string `json:"email"`
Age int `json:"age"`
Gender string `json:"gender"`
Username string `json:"username"`
City string `json:"city"`
Country string `json:"country"`
}
User is a DummyJSON user record.