brickset

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2022 License: MIT Imports: 16 Imported by: 0

README

Abstract

brickset is a Go client library for accessing the brickset.com API v3.

If using this API, you may need to complete the following:

  • Register for the brickset.com,click here
  • All methods require a valid API key to be passed, which can be obtained here.

Interfaces

type IBrickSet interface {
	GetSets(ctx context.Context, params *GetSetRequest) (int, []*Sets, error)
	GetThemes(ctx context.Context) (int, []*Themes, error)
	GetReviews(ctx context.Context, setID int) (int, []*Review, error)
	GetSubthemes(ctx context.Context, theme string) (int, []*Subthemes, error)
	GetInstructions(ctx context.Context, setID int) (int, []*Instruction, error)
	GetInstructions2(ctx context.Context, setNumber string) (int, []*Instruction, error)
	GetAdditionalImages(ctx context.Context, setID int) (int, []*Image, error)
	GetYears(ctx context.Context, theme string) (int, []*Years, error)
}

Installation

# Go Modules
require github.com/lehoqi/brickset

Usage

The following samples will assist you to become as comfortable as possible with brickset library.

package main

import (
	"context"
	"github.com/lehoqi/brickset"
	"log"
)

func main() {
	ctx := context.Background()
	svc := brickset.New("api-key", "username", "password", brickset.WithDebug(true))
	_, themes, err := svc.GetThemes(ctx)
	if err != nil {
		panic(err)
	}
	for _, theme := range themes {
		_, sets, err := svc.GetSets(ctx, &brickset.GetSetRequest{Theme: theme.Theme, PageSize: 2})
		if err != nil {
			panic(err)
		}
		for _, set := range sets {
			log.Println(set.Name)
		}
	}
}

Tests

go test -v

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Logger = log.Default()

Functions

This section is empty.

Types

type AgeRange

type AgeRange struct {
	Min int `json:"min"`
	Max int `json:"max"`
}

type Barcodes

type Barcodes struct {
	EAN string `json:"EAN"`
	UPC string `json:"UPC"`
}

type Collection

type Collection struct {
	Owned    bool   `json:"owned"`
	Wanted   bool   `json:"wanted"`
	QtyOwned int    `json:"qtyOwned"`
	Rating   int    `json:"rating"`
	Notes    string `json:"notes"`
}

type Collections

type Collections struct {
	OwnedBy  int `json:"ownedBy"`
	WantedBy int `json:"wantedBy"`
}

type CommonResponse

type CommonResponse struct {
	Status           string         `json:"status"`
	Message          string         `json:"message"`
	Themes           []*Themes      `json:"themes"`
	Matches          int            `json:"matches"`
	Sets             []*Sets        `json:"sets"`
	Hash             string         `json:"hash"`
	Reviews          []*Review      `json:"reviews"`
	Subthemes        []*Subthemes   `json:"subthemes"`
	Instructions     []*Instruction `json:"instructions"`
	AdditionalImages []*Image       `json:"additionalImages"`
	Years            []*Years
}

func (CommonResponse) Error

func (c CommonResponse) Error() error

func (CommonResponse) IsSuccess

func (c CommonResponse) IsSuccess() bool

type Dimensions

type Dimensions struct {
	Height float32 `json:"height"`
	Width  float32 `json:"width"`
	Depth  float32 `json:"depth"`
	Weight float32 `json:"weight"`
}

type ExtendedData

type ExtendedData struct {
	Notes       string   `json:"notes"`
	Tags        []string `json:"tags"`
	Description string   `json:"description"`
}

type GetSetRequest

type GetSetRequest struct {
	SetID      int    `json:"setID,omitempty"`
	Query      string `json:"query,omitempty"`
	Theme      string `json:"theme,omitempty"`
	SetNumber  string `json:"setNumber,omitempty"`
	PageSize   int    `json:"pageSize,omitempty"`
	PageNumber int    `json:"pageNumber,omitempty"`
}

func (GetSetRequest) JSON

func (g GetSetRequest) JSON() string

type IBrickAuth

type IBrickAuth interface {
	Login(ctx context.Context) (string, error)
	CheckUserHash(ctx context.Context, hash string) (bool, error)
	CheckKey(ctx context.Context, key string) (bool, error)
}

func NewAuth

func NewAuth(apiKey, username, password string, client IClient) IBrickAuth

type IBrickHash

type IBrickHash interface {
	GetHash(ctx context.Context, username string) (string, error)
}

func NewHash

func NewHash(auth IBrickAuth, store IBrickStorage, expires time.Duration) IBrickHash

type IBrickSet

