go_bricklink_api

package module
v0.1.4-beta Latest Latest
Warning

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

Go to latest
Published: May 15, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

README

This package implements a wrapper for the Bricklink API v3.0.

It is a work in progress and is not yet complete.

There are three packages that represent broad areas of the API.

  • Reference API: The Bricklink catalog of items, colors, and categories. These are not editable resources.
    • Catalog Items
    • Colors
    • Categories
    • Item Types
    • Item / color / type mappings
    • Price Guide
    • Supersets
    • Subsets
  • Order API: The Bricklink order system.
    • Orders
    • Order Items
    • Feedback
    • Members
    • Messages
    • Problems
  • Inventory API: The Bricklink store inventory system.
    • Inventories
    • Inventory Items

The API packages share an implementation of the HTTP client to allow mocking.

Each API Resource is available as a separate package with one or more structs and methods to access the API. Each Resource Representation in the API has its own struct. API methods are members of the package.

Coupons API is not yet implemented.

Simple Example

package main

import (
   "fmt"
   bricklink "github.com/bricklink/go-bricklink-api"
   "github.com/funwithbots/go-bricklink-api/inventory"
   "github.com/funwithbots/go-bricklink-api/orders"
   "github.com/funwithbots/go-bricklink-api/reference"
)

func main() { 
   // Create a new Bricklink API client
   b, err := bricklink.New(bricklink.WithEnv())
   if err != nil {
      panic(err)
   }
   ref := reference.New(*b)

   // Interact with the Reference API
   item, err := ref.GetCatalogItem(
      reference.WithItemNo("3001"),
      reference.WithItemType(reference.ItemTypePart),
   )
   if err != nil {
      panic(err)
   }
   fmt.Printf("%s %s is %s\n", item.Type, item.ItemNo, item.Name)

   // Interact with the Inventory API
   inv := inventory.New(*b)
   items, err := inv.GetItems(
      inventory.WithInventoryType(inventory.InventoryTypePart),
      inventory.WithColorID(11),
      inventory.WithItemNo("3001"),
   )
   if err != nil {
      panic(err)
   }
   fmt.Printf("There are %d matching items in inventory\n", len(items))

   // Interact with the Orders API
   ord := orders.New(*b)
   o, err := ord.GetOrders(
      orders.WithOrderStatus(orders.OrderStatusShipped),
      orders.WithOrderStatus(orders.OrderStatusPaid), 
      orders.WithOrderFiled(false),
   )
   if err != nil {
      panic(err)
   }
   fmt.Printf("There are %d matching orders\n", len(o))
}

References

https://www.bricklink.com/v3/api.page?page=references

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ItemTypeMap = map[ItemType]string{
	ItemTypePart:        "part",
	ItemTypeMinifig:     "minifig",
	ItemTypeBook:        "book",
	ItemTypeCatalog:     "catalog",
	ItemTypeInstruction: "instruction",
	ItemTypeSet:         "set",
	ItemTypeOriginalBox: "original_box",
	ItemTypeGear:        "gear",
	ItemTypeUnsortedLot: "unsorted_lot",
}

Functions

This section is empty.

Types

type Bricklink struct {
	Client internal.HTTPClient

	Timeout time.Duration
	Rand    *rand.Rand
	// contains filtered or unexported fields
}

Bricklink is a wrapper for the Bricklink API.

func New

func New(opts ...BricklinkOption) (*Bricklink, error)

New creates a new Bricklink API wrapper.

func (*Bricklink) NewRequest

func (b *Bricklink) NewRequest(method string, path string, params map[string]string, body []byte) (*http.Request, error)

NewRequest creates a new HTTP request with auth headers and the specified method and path. The body is optional. If present, it should be sent as an urlencoded strings.NewReader(body).

func (*Bricklink) NewRequestWithContext

func (b *Bricklink) NewRequestWithContext(ctx context.Context, method, path string, params map[string]string, body []byte) (*http.Request, error)

NewRequestWithContext creates a new HTTP request with auth headers and the specified method and path. The body is optional. If present, it should be sent as an urlencoded strings.NewReader(body).

type BricklinkOption

type BricklinkOption func(opts *Bricklink)

func WithBaseURL

func WithBaseURL(baseURL string) BricklinkOption

func WithConsumerKey

func WithConsumerKey(consumerKey string) BricklinkOption

func WithConsumerSecret

func WithConsumerSecret(consumerKey string) BricklinkOption

func WithEnv

func WithEnv(files ...string) BricklinkOption

WithEnv reads the environment variables from the specified files and sets them on the client. If the files are not specified, it will read from .env in the project root. If the expected file is not found, it will do nothing.

func WithHTTPClient

func WithHTTPClient(client internal.HTTPClient) BricklinkOption

func WithOAuthTokenKey

func WithOAuthTokenKey(oAuthToken string) BricklinkOption

func WithOAuthTokenSecret

func WithOAuthTokenSecret(oAuthToken string) BricklinkOption

func WithTimeout

func WithTimeout(timeout time.Duration) BricklinkOption

type ItemType

type ItemType string
const (
	ItemTypePart        ItemType = "P"
	ItemTypeMinifig     ItemType = "M"
	ItemTypeGear        ItemType = "G"
	ItemTypeBook        ItemType = "B"
	ItemTypeCatalog     ItemType = "C"
	ItemTypeInstruction ItemType = "I"
	ItemTypeSet         ItemType = "S"
	ItemTypeOriginalBox ItemType = "O"
	ItemTypeUnsortedLot ItemType = "L"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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