cex

package module
v0.0.0-...-acfeb6e Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2023 License: Unlicense Imports: 6 Imported by: 0

README

CeX Go Client

CeX is a UK trade shop for movies, games and electronics.

The CeX website is built with Vue.js and Nuxt. It uses a RESTful API for sourcing products and their categories. It's actually a very pleasant API that's pretty well designed and easy to use, props to the CeX folks behind it!

This library implements some portion of that API, at least the interesting bits such as listing products. Using this library, you can pragmatically list all the products available in the store (at the time of writing, this was 369,625!)

The library has some extremely basic unit tests that simply make an API call and print the result. I didn't want to bother writing a full test suite against a dataset that will change! Run the tests to see an example of the output. The code is also documented so you should be up and running pretty quickly.

To CeX

If a CeX employee runs across this: This library is just the result of some mild curiosity, it's in no way intended to be malicious despite being unofficial and reverse engineered. The data itself is actually quite interesting and being able to access it pragmatically in this way could result in some interesting things!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Box

type Box struct {
	BoxID                string    `json:"boxId"`
	BoxName              string    `json:"boxName"`
	BoxDescription       string    `json:"boxDescription"`
	IsMasterBox          int       `json:"isMasterBox"`
	CategoryID           int       `json:"categoryId"`
	CategoryName         string    `json:"categoryName"`
	CategoryFriendlyName string    `json:"categoryFriendlyName"`
	SuperCatID           int       `json:"superCatId"`
	SuperCatName         string    `json:"superCatName"`
	SuperCatFriendlyName string    `json:"superCatFriendlyName"`
	ImageURLs            ImageURLs `json:"imageUrls"`
	CannotBuy            int       `json:"cannotBuy"`
	IsNewBox             int       `json:"isNewBox"`
	SellPrice            float64   `json:"sellPrice"`
	CashPrice            float64   `json:"cashPrice"`
	ExchangePrice        float64   `json:"exchangePrice"`
	FirstPrice           int       `json:"firstPrice"`
	PreviousPrice        int       `json:"previousPrice"`
	LastPriceUpdatedDate string    `json:"lastPriceUpdatedDate"`
	BoxRating            float64   `json:"boxRating"`
	CollectionQuantity   int       `json:"collectionQuantity"`
	EcomQuantityOnHand   int       `json:"ecomQuantityOnHand"`
	OutOfStock           int       `json:"outOfStock"`
	OutOfEcomStock       int       `json:"outOfEcomStock"`
}

Box represents an individual product

type BoxesParams

type BoxesParams struct {
	// One of these must be present
	SuperCatIDs []int  `qstring:"superCatIds"` // super category ID
	CategoryIDs []int  `qstring:"categoryIds"` // category ID
	BoxID       string `qstring:"q"`           // box ID

	// These are all optional
	FirstRecord int    `qstring:"firstRecord,omitempty"` // default: 50, basically a database OFFSET
	Count       int    `qstring:"count,omitempty"`       // default: 1, and a database LIMIT
	SortBy      string `qstring:"sortBy,omitempty"`      // default: relevance, attribute to sort by
	SortOrder   string `qstring:"sortOrder,omitempty"`   // default: desc, sort order
}

BoxesParams represents the URL query parameters for the Boxes endpoint

type Category

type Category struct {
	SuperCatID           int    `json:"superCatId"`
	CategoryID           int    `json:"categoryId"`
	CategoryFriendlyName string `json:"categoryFriendlyName"`
	ProductLineID        int    `json:"productLineId"`
	TotalBoxes           int    `json:"totalBoxes"`
}

Category represents a category of boxes with a super category

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents a HTTP client for interacting with CeX web resources.

func NewClient

func NewClient() *Client

NewClient creates a new CeX RESTful client.

func (*Client) Boxes

func (client *Client) Boxes(params BoxesParams) (result []Box, total int, err error)

Boxes returns product boxes from the given search parameters

func (*Client) Categories

func (client *Client) Categories(productLines []int) (result []Category, err error)

Categories returns product categories from for a set of productlines

func (*Client) ProductLines

func (client *Client) ProductLines(superCatIds []int) (result []ProductLine, err error)

ProductLines returns a list of product lines given a list of superCatIds

func (*Client) SuperCats

func (client *Client) SuperCats() (result []SuperCat, err error)

SuperCats simple returns a list of all super categories

type Facets

type Facets struct {
	SuperCatName           []map[string]interface{} // TODO
	CategoryFriendlyName   []map[string]interface{} // TODO
	ManufacturerName       []map[string]interface{} // TODO
	NetworkName            []map[string]interface{} // TODO
	AttributeStructureInfo interface{}              // ???
	AttributeInfo          interface{}              // ???
}

Facets seems to be some sort of summary of a set of query results containing data such as the number of items from each manufacturer etc. It hasn't been fully explored and modelled yet.

type ImageURLs

type ImageURLs struct {
	Large  string `json:"large"`
	Medium string `json:"medium"`
	Small  string `json:"small"`
}

ImageURLs contains a simple set of image URLs

type ProductLine

type ProductLine struct {
	SuperCatID      int    `json:"superCatId"`
	ProductLineID   int    `json:"productLineId"`
	ProductLineName string `json:"productLineName"`
	TotalCategories int    `json:"totalCategories"`
}

ProductLine represents a top-level line of product categories

type ResponseData

type ResponseData struct {
	// These are the main query result fields
	SuperCats    []SuperCat    `json:"superCats"`
	ProductLines []ProductLine `json:"productLines"`
	Categories   []Category    `json:"categories"`
	Boxes        []Box         `json:"boxes"`

	// These are additional pieces of data sent back with query results
	TotalRecords int     `json:"totalRecords"`
	MinPrice     float64 `json:"minPrice"`
	MaxPrice     float64 `json:"maxPrice"`
	Facets       Facets  `json:"facets"`
}

ResponseData contains the actual data from a query. Each query fills a different field.

type ResponseError

type ResponseError struct {
	Code            string        `json:"code"`
	InternalMessage string        `json:"internal_message"`
	MoreInfo        []interface{} `json:"moreInfo"`
}

ResponseError contains the structured error data (if any) in a response.

func (ResponseError) Error

func (re ResponseError) Error() string

type ResponsePayload

type ResponsePayload struct {
	Ack   string        `json:"ack"`
	Data  ResponseData  `json:"data"`
	Error ResponseError `json:"error"`
}

ResponsePayload is the only member of the response object. Why it's wrapped in this way? Who knows... Maybe another version of the API contained more fields in the parent object.

type ResponseWrapper

type ResponseWrapper struct {
	Response ResponsePayload `json:"response"`
}

ResponseWrapper wraps each response from the API.

type SortBy

type SortBy string

SortBy defines the different sort types

var (
	SortByMostPopular SortBy = "relevance" //
	SortBySellPrice   SortBy = "sellprice" //
	SortByName        SortBy = "boxname"   //
	SortByRating      SortBy = "rating"    //
)

The different sort types

type SuperCat

type SuperCat struct {
	SuperCatID           int    `json:"superCatId"`
	SuperCatFriendlyName string `json:"superCatFriendlyName"`
}

SuperCat or "super category" represents a general purpose category, there are only a few of these. The following supercats exist at the time of writing:

- Gaming (1) - Film & TV (2) - Computing (3) - Phones (4) - Electronics (5) - Music (8)

Jump to

Keyboard shortcuts

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