type IBrickSet interface {
	GetSets(ctx context.Context, params *GetSetRequest) (int, []*Sets, error)
	GetThemes(ctx context.Context) (int, []*Themes, error)
	GetReviews(ctx context.Context, setID int) (int, []*Review, error)
	GetSubthemes(ctx context.Context, theme string) (int, []*Subthemes, error)
	GetInstructions(ctx context.Context, setID int) (int, []*Instruction, error)
	GetInstructions2(ctx context.Context, setNumber string) (int, []*Instruction, error)
	GetAdditionalImages(ctx context.Context, setID int) (int, []*Image, error)
	GetYears(ctx context.Context, theme string) (int, []*Years, error)
}

func New

func New(apiKey, username, password string, opts ...Option) IBrickSet

type IBrickStorage

type IBrickStorage interface {
	Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error
	Get(ctx context.Context, key string) (interface{}, error)
}

type IClient

type IClient interface {
	GetJSON(ctx context.Context, api string, params url.Values, response interface{}) error
	PostJSON(ctx context.Context, api string, request interface{}, response interface{}) error
	PostForm(ctx context.Context, api string, params url.Values, response interface{}) error
}

func NewClient

func NewClient(baseURL string, debug bool) IClient

type Image

type Image struct {
	ThumbnailURL string `json:"thumbnailURL"`
	ImageURL     string `json:"imageURL"`
}

func (*Image) Download

func (i *Image) Download(c *imagePath) error

type Instruction

type Instruction struct {
	URL    string `json:"url"`
	Number int    `json:"number"`
	Text   string `json:"text"`
}

type LEGOCom

type LEGOCom struct {
	US LEGOComDetails `json:"US"`
	UK LEGOComDetails `json:"UK"`
	CA LEGOComDetails `json:"CA"`
	DE LEGOComDetails `json:"DE"`
}

type LEGOComDetails

type LEGOComDetails struct {
	RetailPrice        float32   `json:"retailPrice"`
	DateFirstAvailable time.Time `json:"dateFirstAvailable"`
	DateLastAvailable  time.Time `json:"dateLastAvailable"`
}

type Option

type Option func(conf *config)

func WithAuth

func WithAuth(username, password string) Option

func WithDebug

func WithDebug(debug bool) Option

func WithHashExpires

func WithHashExpires(expires time.Duration) Option

func WithImagePath

func WithImagePath(basePath string, prefix string) Option

func WithStorage

func WithStorage(s IBrickStorage) Option

type Rating

type Rating struct {
	Overall            int `json:"overall"`
	Parts              int `json:"parts"`
	BuildingExperience int `json:"buildingExperience"`
	Playability        int `json:"playability"`
	ValueForMoney      int `json:"valueForMoney"`
}

type Review

type Review struct {
	Author     string  `json:"author"`
	DatePosted string  `json:"datePosted"`
	Rating     *Rating `json:"rating"`
	Title      string  `json:"title"`
	Review     string  `json:"review"`
	HTML       bool    `json:"HTML"`
}

type Sets

type Sets struct {
	SetID                int          `json:"setID"`
	Number               string       `json:"number"`
	NumberVariant        int          `json:"numberVariant"`
	Name                 string       `json:"name"`
	Year                 int          `json:"year"`
	Theme                string       `json:"theme"`
	ThemeGroup           string       `json:"themeGroup"`
	Subtheme             string       `json:"subtheme"`
	Category             string       `json:"category"`
	Released             bool         `json:"released"`
	Pieces               int          `json:"pieces"`
	Minifigs             int          `json:"minifigs"`
	Image                Image        `json:"image"`
	BricksetURL          string       `json:"bricksetURL"`
	Collection           Collection   `json:"collection"`
	Collections          Collections  `json:"collections"`
	LEGOCom              LEGOCom      `json:"LEGOCom"`
	Rating               float32      `json:"rating"`
	ReviewCount          int          `json:"reviewCount"`
	PackagingType        string       `json:"packagingType"`
	Availability         string       `json:"availability"`
	InstructionsCount    int          `json:"instructionsCount"`
	AdditionalImageCount int          `json:"additionalImageCount"`
	AgeRange             AgeRange     `json:"ageRange"`
	Dimensions           Dimensions   `json:"dimensions"`
	Barcode              Barcodes     `json:"barcode"`
	ExtendedData         ExtendedData `json:"extendedData"`
	LastUpdated          string       `json:"lastUpdated"`
}

type Subthemes

type Subthemes struct {
	Theme    string
	Subtheme string
	SetCount int
	YearFrom int
	YearTo   int
}

type Themes

type Themes struct {
	Theme         string
	SetCount      int
	SubthemeCount int
	YearFrom      int
	YearTo        int
}

type Years

type Years struct {
	Theme string `json:"theme"`
	Year  string `json:"year"`
	Count int    `json:"setCount"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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