api-go-wrapper

module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2020 License: MIT

README

ERPLY API Go SDK

GoDoc API Reference

This SDK covers the ERPLY API requests. Majority of the available requests can be checked from IClient file, but some are also here and here.

Install

go get github.com/erply/api-go-wrapper

Example usage as a service

import (
	"github.com/pkg/errors"
	"github.com/erply/api-go-wrapper/pkg/api"
	"strconv"
	"strings"
)

type erplyApiService struct {
	api.IClient
}

func NewErplyApiService(sessionKey, clientCode string) *erplyApiService {
	return &erplyApiService{api.NewClient(sessionKey, clientCode, nil)}
}

//getPointsOfSale erply API request
func (s *erplyApiService) getPointsOfSale(posID string) (string, error) {
	res, err := s.GetPointsOfSaleByID(posID)
	if err != nil {
		return "", err
	}
	return strconv.Itoa(res.WarehouseID), nil
}

//verifyIdentityToken erply API request
func (s *erplyApiService) verifyIdentityToken(jwt string) (string, error) {
	res, err := s.VerifyIdentityToken(jwt)
	if err != nil {
		if strings.Contains(err.Error(), "1000") {
			return "", errors.New("jwt expired")
		}
	}
	return res.SessionKey, nil
}

//getIdentityToken erply API request
func (s *erplyApiService) getIdentityToken() (string, error) {
	res, err := s.GetIdentityToken()
	if err != nil {
		if strings.Contains(err.Error(), "1054") {
			return "", errors.New("API session key expired")
		}
	}
	return res.Jwt, nil
}

Contributing

I would like to cover the entire ERPLY API and contributions are of course always welcome. The calling pattern is pretty well established, so adding new methods is relatively straightforward.

Authors

David Zingerman

Directories

Path Synopsis
pkg
api

Jump to

Keyboard shortcuts

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