client

package
v0.0.0-...-7a89833 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateDisabled = "disabled"
	StateInvited  = "invited"
	StateEnabled  = "enabled"
	StateDeclined = "declined"
)
View Source
const (
	UserAgent = "goshopify/1.0.0"
)

Variables

This section is empty.

Functions

func CheckResponseError

func CheckResponseError(r *http.Response) error

Types

type Client

type Client struct {
	// HTTP client used to communicate with the Shopify API.
	Client *http.Client

	// version you're currently using of the api, defaults to "stable"
	ApiVersion string

	// Services used for communicating with the API
	Customer CustomerService
	// contains filtered or unexported fields
}

Client manages communication with the Shopify API.

func NewClient

func NewClient(apiUrl, token string) *Client

func (*Client) Count

func (c *Client) Count(path string, options interface{}) (int, error)

func (*Client) CreateAndDo

func (c *Client) CreateAndDo(method, relPath string, data, options, resource interface{}) error

CreateAndDo performs a web request to Shopify with the given method (GET, POST, PUT, DELETE) and relative path (e.g. "/admin/orders.json"). The data, options and resource arguments are optional and only relevant in certain situations. If the data argument is non-nil, it will be used as the body of the request for POST and PUT requests. The options argument is used for specifying request options such as search parameters like created_at_min Any data returned from Shopify will be marshalled into resource argument.

func (*Client) Delete

func (c *Client) Delete(path string) error

Delete performs a DELETE request for the given path

func (*Client) Get

func (c *Client) Get(path string, resource, options interface{}) error

Get performs a GET request for the given path and saves the result in the given resource.

func (*Client) NewRequest

func (c *Client) NewRequest(method, relPath string, body, options interface{}) (*http.Request, error)

Creates an API request. A relative URL can be provided in urlStr, which will be resolved to the BaseURL of the Client. Relative URLS should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

func (*Client) Post

func (c *Client) Post(path string, data, resource interface{}) error

Post performs a POST request for the given path and saves the result in the given resource.

func (*Client) Put

func (c *Client) Put(path string, data, resource interface{}) error

Put performs a PUT request for the given path and saves the result in the given resource.

type Customer

type Customer struct {
	ID               int64      `json:"id,omitempty"`
	Email            string     `json:"email,omitempty"`
	FirstName        string     `json:"first_name,omitempty"`
	LastName         string     `json:"last_name,omitempty"`
	State            string     `json:"state,omitempty"`
	Note             string     `json:"note,omitempty"`
	VerifiedEmail    bool       `json:"verified_email,omitempty"`
	OrdersCount      int        `json:"orders_count,omitempty"`
	TaxExempt        bool       `json:"tax_exempt,omitempty"`
	Phone            string     `json:"phone,omitempty"`
	Tags             string     `json:"tags,omitempty"`
	LastOrderId      int64      `json:"last_order_id,omitempty"`
	LastOrderName    string     `json:"last_order_name,omitempty"`
	AcceptsMarketing bool       `json:"accepts_marketing"`
	CreatedAt        *time.Time `json:"created_at,omitempty"`
	UpdatedAt        *time.Time `json:"updated_at,omitempty"`
}

Customer represents a Shopify customer

type CustomerResource

type CustomerResource struct {
	Customer *Customer `json:"customer"`
}

Represents the result from the customers/X.json endpoint

type CustomerService

type CustomerService interface {
	List(interface{}) ([]Customer, *Pagination, error)
	Count(interface{}) (int, error)
	Get(int64) (*Customer, error)
	Create(*Customer) (*Customer, error)
	Update(*Customer) (*Customer, error)
	Delete(int64) error
}

CustomerService is an interface for interfacing with the customers endpoints of Shopify API.

type CustomerServiceOp

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

CustomerServiceOp handles communication with the product related methods of the Shopify API.

func (*CustomerServiceOp) Count

func (s *CustomerServiceOp) Count(options interface{}) (int, error)

func (*CustomerServiceOp) Create

func (s *CustomerServiceOp) Create(customer *Customer) (*Customer, error)

func (*CustomerServiceOp) Delete

func (s *CustomerServiceOp) Delete(customerID int64) error

func (*CustomerServiceOp) Get

func (s *CustomerServiceOp) Get(customerID int64) (*Customer, error)

func (*CustomerServiceOp) List

func (s *CustomerServiceOp) List(options interface{}) ([]Customer, *Pagination, error)

func (*CustomerServiceOp) Update

func (s *CustomerServiceOp) Update(customer *Customer) (*Customer, error)

type CustomersResource

type CustomersResource struct {
	Customers []Customer `json:"customers"`
}

Represents the result from the customers.json endpoint

type ListOptions

type ListOptions struct {
	PageInfo     string     `url:"page_info,omitempty"`
	Page         int        `url:"page,omitempty"`
	Limit        int        `url:"limit,omitempty"`
	CreatedAtMin *time.Time `url:"created_at_min,omitempty"`
	CreatedAtMax *time.Time `url:"created_at_max,omitempty"`
	UpdatedAtMin *time.Time `url:"updated_at_min,omitempty"`
	UpdatedAtMax *time.Time `url:"updated_at_max,omitempty"`
	Order        string     `url:"order,omitempty"`
	Fields       string     `url:"fields,omitempty"`
	Vendor       string     `url:"vendor,omitempty"`
}

The query string otpions provided by Shopify

type Pagination

type Pagination struct {
	NextPageOptions     *ListOptions
	PreviousPageOptions *ListOptions
}

Represents the pagination data from the response header

type RateLimitError

type RateLimitError struct {
	ResponseError
	RetryAfter int
}

An error specific to a rate-limiting response. Embeds the ResponseError to allow consumers to handle it the same was a normal ResponseError.

type ResponseDecodingError

type ResponseDecodingError struct {
	Body    []byte
	Message string
	Status  int
}

ResponseDecodingError occurs when the response body from Shopify could not be parsed.

func (ResponseDecodingError) Error

func (e ResponseDecodingError) Error() string

type ResponseError

type ResponseError struct {
	Status  int
	Message string
	Errors  []string
}

A general response error that follows a similar layout to Shopify response errors, i.e. either a single message or a list of messages.

func (ResponseError) Error

func (e ResponseError) Error() string

func (ResponseError) GetErrors

func (e ResponseError) GetErrors() []string

GetErrors returns response errors list

func (ResponseError) GetMessage

func (e ResponseError) GetMessage() string

GetMessage returns response error message

func (ResponseError) GetStatus

func (e ResponseError) GetStatus() int

GetStatus returns http response status

Jump to

Keyboard shortcuts

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