Documentation
¶
Overview ¶
Package itembase gives a thin wrapper around the itembase REST API.
Index ¶
- func ConvertTo(inputInterface, outputType interface{}) error
- type API
- type Address
- type Billing
- type Brand
- type Buyer
- type BuyerID
- type Buyers
- type Category
- type Client
- type Config
- type Contact
- type Error
- type Identifier
- type ItembaseResponse
- type ItembaseTokens
- type Product
- type ProductDescription
- type ProductID
- type Products
- func (products *Products) Add(product interface{}) error
- func (products *Products) ByShop(shopID string) (filteredProducts Products)
- func (products *Products) Count() int
- func (products *Products) Exists(searchProduct Product) bool
- func (products *Products) InStock() (filteredProducts Products)
- func (products *Products) MaxCreatedAt() time.Time
- func (products *Products) MaxUpdatedAt() time.Time
- type Profile
- type ProfileID
- type Profiles
- type Shipping
- type Status
- type StockInformation
- type TokenLoader
- type TokenPermissions
- type TokenSaver
- type Transaction
- type TransactionID
- type Transactions
- func (transactions *Transactions) Add(transaction interface{}) error
- func (transactions *Transactions) Completed() (filteredTransactions Transactions)
- func (transactions *Transactions) Count() int
- func (transactions *Transactions) Exists(searchTransaction Transaction) bool
- func (transactions *Transactions) MaxCreatedAt() time.Time
- func (transactions *Transactions) MaxUpdatedAt() time.Time
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type API ¶
type API interface { // Call is responsible for performing HTTP transactions such as GET, POST, // PUT, PATCH, and DELETE. It is used to communicate with Itembase by all // of the Client methods. // // Arguments are as follows: // - `method`: The http method for this call // - `path`: The full itembase url to call // - `auth`: TODO // - `body`: Data to be marshalled to JSON (it's the responsibility of Call to do the marshalling and unmarshalling) // - `params`: Additional parameters to be passed to itembase // - `dest`: The object to save the unmarshalled response body to. // It's up to this method to unmarshal correctly, the default implementation just uses `json.Unmarshal` Call(method, path, auth string, body interface{}, params map[string]string, dest interface{}) error }
API is the internal interface for interacting with Itembase. The internal implementation of this interface is responsible for all HTTP operations that communicate with Itembase.
Users of this library can implement their own API-conformant types for testing purposes. To use your own test API type, pass it in to the NewClient function.
type Address ¶
type Address struct { City string `json:"city,omitempty"` Country string `json:"country,omitempty"` Line1 string `json:"line_1,omitempty"` Name string `json:"name,omitempty"` Zip string `json:"zip,omitempty"` }
An Address represents a mailing address model from the itembase API.
type Billing ¶
type Billing struct {
Address Address `json:"address,omitempty"`
}
Billing represents a model from the itembase API containing the billing address of a Transaction.
type Brand ¶
type Brand struct { Name struct { Language string `json:"language,omitempty"` Value string `json:"value,omitempty"` } `json:"name,omitempty"` }
A Brand represents a product brand model from the itembase API.
type Buyer ¶
type Buyer struct { Active bool `json:"active,omitempty"` Contact Contact `json:"contact,omitempty"` CreatedAt *time.Time `json:"created_at,omitempty"` Currency string `json:"currency,omitempty"` DateOfBirth string `json:"date_of_birth,omitempty"` FirstName string `json:"first_name,omitempty"` ID BuyerID `json:"id"` Language string `json:"language,omitempty"` LastName string `json:"last_name,omitempty"` Locale string `json:"locale,omitempty"` Note string `json:"note,omitempty"` OptOut bool `json:"opt_out,omitempty"` OriginalReference string `json:"original_reference,omitempty"` SourceID string `json:"source_id,omitempty"` Status string `json:"status,omitempty"` Type string `json:"type,omitempty"` UpdatedAt *time.Time `json:"updated_at,omitempty"` URL string `json:"url,omitempty"` }
A Buyer represents a buyer entity from the itembase API.
type Buyers ¶
type Buyers struct {
Buyers []Buyer `json:"documents"`
}
Buyers is a container for pagination of Buyer entities.
func (*Buyers) MaxCreatedAt ¶
Return date of heighest Created At buyer
func (*Buyers) MaxUpdatedAt ¶
Return date of heighest Updated At buyer
type Category ¶
type Category struct { CategoryID string `json:"category_id,omitempty"` Language string `json:"language,omitempty"` Value string `json:"value,omitempty"` }
A Category represents a product category model from the itembase API.
type Client ¶
type Client interface { // Returns the absolute URL path for the client URL() string // Gets the value referenced by the client and unmarshals it into // the passed in destination. GetInto(destination interface{}) error // Paginates through all possible values from client, and unmarshals // into the passed in destination GetAllInto(destination interface { Add(interface{}) error Count() int MaxCreatedAt() time.Time MaxUpdatedAt() time.Time }) error // Returns how many documents were found Found() (count int, err error) // Gets values referenced by the client, and returns them as generic interface(!) Get() (destination interface{}, err error) Me() (destination User, err error) Activate() (destination interface{}, err error) // Child returns a reference to the child specified by `path`. This does not // actually make a request to itembase, but you can then manipulate the reference // by calling one of the other methods (such as `GetInto` or `Get`). Child(path string) Client Transactions() Client Products() Client Profiles() Client Buyers() Client Sandbox() Client User(path string) Client Select(prop string) Client CreatedAtFrom(value time.Time) Client CreatedAtTo(value time.Time) Client UpdatedAtFrom(value time.Time) Client UpdatedAtTo(value time.Time) Client Limit(limit uint) Client Offset(offset uint) Client Max(max int) Client SaveToken(userID string, token *oauth2.Token) (err error) GetCachedToken(userID string) (token *oauth2.Token, err error) GiveTokenPermissions(authURL string) (authcode string, err error) HandleOAuthCode(authcode string) (*oauth2.Token, error) GetUserIDForToken(token *oauth2.Token) (string, error) }
A Client retrieves data from the itembase API. Use itembase.New to create an instance of the default implementation.
TODO: document each method
func New ¶
New creates a new instance of the default itembase Client implementation.
The options must be non-nil and must provide all OAuth2 credentials and configuration for an application registered with the itembase API.
TODO: always use the default API impl, NewClient allows dependency injection needed for testing.
type Config ¶
type Config struct { // ClientID is the OAuth2 application ID for a registered itembase app. // See oauth2.Config. ClientID string // ClientSecret is the application's OAuth2 secret credential. // See oauth2.Config. ClientSecret string // Scopes specify requested OAuth2 permissions, as defined by the itembase // API. See oauth2.Config. Scopes []string // A TokenHandler provides handlers for lifecycle events of OAuth2 tokens. TokenHandler ItembaseTokens // Production may be set to false to put a Client into sandbox mode. Production bool // RedirectURL is the URL to redirect users after requesting OAuth2 // permission grants from itembase. See oauth2.Config. RedirectURL string }
A Config structure is used to configure an itembase Client instance.
type Contact ¶
type Contact struct { Addresses []Address `json:"addresses,omitempty"` Emails []struct { Value string `json:"value,omitempty"` } `json:"emails,omitempty"` Phones []interface{} `json:"phones,omitempty"` }
A Contact represents a container of contact information from itembase API models.
type Error ¶
Error is a Go representation of the error message sent back by itembase when a request results in an error.
type Identifier ¶
type Identifier struct {
ID string `json:"id,omitempty"`
}
type ItembaseResponse ¶
type ItembaseResponse struct { Documents []interface{} `json:"documents"` NumDocumentsFound int `json:"num_documents_found"` NumDocumentsReturned int `json:"num_documents_returned"` }
ItembaseResponse is a container for any Itembase response. It returns the resultset, Number of found documents and Number of documents returned
type ItembaseTokens ¶
type ItembaseTokens struct { TokenLoader TokenLoader TokenSaver TokenSaver TokenPermissions TokenPermissions }
ItembaseTokens is a container struct holding handler functions for events in an OAuth2 token's lifecycle.
type Product ¶
type Product struct { Active bool `json:"active,omitempty"` Brand Brand `json:"brand,omitempty"` Categories []Category `json:"categories,omitempty"` Condition string `json:"condition,omitempty"` CreatedAt *time.Time `json:"created_at,omitempty"` Currency string `json:"currency,omitempty"` Description []ProductDescription `json:"description,omitempty"` ID ProductID `json:"id"` Identifier Identifier `json:"identifier,omitempty"` Name []struct { Language string `json:"language,omitempty"` Value string `json:"value,omitempty"` } `json:"name,omitempty"` OriginalReference string `json:"original_reference,omitempty"` PictureUrls []struct { URLOriginal string `json:"url_original,omitempty"` } `json:"picture_urls,omitempty"` PricePerUnit float64 `json:"price_per_unit,omitempty"` Shipping []struct { Price float64 `json:"price,omitempty"` ShippingService string `json:"shipping_service,omitempty"` } `json:"shipping,omitempty"` SourceID string `json:"source_id,omitempty"` StockInformation StockInformation `json:"stock_information,omitempty"` Tax float64 `json:"tax,omitempty"` TaxRate float64 `json:"tax_rate,omitempty"` UpdatedAt *time.Time `json:"updated_at,omitempty"` URL string `json:"url,omitempty"` Variants []interface{} `json:"variants,omitempty"` }
A Product represents a product entity from the itembase API.
See http://sandbox.api.itembase.io/swagger-ui/
func (*Product) GetDefaultName ¶
Returns any name for Product
type ProductDescription ¶
type ProductDescription struct { Language string `json:"language,omitempty"` Value string `json:"value,omitempty"` }
A ProductDescription represents a product description model from the itembase API, which may be in a specified language.
type Products ¶
type Products struct {
Products []Product `json:"documents"`
}
Products is a container for pagination of Product entities.
func (*Products) MaxCreatedAt ¶
Return date of heighest Created At product
func (*Products) MaxUpdatedAt ¶
Return date of heighest Updated At product
type Profile ¶
type Profile struct { Active bool `json:"active,omitempty"` AvatarURL string `json:"avatar_url,omitempty"` Contact struct { Contact []Contact `json:"contact,omitempty"` } `json:"contact,omitempty"` CreatedAt *time.Time `json:"created_at,omitempty"` Currency string `json:"currency,omitempty"` DisplayName string `json:"display_name,omitempty"` ID ProfileID `json:"id"` Language string `json:"language,omitempty"` Locale string `json:"locale,omitempty"` OriginalReference string `json:"original_reference,omitempty"` PlatformID string `json:"platform_id,omitempty"` PlatformName string `json:"platform_name,omitempty"` SourceID string `json:"source_id,omitempty"` Status string `json:"status,omitempty"` Type string `json:"type,omitempty"` UpdatedAt *time.Time `json:"updated_at,omitempty"` URL string `json:"url,omitempty"` }
A Profile represents a user profile entity from the itembase API.
type Profiles ¶
type Profiles struct {
Profiles []Profile `json:"documents"`
}
Profiles is a container for pagination of Profile entities.
func (*Profiles) MaxCreatedAt ¶
Return date of heighest Created At profile
func (*Profiles) MaxUpdatedAt ¶
Return date of heighest Updated At profile
type Status ¶
type Status struct { Global string `json:"global,omitempty"` Payment string `json:"payment,omitempty"` Shipping string `json:"shipping,omitempty"` }
Status describes a transactions' status
type StockInformation ¶
type TokenLoader ¶
A TokenLoader is called at points during OAuth2 authorization flow when an application might wish to retrieve a persisted token from a data store.
type TokenPermissions ¶
A TokenPermissions handler is called at points during OAuth2 authorization flow when a grantor might have granted new permissions for an authorization, such as new scopes.
type TokenSaver ¶
A TokenSaver is called at points during OAuth2 authorization flow when an application might wish to persist the given token to a data store or cache.
type Transaction ¶
type Transaction struct { Billing Billing `json:"billing,omitempty"` Buyer Buyer `json:"buyer,omitempty"` CreatedAt *time.Time `json:"created_at,omitempty"` Currency string `json:"currency,omitempty"` ID TransactionID `json:"id"` OriginalReference string `json:"original_reference,omitempty"` Products []Product `json:"products,omitempty"` Shipping Shipping `json:"shipping,omitempty"` SourceID string `json:"source_id,omitempty"` Status Status `json:"status,omitempty"` TotalPrice float64 `json:"total_price,omitempty"` TotalPriceNet float64 `json:"total_price_net,omitempty"` TotalTax float64 `json:"total_tax,omitempty"` UpdatedAt *time.Time `json:"updated_at,omitempty"` }
A Transaction represents a transaction entity from the itembase API.
See http://sandbox.api.itembase.io/swagger-ui/
func (*Transaction) Completed ¶
func (t *Transaction) Completed() bool
type TransactionID ¶
type TransactionID string
func (TransactionID) String ¶
func (transactionID TransactionID) String() string
type Transactions ¶
type Transactions struct {
Transactions []Transaction `json:"documents"`
}
Transactions is a container for pagination of Transaction entities.
func (*Transactions) Add ¶
func (transactions *Transactions) Add(transaction interface{}) error
func (*Transactions) Completed ¶
func (transactions *Transactions) Completed() (filteredTransactions Transactions)
Return only completed transactions
func (*Transactions) Count ¶
func (transactions *Transactions) Count() int
func (*Transactions) Exists ¶
func (transactions *Transactions) Exists(searchTransaction Transaction) bool
func (*Transactions) MaxCreatedAt ¶
func (transactions *Transactions) MaxCreatedAt() time.Time
Return date of heighest Created At transaction
func (*Transactions) MaxUpdatedAt ¶
func (transactions *Transactions) MaxUpdatedAt() time.Time
Return date of heighest Updated At transaction
type User ¶
type User struct { UUID string `json:"uuid"` Username string `json:"username,omitempty"` FirstName string `json:"first_name,omitempty"` LastName string `json:"last_name,omitempty"` MiddleName string `json:"middle_name,omitempty"` NameFormat string `json:"name_format,omitempty"` Locale string `json:"locale,omitempty"` Email string `json:"email,omitempty"` PreferredCurrency string `json:"preferred_currency,omitempty"` }
A User represents a user entity from the itembase API, such as returned from the "me" endpoint.