pingen

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2023 License: MIT Imports: 5 Imported by: 0

README

go-pingen-sdk

Build Status Go Report Card GitHub release (latest by date)

A personal hobby project that implements the API of postal provider pingen.com in Go.

Not affiliated in any way with pingen.com

Usage

Warning This API sends real letters and costs money. After you sent a letter it is validated and printed. There is only a very short timeframe before printing were you can cancel a letter.

Import it with

    go get github.com/goneup/go-pingen-sdk

Simple usage with (or see main.go)

    clientID := os.Getenv("CLIENT_ID")
    clientSecret := os.Getenv("CLIENT_SECRET")
    org := os.Getenv("PINGEN_ORG")
    useProd := true

    c := pingen.NewClient(clientID, clientSecret, useProd, org, context.Background())
    c.ListLetters()
	

For a complete overview of methods, refer to the go package documentation

API Information

Documentation

You need a API key, type Client Credentials. Instructions can be found here. The organisation UUID can be found in any URL on the website.

Pingen has a seperate staging environment if you want to test the complete flow, see here

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiError

type ApiError struct {
	Errors []struct {
		Code   string `json:"code"`
		Title  string `json:"title"`
		Detail string `json:"detail"`
		Source struct {
			Pointer   string `json:"pointer"`
			Parameter string `json:"parameter"`
		} `json:"source"`
	} `json:"errors"`
}

type AuthSuccess

type AuthSuccess struct {
	TokenType   string `json:"token_type"`
	ExpiresIn   int    `json:"expires_in"`
	AccessToken string `json:"access_token"`
}

type Client

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

func NewClient

func NewClient(clientID string, clientSecret string, useProd bool, organisationId string, ctx context.Context) (*Client, error)

Creates a new client struct.

func (*Client) CancelLetter

func (c *Client) CancelLetter(letterID string) (err error)

Tries to cancel the sending of a letter. If no error is returned the letter was canceled

func (*Client) CreateLetter

func (c *Client) CreateLetter(uploadPDF []byte, createData *CreateData) (result *Letter, err error)

Upload process!

Function that uploads the pdf file and creates a letter. Required letter data needs to be provided in createData.

--

createData.Data.Attributes.AddressPosition must be right or left

createData.Data.Attributes.DeliveryProduct can be empty, "fast", "cheap", "bulk", "premium", "registered", defaults to cheap

createData.Data.Attributes.PrintMode can be "simplex", "duplex", defaults to simplex

createData.Data.Attributes.PrintSpectrum can be "grayscale", "color", defaults to grayscale

createData.Data.Attributes.FileURL & createData.Data.Attributes.FileURLSignature will be autofilled.

func (*Client) DeleteLetter

func (c *Client) DeleteLetter(letterID string) (err error)

Tries to delete a letter. If no error is returned the letter was deleted

func (*Client) GetLetter

func (c *Client) GetLetter(letterID string) (result *Letter, err error)

Retrives details for one letter

func (*Client) ListLetters

func (c *Client) ListLetters() (result *LetterList, err error)

Return a list of all letters

func (*Client) SendLetter

func (c *Client) SendLetter(letterID string, data *SendData) (result *Letter, err error)

Function that sends a letter.

--

data.Data.Attributes.DeliveryProduct can be empty, "fast", "cheap", "bulk", "premium", "registered"

data.Data.Attributes.PrintMode can be empty, "simplex", "duplex"

data.Data.Attributes.PrintSpectrum can be empty, "grayscale", "color"

Data.Type & Data.ID will be autofilled

type CreateData

type CreateData struct {
	Data struct {
		Type       string `json:"type"`
		Attributes struct {
			FileOriginalName string `json:"file_original_name"`
			FileURL          string `json:"file_url"`
			FileURLSignature string `json:"file_url_signature"`
			AddressPosition  string `json:"address_position"`
			AutoSend         bool   `json:"auto_send"`

			DeliveryProduct string `json:"delivery_product"`
			PrintMode       string `json:"print_mode"`
			PrintSpectrum   string `json:"print_spectrum"`
		} `json:"attributes"`
	} `json:"data"`
}

type Letter

type Letter struct {
	Data LetterData `json:"data"`
}

type LetterData

type LetterData struct {
	ID         string `json:"id"`
	Type       string `json:"type"`
	Attributes struct {
		Status           string   `json:"status"`
		FileOriginalName string   `json:"file_original_name"`
		FilePages        int      `json:"file_pages"`
		Address          string   `json:"address"`
		AddressPosition  string   `json:"address_position"`
		Country          string   `json:"country"`
		DeliveryProduct  string   `json:"delivery_product"`
		PrintMode        string   `json:"print_mode"`
		PrintSpectrum    string   `json:"print_spectrum"`
		PriceCurrency    string   `json:"price_currency"`
		PriceValue       float64  `json:"price_value"`
		PaperTypes       []string `json:"paper_types"`
		Fonts            []struct {
			Name       string `json:"name"`
			IsEmbedded bool   `json:"is_embedded"`
		} `json:"fonts"`
		TrackingNumber string `json:"tracking_number"`
		SubmittedAt    string `json:"submitted_at"`
		CreatedAt      string `json:"created_at"`
		UpdatedAt      string `json:"updated_at"`
	} `json:"attributes"`
}

type LetterList

type LetterList struct {
	Data []LetterData `json:"data"`
}

type SendData

type SendData struct {
	Data struct {
		ID         string `json:"id"`
		Type       string `json:"type"`
		Attributes struct {
			DeliveryProduct string `json:"delivery_product"`
			PrintMode       string `json:"print_mode"`
			PrintSpectrum   string `json:"print_spectrum"`
		} `json:"attributes"`
	} `json:"data"`
}

type UploadData

type UploadData struct {
	Data struct {
		ID         string `json:"id"`
		Type       string `json:"type"`
		Attributes struct {
			URL          string `json:"url"`
			URLSignature string `json:"url_signature"`
			ExpiresAt    string `json:"expires_at"`
		} `json:"attributes"`
		Links struct {
			Self string `json:"self"`
		} `json:"links"`
	} `json:"data"`
}

Jump to

Keyboard shortcuts

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