baselinker

package module
v0.0.0-...-c9bd229 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2020 License: BSD-3-Clause Imports: 4 Imported by: 0

README

GoLang BaseLinker API

go-baselinker is a Go client library for accessing the BaseLinker service.

Currently, library is BETA version and testing only on Go version 1.12.

Library not implement each of method from BaseLinker API Documentation yet.

Usage

import "github.com/oxess/go-baselinker"

Construct a new BaseLinker client. Base API url is publish in Documentation.

For generate api key must go to "My account" -> "API" -> type name of application and click "Generate token".

baseLinkerUrl := "https://api.baselinker.com/connector.php"
baseLinkerToken := "xxx"

baseLinker := baselinker.NewBaseLinker(baseLinkerUrl, baseLinkerToken)
Example

Get logs kind of "create new order", "change order status" from the journal.

journalListParameters := baselinker.GetJournalListParameters{
    Types: []int{
        baselinker.LogTypeCreateNewOrder, 
        baselinker.LogTypeChangeOrderStatus
    },
}
logs, err := baseLinker.GetJournal(journalListParameters)

Get order by the id.

order, err := baseLinker.GetOrder(orderId)

Errors

BaseLinker return field "status" with values: "SUCCESS" or "ERROR". When status is "ERROR" then it add fields: "error_message" and "error_code".

Library supports errors by return error object but with custom field "code". Each error allow check code and compare it with baselinker error code list. Example:


order, err := baseLinker.GetOrder(orderId)
if nil != err {
    if err.CodeError() == ErrorCodeAccountBlocked {
        panic("Your %s account is blocked!", baseLinkerToken)
    } else {
        panic(err.Error()) // <-- here is baselinker error message
    } 
}

Developed methods

Name Description
GetJournal Get list of logs
GetOrders Get list of orders
GetOrder Get single order by the id

Versioning

Versioning is base on semver. The new version is release by a new tag.

Licence

This library is distributed under the BSD 3 Licence, see LICENSE for more information.

Contributing

Author of this library is Mikołaj Jeziorny.

If you want to help with development it - fork me!

Documentation

Index

Constants

