sendowl

package module
v0.0.0-...-5c2b020 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2017 License: MIT Imports: 18 Imported by: 0

README

Sendowl API Go Client Library

Go client library for the Sendowl API.

Note: implementation is incomplete. Please submit a PR for improvements.

Documentation

For full documentation see: https://godoc.org/github.com/jonathaningram/sendowl.

Install

go get github.com/jonathaningram/sendowl

Usage

package main

import (
	"log"
	"os"

	"golang.org/x/net/context"

	"github.com/jonathaningram/sendowl"
)

func main() {
	key := "sendowl-key"
	secret := "sendowl-secret"

	client := sendowl.New(*key, *secret)
	ctx := context.Background()

	filename := "file.pdf"
	name := filename
	t := sendowl.Digital
	price := 9.99

	f, err := os.Open(filename)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	resp, err := client.CreateProduct(ctx, sendowl.CreateProductRequest{
		Name:       name,
		Price:      sendowl.PriceFromFloat64(price),
		Type:       t,
		Attachment: f,
		Filename:   filename,
	})
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("%#v", resp)
}

To log Sendowl API requests, use WithLogger:

client := sendowl.New(...).WithLogger(log.New(os.Stderr, "", log.LstdFlags))

Documentation

Overview

Package sendowl provides a client for the Sendowl API.

Note: This package is a work-in-progress. Backwards-incompatible changes should be expected.

Index

Constants

View Source
const DefaultEndpoint = "https://www.sendowl.com/api/v1/"

DefaultEndpoint is the default root API endpoint.

View Source
const SignatureQueryParam = "signature"

Variables

View Source
var ErrNotFound = errors.New("sendowl: not found")

Functions

func Signature

func Signature(signingKey, signingKeySecret string, vs url.Values) string

func SigningKey

func SigningKey(signingKey, signingKeySecret string) string

func SigningText

func SigningText(signingKeySecret string, vs url.Values) string

func VerifySignatureFromRequest

func VerifySignatureFromRequest(signingKey, signingKeySecret string, r *http.Request) bool

Types

type Client

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

Client is a type which makes requests to Sendowl.

func New

func New(key, secret string) *Client

New creates a new Client which can be used to make requests to Sendowl services.

func (Client) CreateProduct

func (c Client) CreateProduct(ctx context.Context, req CreateProductRequest) (*CreateProductResponse, error)

CreateProduct uses req to create a new product, returning a CreateProductResponse and non-nil error if there was a problem.

func (Client) DeleteProduct

func (c Client) DeleteProduct(ctx context.Context, req DeleteProductRequest) (*DeleteProductResponse, error)

DeleteProduct uses req to delete a product, returning a DeleteProductResponse and non-nil error if there was a problem.

func (Client) GetProduct

func (c Client) GetProduct(ctx context.Context, req GetProductRequest) (*GetProductResponse, error)

GetProduct uses req to get a product, returning a GetProductResponse and non-nil error if there was a problem.

func (Client) ListProducts

func (c Client) ListProducts(ctx context.Context, req ListProductsRequest) (*ListProductsResponse, error)

ListProducts uses req to list a products, returning a ListProductsResponse and non-nil error if there was a problem.

func (Client) OrderProduct

func (c Client) OrderProduct(ctx context.Context, req OrderProductRequest) (*OrderProductResponse, error)

OrderProduct uses req to issue a new order, returning a OrderProductResponse and non-nil error if there was a problem.

func (Client) UpdateProduct

func (c Client) UpdateProduct(ctx context.Context, req UpdateProductRequest) (*UpdateProductResponse, error)

UpdateProduct uses req to update a product, returning a UpdateProductResponse and non-nil error if there was a problem.

func (*Client) WithEndpoint

func (c *Client) WithEndpoint(e *url.URL) *Client

func (*Client) WithLogger

func (c *Client) WithLogger(l *log.Logger) *Client

func (*Client) WithTransportFunc

func (c *Client) WithTransportFunc(f TransportFunc) *Client

type CreateProductRequest

type CreateProductRequest struct {
	Name        string      // Name of the product.
	Type        ProductType // Type of the product.
	Price       Price       // Price of the product.
	Attachment  io.Reader
	Filename    string // Filename of the file to attach.
	PDFStamping bool
	// SelfHostedURL is the url of the file to be issued at download (only
	// useable when the product is self hosted).
	SelfHostedURL string
}

CreateProductRequest is an API representation of a create product request.

type CreateProductResponse

type CreateProductResponse struct {
	Product Product `json:"product"`
}

CreateProductResponse is an API representation of a create product response.

type DeleteProductRequest

type DeleteProductRequest struct {
	ProductID `json:"-"` // ProductID of the product to delete.
}

DeleteProductRequest is an API representation of a delete product request.

type DeleteProductResponse

type DeleteProductResponse struct{}

DeleteProductResponse is an API representation of a delete product response.

type GetProductRequest

type GetProductRequest struct {
	ID ProductID
}

GetProductRequest is an API representation of a get product request.

type GetProductResponse

type GetProductResponse struct {
	Product `json:"product"`
}

GetProductResponse is an API representation of a get product response.

type ListProductsRequest

type ListProductsRequest struct {
	PerPage int
	Page    int
}

ListProductsRequest is an API representation of a list products request.

type ListProductsResponse

type ListProductsResponse []ListProductsResponseItem

