Documentation ¶
Overview ¶
Package psref implements an (unofficial) Lenovo PSREF API client.
Index ¶
- Variables
- type Book
- type Client
- func (c *Client) Books(ctx context.Context) ([]Book, error)
- func (c *Client) ModelByCode(ctx context.Context, code ModelCode) (*Model, error)
- func (c *Client) ModelByID(ctx context.Context, id PID, code ModelCode) (*Model, error)
- func (c *Client) ProductByID(ctx context.Context, id PID) (*Product, error)
- func (c *Client) ProductByModelCode(ctx context.Context, code ModelCode) (*Product, error)
- func (c *Client) Products(ctx context.Context) ([]ProductType, error)
- func (c *Client) Search(ctx context.Context, qu string) ([]SearchResult, error)
- func (c *Client) Updates(ctx context.Context) (*Updates, error)
- func (c *Client) WithdrawnProducts(ctx context.Context) ([]ProductType, error)
- type ClientOption
- type Date
- type Documentation
- type KeyValue
- type Model
- type ModelCode
- type ModelInfo
- type PID
- type Product
- type ProductLine
- type ProductShort
- type ProductType
- type SearchResult
- type Series
- type UpdatedProduct
- type Updates
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is returned when lookup leads to no results. ErrNotFound = errors.New("not found") )
Functions ¶
This section is empty.
Types ¶
type Book ¶
type Book struct { Title string `json:"BookTitle"` URL string `json:"BookLink"` Geo string `json:"Geo"` Remark string `json:"Remark"` }
Book is a reference to a resource for users to read.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client for PSREF API.
Example ¶
package main import ( "context" "fmt" "github.com/dennwc/psref" ) func main() { c := psref.NewClient() ctx := context.Background() // https://psref.lenovo.com/Detail/ThinkPad/ThinkPad_X1_Carbon_Gen_10?M=21CB000AUS const code = "21CB000AUS" m, err := c.ModelByCode(ctx, code) if err != nil { panic(err) } fmt.Printf("Product %d (%s):\n\tCPU: %s\n\tRAM: %s\n\tGPU: %s\n\tDisk: %s\n", m.ID, m.Key, m.DetailByName("Processor"), m.DetailByName("Memory"), m.DetailByName("Graphics"), m.DetailByName("Storage"), ) }
Output: Product 1972 (ThinkPad_X1_Carbon_Gen_10): CPU: Intel Core i5-1240P, 12C (4P + 8E) / 16T, P-core 1.7 / 4.4GHz, E-core 1.2 / 3.3GHz, 12MB RAM: 16GB Soldered LPDDR5-5200 GPU: Integrated Intel Iris Xe Graphics Disk: 256GB SSD M.2 2280 PCIe 4.0x4 NVMe Opal2
func NewClient ¶
func NewClient(opts ...ClientOption) *Client
NewClient creates a client with specified options.
By default, the client will retry requests a few times and will use a conservative rate limit. See WithRetry and WithRate to adjust these settings.
func (*Client) ModelByCode ¶
ModelByCode returns information about the given product model.
This method uses the search API, which might be considerably slower. Use ModelByID instead.
func (*Client) ProductByID ¶
ProductByID returns an information about the product, given its numeric PSREF ID. Description of the product includes a list of all available product models.
func (*Client) ProductByModelCode ¶
ProductByModelCode returns an information about the product, given its alphanumeric code of one of the models.
This method uses the search API, which might be considerably slower. Use ProductByID instead.
func (*Client) Products ¶
func (c *Client) Products(ctx context.Context) ([]ProductType, error)
Products lists all available and active products. See WithdrawnProducts for discontinued ones.
func (*Client) Updates ¶
Updates returns an information about the current version of PSREF data and a list of added/updated/deleted entries.
func (*Client) WithdrawnProducts ¶
func (c *Client) WithdrawnProducts(ctx context.Context) ([]ProductType, error)
WithdrawnProducts is similar to Products, but returns discontinued products instead of active ones.
type ClientOption ¶ added in v0.2.0
type ClientOption interface {
// contains filtered or unexported methods
}
ClientOption controls different aspects of Client behavior.
func WithBaseURL ¶ added in v0.2.0
func WithBaseURL(url string) ClientOption
WithBaseURL changes the base URL for all API requests.
func WithDebug ¶ added in v0.2.0
func WithDebug(w io.Writer) ClientOption
WithDebug sets a debug log output.
func WithHTTPClient ¶ added in v0.2.0
func WithHTTPClient(cli *http.Client) ClientOption
WithHTTPClient sets an HTTP client for all requests.
func WithRate ¶ added in v0.2.0
func WithRate(rate *rate.Limiter) ClientOption
WithRate sets a rate limit for all requests. Passing nil will disable rate limiting.
func WithRetry ¶ added in v0.2.0
func WithRetry(retries int) ClientOption
WithRetry sets the number of retries per request. Setting 0 or 1 means send request only once, setting -1 means retry until completion.
type Date ¶
Date is wrapper around time.Time which uses custom JSON encoding.
func (Date) MarshalJSON ¶
func (*Date) UnmarshalJSON ¶
type Documentation ¶
type Documentation struct { ProductID PID `json:"ProductId"` Title string `json:"DocTitle"` URL string `json:"DocLink"` }
Documentation is a reference to documentation resource.
type Model ¶
type Model struct { Product WithdrawnStatus int `json:"M_WdStatus"` RefURL string `json:"ModelURL"` Detail []KeyValue `json:"Detail"` Code ModelCode `json:"ModelCode"` }
Model is a full model information, including exact specifications. Not all Product fields will be set.
func (*Model) DetailByName ¶
DetailByName searches a specification value by the key name.
type ModelInfo ¶
type ModelInfo struct { Code ModelCode `json:"ModelCode"` Summary string `json:"Summary"` Updated Date `json:"Updated"` }
ModelInfo is a basic model info used in the model list.
type Product ¶
type Product struct { ID PID `json:"ProductId"` Key string `json:"ProductKey"` Name string `json:"Name"` RefURL string `json:"ProductURL"` WithdrawnStatus int64 `json:"P_WdStatus"` SpecURL string `json:"Spec"` US_Pdf string `json:"US_Pdf"` EMEA_Pdf string `json:"EMEA_Pdf"` WW_Pdf string `json:"WW_Pdf"` Image string `json:"ImageForShare"` Images []string `json:"Images"` Models []ModelInfo `json:"Models"` Docs []Documentation `json:"Documentations"` }
Product is a full product information. It includes multiple models, which in turn list exact specifications.
type ProductLine ¶
type ProductLine struct { Name string `json:"ProductLineName"` Image string `json:"ImageUrl"` Series []Series `json:"Series"` }
ProductLine includes multiple product series.
type ProductShort ¶
type ProductShort struct { ID PID `json:"ProductId"` Key string `json:"ProductKey"` Name string `json:"ProductName"` WithdrawnStatus int64 `json:"P_WdStatus"` Updated Date `json:"LastUpdated"` ModelModified Date `json:"ModelModifyDateTime"` ConfigModified Date `json:"ConfigModifyDateTime"` }
ProductShort is a short product description.
type ProductType ¶
type ProductType struct { Name string `json:"ClassificationName"` BgColor string `json:"BackgroundColor"` Lineup []ProductLine `json:"ProductLine"` }
ProductType is a top-level product type which includes multiple product lineups.
type SearchResult ¶
type SearchResult struct { ID PID `json:"ProductId"` Name string `json:"ProductName"` Models int `json:"ModelCount"` }
SearchResult as returned by the Search API.
type Series ¶
type Series struct { Name string `json:"SeriesName"` Products []ProductShort `json:"Products"` }
type UpdatedProduct ¶
type UpdatedProduct struct { ID PID `json:"productId"` Title string `json:"title"` Reason string `json:"reason,omitempty"` }
UpdatedProduct is an information about product update used in the PSREF Updates info.
type Updates ¶
type Updates struct { Version uint64 `json:"x_Version"` // TODO: upstream VersionTS time.Time `json:"x_VersionTS"` // TODO: upstream VersionTitle string `json:"LatestUpdateVersion"` New []UpdatedProduct `json:"New"` Updated []UpdatedProduct `json:"Updated"` Withdrawn []UpdatedProduct `json:"Withdrawn"` }