View Source
const (
	ErrorNoCode             = "ERROR_NO_CODE"
	ErrorCodeAccountBlocked = "ERROR_USER_ACCOUNT_BLOCKED"
)
View Source
const (
	LogTypeCreateNewOrder    = 1
	LogTypeChangeOrderStatus = 18
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseLinker

type BaseLinker struct {
	Url   string
	Token string
}

func NewBaseLinker

func NewBaseLinker(url string, token string) *BaseLinker

func (*BaseLinker) GetJournal

func (baseLiner *BaseLinker) GetJournal(parameters GetJournalListParameters) ([]Log, Error)

Documentation: https://api.baselinker.com/index.php?method=getJournalList

func (*BaseLinker) GetOrder

func (baseLiner *BaseLinker) GetOrder(orderId int, unconfirmed bool) (Order, Error)

func (*BaseLinker) GetOrders

func (baseLiner *BaseLinker) GetOrders(parameters GetOrdersListParameters) ([]Order, Error)

Documentation: https://api.baselinker.com/index.php?method=getOrders

func (*BaseLinker) GetProduct

func (baseLiner *BaseLinker) GetProduct(storageId, productId string) (Product, Error)

func (*BaseLinker) GetProductDetails

func (baseLiner *BaseLinker) GetProductDetails(storageId, productId string) (Product, Error)

func (*BaseLinker) GetProductsList

func (baseLiner *BaseLinker) GetProductsList(parameters GetProductsListParameters) ([]Product, Error)

Documentation: https://api.baselinker.com/index.php?method=getProductsList

func (*BaseLinker) GetProdutsDetails

func (baseLiner *BaseLinker) GetProdutsDetails(parameters GetProductsDetailsParameters) ([]Product, Error)

Documentation: https://api.baselinker.com/index.php?method=getProductsData

type BaseResponse

type BaseResponse struct {
	Status       string `json:"status"`
	ErrorMessage string `json:"error_message"`
	ErrorCode    string `json:"error_code"`
}

func NewSimpleError

func NewSimpleError(err error) *BaseResponse

func (*BaseResponse) CodeError

func (baseLinkerResponse *BaseResponse) CodeError() string

func (*BaseResponse) Error

func (baseLinkerResponse *BaseResponse) Error() string

func (*BaseResponse) IsSuccess

func (baseLinkerResponse *BaseResponse) IsSuccess() bool

type Error

type Error interface {
	Error() string
	CodeError() string
}

type GetJournalListParameters

type GetJournalListParameters struct {
	OrderId int   `json:"order_id,omitempty"`
	LastId  int   `json:"last_log_id,omitempty"`
	Types   []int `json:"logs_types,omitempty"`
}

type GetJournalListResponse

type GetJournalListResponse struct {
	*BaseResponse
	Logs []Log `json:"logs"`
}

type GetOrdersListParameters

type GetOrdersListParameters struct {
	Unconfirmed   bool   `json:"get_unconfirmed_orders"`
	ConfirmedOn   int    `json:"date_confirmed_from,omitempty"`
	FromOn        int    `json:"date_from,omitempty"`
	FromId        int    `json:"id_from,omitempty"`
	OrderId       int    `json:"order_id,omitempty"`
	StatusId      int    `json:"status_id,omitempty"`
	FilterByEmail string `json:"filter_email,omitempty"`
}

type GetOrdersListResponse

type GetOrdersListResponse struct {
	*BaseResponse
	Orders []Order `json:"orders"`
}

type GetProductsDetailsParameters

type GetProductsDetailsParameters struct {
	StorageId   string   `json:"storage_id"`
	ProductsIds []string `json:"products"`
}

type GetProductsListParameters

type GetProductsListParameters struct {
	StorageId          string  `json:"storage_id"`
	FilterCategoryId   string  `json:"filter_category_id,omitempty"`
	FilterSort         string  `json:"filter_sort,omitempty"`
	FilterId           string  `json:"filter_id,omitempty"`
	FilterEan          string  `json:"filter_ean,omitempty"`
	FilterSku          string  `json:"filter_sku,omitempty"`
	FilterName         string  `json:"filter_name,omitempty"`
	FilterPriceFrom    float32 `json:"filter_price_from,omitempty"`
	FilterPriceTo      float32 `json:"filter_price_to,omitempty"`
	FilterQuantityFrom int     `json:"filter_quantity_from,omitempty"`
	FilterQuantityTo   int     `json:"filter_quantity_to,omitempty"`
	FilterAvailable    int     `json:"filter_available,omitempty"`
	Page               int     `json:"page,omitempty"`
}

type GetProductsResponse

type GetProductsResponse struct {
	*BaseResponse
	Products []Product `json:"products"`
}

type Log

type Log struct {
	Id       int `json:"log_id"`
	Type     int `json:"log_type"`
	OrderId  int `json:"order_id"`
	ObjectId int `json:"object_id"`
	Date     int `json:"date"`
}

type Order

type Order struct {
	Id       int       `json:"order_id"`
	Phone    string    `json:"phone"`
	Email    string    `json:"email"`
	Products []Product `json:"products"`

	// Invoice
	InvoiceNip         string `json:"invoice_nip"`
	InvoiceClientName  string `json:"invoice_fullname"`
	InvoiceCompanyName string `json:"invoice_company"`

	// Client
	ClientName        string `json:"delivery_fullname"`
	ClientCompanyName string `json:"delivery_company"`
	ClientCity        string `json:"delivery_city"`
	ClientStreet      string `json:"delivery_address"`
	ClientPostalCode  string `json:"delivery_postcode"`
}

func (*Order) GetClientFullName

func (order *Order) GetClientFullName() string

func (*Order) HasInvoiceNip

func (order *Order) HasInvoiceNip() bool

type Product

type Product struct {
	Id        string `json:"product_id"`
	Sku       string `json:"sku"`
	Quantity  int    `json:"quantity"`
	Storage   string `json:"storage"`
	StorageId string `json:"storage_id"`
}

Jump to

Keyboard shortcuts

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