ListProductsResponse is an API representation of a list products response.

func (*ListProductsResponse) Items

type ListProductsResponseItem

type ListProductsResponseItem struct {
	Product `json:"product"`
}

type Order

type Order struct {
	ID         OrderID `json:"id"` // ID of the order.
	BuyerEmail string  `json:"buyer_email"`
	BuyerName  string  `json:"buyer_name"`
	Cart       struct {
		Items []struct {
			Item struct {
				ProductID        `json:"product_id"`
				PackageID        int        `json:"package_id"`
				Quantity         int        `json:"quantity"`
				PriceAtCheckout  Price      `json:"price_at_checkout"`
				ValidUntil       *time.Time `json:"valid_until"`
				DownloadAttempts int        `json:"download_attempts"`
			} `json:"cart_item"`

			Product          Product    `json:"product"`
			Quantity         int        `json:"quantity"`
			ValidUntil       *time.Time `json:"valid_until"`
			DownloadAttempts int        `json:"download_attempts"`
		} `json:"cart_items"`
		CompletedCheckoutAt time.Time `json:"completed_checkout_at"`
		StartedCheckoutAt   time.Time `json:"started_checkout_at"`
	} `json:"cart"`
}

type OrderID

type OrderID int

func OrderIDFromInt

func OrderIDFromInt(i int64) OrderID

func OrderIDFromString

func OrderIDFromString(s string) OrderID

func (OrderID) Int

func (id OrderID) Int() int64

func (OrderID) String

func (id OrderID) String() string

func (*OrderID) UnmarshalJSON

func (id *OrderID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type OrderProductRequest

type OrderProductRequest struct {
	ProductID `json:"-"`   // ProductID of the product to order.
	Order     ProductOrder `json:"order"` // Order details.
}

OrderProductRequest is an API representation of an order product request.

type OrderProductResponse

type OrderProductResponse struct {
	Order `json:"order"`
}

OrderProductResponse is an API representation of an order product response.

type Price

type Price float64

func PriceFromFloat64

func PriceFromFloat64(f float64) Price

func (Price) String

func (p Price) String() string

func (*Price) UnmarshalJSON

func (p *Price) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type Product

type Product struct {
	// ID of the product.
	ID ProductID `json:"id"`
	// Name of the product.
	Name string `json:"name"`
	// Type of the product.
	Type ProductType `json:"product_type"`
	// Price of the product (in dollars and cents).
	Price Price `json:"price"`
	// InstantBuyURL for purchasing the product.
	InstantBuyURL string `json:"instant_buy_url"`
	PDFStamping   bool   `json:"pdf_stamping"`
	// SelfHostedURL is the url of the file to be issued at download (only
	// useable when the product is self hosted).
	SelfHostedURL string `json:"self_hosted_url"`
}

type ProductID

type ProductID int

func ProductIDFromInt

func ProductIDFromInt(i int64) ProductID

func ProductIDFromString

func ProductIDFromString(s string) ProductID

func (ProductID) Int

func (id ProductID) Int() int64

func (ProductID) String

func (id ProductID) String() string

func (*ProductID) UnmarshalJSON

func (id *ProductID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type ProductOrder

type ProductOrder struct {
	BuyerEmail       string     `json:"buyer_email"`
	BuyerName        string     `json:"buyer_name"`
	BuyerID          string     `json:"buyer_id,omitempty"`
	BuyerStatus      string     `json:"buyer_status,omitempty"`
	BuyerAddress1    string     `json:"buyer_address1,omitempty"`
	BuyerAddress2    string     `json:"buyer_address2,omitempty"`
	BuyerCity        string     `json:"buyer_city,omitempty"`
	BuyerRegion      string     `json:"buyer_region,omitempty"`
	BuyerPostCode    string     `json:"buyer_postcode,omitempty"`
	BuyerCountry     string     `json:"buyer_country,omitempty"`
	BuyerIPAddress   string     `json:"buyer_ip_address,omitempty"`
	CanMarketToBuyer bool       `json:"can_market_to_buyer"`
	Quantity         int        `json:"quantity,omitempty"`
	DispatchedAt     *time.Time `json:"dispatched_at,omitempty"`
	Tag              string     `json:"tag,omitempty"`
}

ProductOrder is an API representation of the order details for an order product request.

type ProductType

type ProductType string
const (
	Digital ProductType = "digital"
)

type ResponseNotJSONError

type ResponseNotJSONError struct {
	ContentType string
	Body        []byte
}

func (*ResponseNotJSONError) Error

func (e *ResponseNotJSONError) Error() string

type TransportFunc

type TransportFunc func(context.Context) http.RoundTripper

type UpdateProductRequest

type UpdateProductRequest struct {
	ProductID   `json:"-"`  // ProductID of the product to update.
	Name        string      // Name of the product.
	Type        ProductType // Type of the product.
	Price       Price       // Price of the product.
	Attachment  io.Reader
	Filename    string // Filename of the file to attach.
	PDFStamping bool
	// SelfHostedURL is the url of the file to be issued at download (only
	// useable when the product is self hosted).
	SelfHostedURL string
}

UpdateProductRequest is an API representation of an update product request.

type UpdateProductResponse

type UpdateProductResponse struct{}

UpdateProductResponse is an API representation of an update product response.

Jump to

Keyboard shortcuts

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