sendico

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CaesarShift = -3
)
View Source
const (
	// DefaultBaseURL is the default base URL for the Sendico API.
	DefaultBaseURL = "https://sendico.com"
)

Variables

View Source
var (
	ErrRequest        = errors.New("sendico request failed")
	ErrSecretNotFound = errors.New("sendico API secret not found")
	ErrInvalidShop    = errors.New("invalid shop")
)
View Source
var ShopMap = map[string]Shop{
	YahooAuctions.Identifier(): YahooAuctions,
	Mercari.Identifier():       Mercari,
	Rakuma.Identifier():        Rakuma,
	Rakuten.Identifier():       Rakuten,
	Yahoo.Identifier():         Yahoo,
}

Functions

func DecodeHMACKey added in v0.4.0

func DecodeHMACKey(key string) string

func NewInvalidShopError

func NewInvalidShopError(s string) error

func NewRequestError

func NewRequestError(err error) error

func NewUnexpectedResponseCodeError

func NewUnexpectedResponseCodeError(code int) error

Types

type Auction

type Auction struct {
	BuyOutPriceYen *int      `json:"buy_out_price"`
	BuyOutPriceUSD *int      `json:"buy_out_converted_price"`
	EndTime        time.Time `json:"end_time"`
	Bids           int       `json:"bids"`
}

func (*Auction) Ends

func (a *Auction) Ends() time.Duration

func (*Auction) IsEnded

func (a *Auction) IsEnded() bool

type Client

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

func New

func New(ctx context.Context, opts ...ClientOption) (*Client, error)

func (*Client) BulkSearch

func (c *Client) BulkSearch(ctx context.Context, shops []Shop, opts SearchOptions) ([]Item, error)

BulkSearch performs a search for the given term on the specified merchants. It will only return the first page of results.

func (*Client) FindHMAC added in v0.3.0

func (c *Client) FindHMAC(ctx context.Context) error

FindHMAC finds the HMAC secret key used to sign requests to the Sendico API. This is very jank, it will go through the frontend's SSR'd nuxt data and attempt to find the latest hmac secret key(s). This will most likely break at some point in the future.

func (*Client) HMACSecret added in v0.3.0

func (c *Client) HMACSecret() string

HMACSecret returns the HMAC secret key used to sign requests to the Sendico API.

func (*Client) Search

func (c *Client) Search(ctx context.Context, shop Shop, opts SearchOptions) ([]Item, error)

Search performs a search for the given term on the specified merchant. It will only return the first page of results. The supplied search term must be in Japanese.

func (*Client) Translate

func (c *Client) Translate(ctx context.Context, text string) (string, error)

Translate translates the given text from English to Japanese.

type ClientOption

type ClientOption func(*Client)

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ClientOption

type HMACAttributes added in v0.3.0

type HMACAttributes struct {
	Signature string
	Nonce     string
	Timestamp int64
}

func BuildHMAC added in v0.3.0

func BuildHMAC(in HMACInput) (*HMACAttributes, error)

type HMACInput added in v0.3.0

type HMACInput struct {
	Secret    string
	Path      string
	Payload   *orderedmap.OrderedMap[string, any]
	Timestamp int64
	Nonce     string
}

type Item

type Item struct {
	*Auction
	Shop     Shop         `json:"shop"`
	Code     string       `json:"code"`
	Name     string       `json:"name"`
	Category *json.Number `json:"category"`
	URL      string       `json:"url"`
	Image    string       `json:"img"`
	PriceYen int          `json:"price"`
	PriceUSD int          `json:"converted_price"`
	Labels   []string     `json:"labels"`
}

func (*Item) IsAuction

func (i *Item) IsAuction() bool
func (i *Item) SendicoLink() string

type SearchOptions

type SearchOptions struct {
	TermJP   string
	MinPrice *int
	MaxPrice *int
}

type Shop

type Shop int
const (
	YahooAuctions Shop = 0b00001
	Mercari       Shop = 0b00010
	Rakuma        Shop = 0b00100
	Rakuten       Shop = 0b01000
	Yahoo         Shop = 0b10000
)

func ShopsFromBits

func ShopsFromBits(bits int) []Shop

func (Shop) Identifier

func (s Shop) Identifier() string

func (Shop) IsAuction

func (s Shop) IsAuction() bool

func (Shop) MarshalJSON

func (s Shop) MarshalJSON() ([]byte, error)

func (*Shop) Name

func (s *Shop) Name() string

func (*Shop) UnmarshalJSON

func (s *Shop) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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