codeswholesale

package module
v0.0.0-...-1b785cd Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2016 License: MIT Imports: 8 Imported by: 0

README

Go CodesWholesale API

Build Status GoDoc

codeswholesale is a Go client library for the CodesWholesale API.

Start using it

  1. Download and install it:

    $ go get github.com/MarinX/codeswholesale
    
  2. Import it in your code:

    import "github.com/MarinX/codeswholesale"
    
  3. (Optional) Run test

    $ go test -v
    

API Examples

Get Account
	cw := codeswholesale.New("ClientID", "ClientSecret", codeswholesale.MODE_SANDBOX)

	account, err := cw.GetAccount()
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Printf("%+v", account)
Get all products
	cw := codeswholesale.New("ClientID", "ClientSecret", codeswholesale.MODE_SANDBOX)

	products, err := cw.GetProducts()
	if err != nil {
		fmt.Println(err)
		return
	}

	for _, val := range products {
		fmt.Printf("%+v\n", val)
	}
Get Single Product
	cw := codeswholesale.New("ClientID", "ClientSecret", codeswholesale.MODE_SANDBOX)

	product, err := cw.GetProductByID("product-cwid")
	if err != nil {
		fmt.Println(err)
		return
	}
	
	fmt.Printf("%+v\n", product)
Order single code
	cw := codeswholesale.New("ClientID", "ClientSecret", codeswholesale.MODE_SANDBOX)

	order, err := cw.SingleCodeOrder("product-cwid")
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Printf("%+v\n", order)
Multiple code order
	cw := codeswholesale.New("ClientID", "ClientSecret", codeswholesale.MODE_SANDBOX)

	orders, err := cw.MultipleCodeOrder("product-cwid",5)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("Order ID %s", orders.OrderID)

	for _, val := range orders.Items {
		fmt.Printf("%+v\n", val)
	}

License

This library is under the MIT License

Documentation

Overview

account, model

codeswholesale

common, model for common structs for other models

order

product

util provides utility for common usage

Index

Constants

View Source
const (
	API_STATUS_SUCCESS   = 0
	API_VERSION          = "v1"
	API_LIVE_ENDPOINT    = "https://api.codeswholesale.com"
	API_SANDBOX_ENDPOINT = "https://sandbox.codeswholesale.com"
)

API Constants

View Source
const (
	MODE_LIVE    cwMode = 1
	MODE_SANDBOX cwMode = 0
)

API modes

View Source
const (
	CODE_TEXT     cwTypeCode = "CODE_TEXT"
	CODE_PREORDER cwTypeCode = "CODE_PREORDER"
	CODE_IMAGE    cwTypeCode = "CODE_IMAGE"
)

Order response codes

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	FullName       string  `json:"fullName"`
	Email          string  `json:"email"`
	CurrentBalance float32 `json:"currentBalance"`
	CurrentCredit  float32 `json:"currentCredit"`
	TotalToUse     float32 `json:"totalToUse"`
	Links          []Link  `json:"links"`
}

type CWError

type CWError struct {
	Status  int    `json:"status,omitempty"`
	Message string `json:"message,omitempty"`
}

type CodesWholesale

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

func New

func New(clientID string, clientSecret string, mode cwMode) *CodesWholesale

Creates new REST API client, to get api key: 1. Login into your account on app.codeswholesale.com 2. Locate Web API tab on the left bar 3. Generate new credentials (Keep in mind that a client secret will be visible only once)

func (*CodesWholesale) GetAccount

func (c *CodesWholesale) GetAccount() (*Account, error)

Account Details provide you whole information about your account from name to actual balance with credit included.

func (*CodesWholesale) GetEndpoint

func (c *CodesWholesale) GetEndpoint() string

Get endpoint based by mode: MODE_LIVE or MODE_SANDBOX It’s highly recommended to start working on your custom implementatnion on SANDBOX environment

func (*CodesWholesale) GetProductByID

func (c *CodesWholesale) GetProductByID(cwID string) (*Product, error)

You can ask our API for only one product using ID. Tip: It’s good way to keep your stock and prices always updated.

func (*CodesWholesale) GetProducts

func (c *CodesWholesale) GetProducts() ([]Product, error)

Here you can easily ask for all products from CodesWholesale Price List. In response you will receive important informations about each product.

func (*CodesWholesale) MultipleCodeOrder

func (c *CodesWholesale) MultipleCodeOrder(cwID string, quantity uint) (*Orders, error)

Using your productID you can order games. Everything depends on quantity which you have to provide in your request. Create multiple codes order

func (*CodesWholesale) SingleCodeOrder

func (c *CodesWholesale) SingleCodeOrder(cwID string) (*Order, error)

Using your before recieved productId you can order this game in our API via this CURL. Remember it is only for one code.

type Image

type Image struct {
	URL    string `json:"image"`
	Format string `json:"format"`
}

type Item

type Item struct {
	Items []Product `json:"items"`
}
type Link struct {
	Rel  string `json:"rel"`
	Href string `json:"href"`
}

type Order

type Order struct {
	CodeType cwTypeCode `json:"codeType"`
	Code     string     `json:"code"`
	Links    []Link     `json:"links,omitempty"`
	FileName string     `json:"fileName,omitempty"`
}

func (*Order) IsCodeImage

func (o *Order) IsCodeImage() bool

func (*Order) IsCodePreorder

func (o *Order) IsCodePreorder() bool

func (*Order) IsCodeText

func (o *Order) IsCodeText() bool

type Orders

type Orders struct {
	OrderID string  `json:"orderId"`
	Items   []Order `json:"items"`
}

type Price

type Price struct {
	Value float32 `json:"value"`
	From  float32 `json:"from"`
	To    float32 `json:"to"`
}

type Product

type Product struct {
	ProductID   string     `json:"productId"`
	Identifier  string     `json:"identifier"`
	Name        string     `json:"name"`
	Platform    string     `json:"platform"`
	Quantity    uint       `json:"quantity"`
	Images      []Image    `json:"images"`
	Regions     []string   `json:"regions"`
	Languages   []string   `json:"languages"`
	Prices      []Price    `json:"prices"`
	Links       []Link     `json:"links"`
	ReleaseDate *time.Time `json:"releaseDate"`
}

Jump to

Keyboard shortcuts

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