go_zasilkovna

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2022 License: MIT Imports: 16 Imported by: 0

README

go-zasilkovna

Connecting to API

package main

import (
	"log"
	"go-zasilkovna/models"
)

func main() {
	client, _ := New(&Options{
		Creds: NewCredentials("API KEY"),
	})

	log.Println(client)
}

Full example of getting info about packet

package main

import (
	"log"
	"go-zasilkovna/models"
)

func main() {
	client, _ := New(&Options{
		Creds: NewCredentials("API KEY"),
	})

	log.Println(client)

	a, err := client.PacketInfo(1234567890) //packetId
	log.Println(a)
	log.Println(err)
}

Full example of validating packet attributes

package main

import (
	"log"
	"go-zasilkovna/models"
)

func main() {
	client, _ := New(&Options{
		Creds: NewCredentials("API KEY"),
	})

	log.Println(client)

	a, err := client.PacketAttributesValid(models.PacketAttributes{
		Number:    "123abc",
		Name:      "John",
		Surname:   "Doe",
		Email:     "john.doe@test.te",
		Phone:     "123321123",
		AddressId: 95,
		Value:     100.00,
		Eshop:     "my.eshop",
	})
	log.Println(a)
	log.Println(err)
}

Full example of creating new packet

package main

import (
	"log"
	"go-zasilkovna/models"
)

func main() {
	client, _ := New(&Options{
		Creds: NewCredentials("API KEY"),
	})

	log.Println(client)

	a, err := client.CreatePacket(models.PacketAttributes{
		Number:    "123abc",
		Name:      "John",
		Surname:   "Doe",
		Email:     "john.doe@test.te",
		Phone:     "123321123",
		AddressId: 95,
		Value:     100.00,
		Eshop:     "my.eshop",
	})
	log.Println(a)
	log.Println(err)
}

Documentation

Index

Constants

View Source
const BasicUrl = "https://www.zasilkovna.cz/api/rest/"

Variables

View Source
var DefaultTransport = func() (*http.Transport, error) {
	tr := &http.Transport{
		Proxy: http.ProxyFromEnvironment,
		DialContext: (&net.Dialer{
			Timeout:   30 * time.Second,
			KeepAlive: 30 * time.Second,
		}).DialContext,
		MaxIdleConns:          256,
		MaxIdleConnsPerHost:   16,
		ResponseHeaderTimeout: time.Minute,
		IdleConnTimeout:       time.Minute,
		TLSHandshakeTimeout:   10 * time.Second,
		ExpectContinueTimeout: 10 * time.Second,

		DisableCompression: true,
	}

	tr.TLSClientConfig = &tls.Config{

		MinVersion: tls.VersionTLS12,
	}

	return tr, nil
}

DefaultTransport - this default transport is similar to http.DefaultTransport but with additional param DisableCompression is set to true to avoid decompressing content with 'gzip' encoding.

Functions

This section is empty.

Types

type Client

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

func New

func New(opts *Options) (*Client, error)

New - instantiate minio client with options

func (Client) BarcodePng

func (c Client) BarcodePng(barcode string) (binary.ByteOrder, error)

BarcodePng returns binary result in base64 encoding. The barcode is created with Code 128 symbology. NOTE: The method does not validate the barcode in any way. If you wish to create a barcode to use it on your labels, it is important that you use packetId prefixed by the letter Z e.g. Z1234567890.

func (Client) ClaimAttributesValid

func (c Client) ClaimAttributesValid(claimAttributes models.ClaimAttributes) error

ClaimAttributesValid Validates PacketAttributes. On success (the attributes are valid) returns <status>ok</status> `err.Status == ResponseStatusOk`. On error (the attributes are NOT valid) returns <status>fault</status> as Rfc7807Error `err.Status == ResponseStatusFault`.

func (Client) CreatePacket

func (c Client) CreatePacket(packetAttributes models.PacketAttributes) (*models.CreatePacketResponse, error)

CreatePacket Creates packet from PacketAttributes. On success returns PacketIdDetail with information about the newly created packet.

func (Client) CreatePacketClaim

func (c Client) CreatePacketClaim(claimAttributes models.ClaimAttributes) (*models.PacketIdDetail, error)

CreatePacketClaim Creates a claim assistant packet from ClaimAttributes. On success returns PacketIdDetail with information about the newly created packet.

func (Client) CreatePacketClaimWithPassword

func (c Client) CreatePacketClaimWithPassword(createPacketClaimWithPassword models.CreatePacketClaimWithPassword) (models.PacketDetail, error)

CreatePacketClaimWithPassword Creates a claim assistant packet from ClaimWithPasswordAttributes. On success returns PacketDetail with information about the newly created packet.

func (*Client) EndpointURL

func (c *Client) EndpointURL() *url.URL

EndpointURL returns the URL of the zasilkovna.

func (Client) PacketAttributesValid

func (c Client) PacketAttributesValid(packetAttributes models.PacketAttributes) error

PacketAttributesValid Validates PacketAttributes. On success (the attributes are valid) returns <status>ok</status> `err.Status == ResponseStatusOk`. On error (the attributes are NOT valid) returns <status>fault</status> as Rfc7807Error `err.Status == ResponseStatusFault`.

func (Client) PacketGetStoredUntil

func (c Client) PacketGetStoredUntil(packetId int) (models.ZasilkovnaDate, error)

PacketGetStoredUntil Fetches the date until which the packet specified by packetId is stored and waiting for pickup. If the packet is not yet ready for pickup or is already returning to sender null is returned.

func (Client) PacketInfo

func (c Client) PacketInfo(packetId int) (models.PacketInfoResponse, error)

PacketInfo Returns additional information about packet and its consignment to an external courier, if there is one. On success it returns PacketInfoResult.

func (Client) PacketLabelPdf

func (c Client) PacketLabelPdf(packetIds models.Ids, format string, offset int) (binary.ByteOrder, error)

PacketLabelPdf returns binary result in base64 encoding. Fetches a label for packet specified by packetId in format specified by format on a position specified by offset. The position is calculated left to right starting at top left corner of the document.

func (Client) PacketStatus

func (c Client) PacketStatus(packetId int) (models.CurrentStatusRecord, error)

PacketStatus fetches information about the current status of the packet specified by packetId. On success returns CurrentStatusRecord.

func (Client) PacketTracking

func (c Client) PacketTracking(packetId int) (models.StatusRecords, error)

PacketTracking Fetches the whole tracking history of the packet specified by packetId. On success returns StatusRecords struct

type Credentials

type Credentials struct {
	sync.Mutex

	ApiKey string
}

func NewCredentials

func NewCredentials(key string) *Credentials

type Options

type Options struct {
	Transport http.RoundTripper
	Creds     *Credentials
}

type ToRfc7807Error added in v0.1.0

type ToRfc7807Error interface {
	ToRfc7807Error(code int) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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