Help us shape the future of Go! Take the 2026 Go Developer Survey

neta

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2020 License: MIT Imports: 7 Imported by: 0

README

Go-NETA is a golang client for the public NETA reserve-ahead API.

For usage, see the tests and GoDoc

There are constants for some product categories and filters, but not all of them. They are just strings, so if you need others, just get the strings you need by inspecting the reserve-ahead portal's XHR calls.

All planned features are now supported. To submit a reservation, you should call Login on your client instance with reserve-ahead portal credentials you already created. Creating an account is not supported. The behavior when calling Submit wihtout having logged in is unknown by me.

I have no plans to support the Northampton location, but if you need it, feel free to send me a PR or just fork this package.

Documentation

Index

Constants

View Source
const (
	LabTestTHC = "thc"
	LabTestTAC = "tac"
	LabTestCBD = "cbd"
	LabTestCBN = "cbn"
)

test name constants

View Source
const (
	CategoryConcentrates = "Concentrates"
	CategoryVapes        = "Vapes"
	CategoryFlower       = "Flower"
)

Valid values for Category

View Source
const (
	SubCategoryConcentratesOil     = "Oil"
	SubCategoryConcentratesWax     = "Wax"
	SubCategoryConcentratesShatter = "Shatter"
	SubCategoryVapesApex           = "Apex"
	SubCategoryVapesRubi           = "Rubi"
	SubCategoryVapesRempen         = "Rempen"
)

Valid values for SubCategory

View Source
const (
	FilterIndica = "Indica"
	FilterSativa = "Sativa"
	FilterHybrid = "Hybrid"
)

Valid values for Filter

View Source
const (
	UnavailableItemPreferenceSubstitute = "substitute_item"
	UnavailableItemPreferenceRemove     = "remove_item"
	UnavailableItemPreferenceCancel     = "cancel_order"
)

Unavailable Item Preferences

Variables

View Source
var (
	ErrNoCookie = errors.New("failed to get cookie")
)

errors

Functions

This section is empty.

Types

type CartItem added in v0.2.0

type CartItem struct {
	ProductID  int    `json:"product_id"`
	UnitID     int    `json:"product_unit_id"`
	Quantity   int    `json:"quantity"`
	TopLine    string `json:"top_line"`
	BottomLine string `json:"bottom_line"`
}

CartItem is how the API represents an item in the cart

type Client

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

Client provides access to the NETA reserve-ahead API

func NewClient

func NewClient() (*Client, error)

NewClient returns a Client ready to use

func NewClientFromCookie added in v0.2.8

func NewClientFromCookie(cookie string) *Client

NewClientFromCookie constructs a new Client from a previously obtained cookie. No attempt is made to validate the cookie. Behavior with an invalid cookie is undefined.

func (*Client) AddItem added in v0.2.0

func (c *Client) AddItem(productID, unitID, quantity int) error

AddItem adds an item to the session's cart

func (*Client) Cookie added in v0.2.8

func (c *Client) Cookie() string

Cookie returns the cookie being used by the Client

func (*Client) DeleteItem added in v0.2.0

func (c *Client) DeleteItem(productID, unitID int) error

DeleteItem removes an item from the session's cart

func (*Client) GetCart added in v0.2.0

func (c *Client) GetCart() ([]CartItem, error)

GetCart returns the cart for the current session

func (*Client) Login added in v0.2.0

func (c *Client) Login(username, password string) error

Login associates the Client with a previously-created user account

func (*Client) Query

func (c *Client) Query() *QueryBuilder

Query returns a builder for a new query against the API

func (*Client) Submit added in v0.2.0

func (c *Client) Submit(unavailableItemPreference string) error

Submit creates a reservation from the current cart

type LabTest

type LabTest struct {
	Name  string  `json:"lab_test_name"`
	Value float64 `json:"lab_test_value"`
	Unit  string  `json:"lab_test_unit"`
}

LabTest is a cannabinoid measurement for the Product

type Price

type Price struct {
	UnitID     int         `json:"product_unit_id"`
	Quantity   int         `json:"quantity"`
	RawPrice   interface{} `json:"price"`
	Price      float64     `json:"-"`
	TopLine    string      `json:"top_line"`
	BottomLine string      `json:"bottom_line"`
}

Price contains various representations of the price of the Product

type Product

type Product struct {
	ID          int       `json:"id"`
	Name        string    `json:"name"`
	Category    string    `json:"type_name"`
	SubCategory string    `json:"category"`
	Type        string    `json:"type"`
	LabTests    []LabTest `json:"lab_tests"`
	Description string    `json:"description"`
	Prices      []Price   `json:"prices"`
}

Product is a cannabis product available to reserve ahead

func (Product) CBD added in v0.2.3

func (p Product) CBD() string

CBD returns a formatted string with the Product's CBD content. If none, an empty string is returned.

func (Product) CBN added in v0.2.3

func (p Product) CBN() string

CBN returns a formatted string with the Product's CBN content. If none, an empty string is returned.

func (Product) TAC added in v0.2.3

func (p Product) TAC() string

TAC returns a formatted string with the Product's TAC content. If none, an empty string is returned.

func (Product) THC added in v0.2.3

func (p Product) THC() string

THC returns a formatted string with the Product's THC content. If none, an empty string is returned.

type QueryBuilder

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

QueryBuilder exposes methods for building a query against the API

func (*QueryBuilder) Category

func (qb *QueryBuilder) Category(category string) *QueryBuilder

Category sets a category for the query

func (*QueryBuilder) Do

func (qb *QueryBuilder) Do() ([]Product, error)

Do executes the query and returns the result as a slice of Products

func (*QueryBuilder) Filter

func (qb *QueryBuilder) Filter(filter string) *QueryBuilder

Filter sets a filter for the query

func (*QueryBuilder) SubCategory

func (qb *QueryBuilder) SubCategory(subCategory string) *QueryBuilder

SubCategory sets a sub-cateogry for the query

type QueryResponse added in v0.2.0

type QueryResponse struct {
	Products []Product `json:"products"`
}

QueryResponse contains a slice of Products returned from the reserve-ahead API

Jump to

Keyboard shortcuts

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