-
Notifications
You must be signed in to change notification settings - Fork 0
/
full_example.go
75 lines (61 loc) · 1.82 KB
/
full_example.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"context"
"os"
"time"
"github.com/goneup/go-pingen-sdk"
"github.com/joho/godotenv"
log "github.com/sirupsen/logrus"
)
func init() {
log.SetLevel(log.DebugLevel)
log.SetReportCaller(true)
}
func main() {
log.Info("Startup")
err := godotenv.Load(".env.dev")
if err != nil {
log.Fatal("Error loading .env file")
}
clientID := os.Getenv("CLIENT_ID")
clientSecret := os.Getenv("CLIENT_SECRET")
org := os.Getenv("PINGEN_ORG")
var c *pingen.Client
c, err = pingen.NewClient(clientID, clientSecret, false, org, context.Background())
if err != nil {
log.Fatalf("Init failed, error %w", err)
}
//retriving the current letter list
c.ListLetters()
//demo run
bytes, err := os.ReadFile("demo_mustermann.pdf")
if err != nil {
log.Fatal(err)
}
//test send
log.Info("Testing sending a letter")
createData := &pingen.CreateData{}
createData.Data.Attributes.FileOriginalName = "Testupload.pdf"
createData.Data.Attributes.AddressPosition = "left"
createData.Data.Attributes.AutoSend = false
result, _ := c.CreateLetter(bytes, createData)
time.Sleep(5 * time.Second) //wait until api catches up
//c.ListLetters()
c.GetLetter(result.Data.ID)
sendData := &pingen.SendData{}
sendData.Data.Attributes.DeliveryProduct = "cheap"
sendData.Data.Attributes.PrintMode = "simplex"
sendData.Data.Attributes.PrintSpectrum = "color"
//c.SendLetter(result.Data.ID, sendData)
c.GetLetter(result.Data.ID)
//test delete
log.Info("Testing create & delete")
createData = &pingen.CreateData{}
createData.Data.Attributes.FileOriginalName = "DeleteTest.pdf"
createData.Data.Attributes.AddressPosition = "left"
createData.Data.Attributes.AutoSend = false
result, _ = c.CreateLetter(bytes, createData)
time.Sleep(5 * time.Second) //wait until api catches up
c.GetLetter(result.Data.ID)
c.DeleteLetter(result.Data.ID)
}