forked from dkerwin/gini-api-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
69 lines (53 loc) · 1.78 KB
/
example_test.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
package giniapi_test
import (
"fmt"
"github.com/dkerwin/gini-api-go"
"log"
"os"
"time"
)
// Very simplistic example. You shoud have a lot more error handling in place
func ExampleNewClient() {
//////////////////////////////////
// Oauth2
//////////////////////////////////
// Setup api connection
api, err := giniapi.NewClient(&giniapi.Config{
ClientID: "MY_CLIENT_ID",
ClientSecret: "********",
Username: "user1",
Password: "secret",
Authentication: giniapi.UseOauth2,
})
if err != nil {
log.Panicf("Gini API login failed: %s", err)
}
// Read a PDF document
document, _ := os.Open("/tmp/invoice.pdf")
// Upload document to gini without doctype hint and user identifier
doc, _ := api.Upload(document, giniapi.UploadOptions{FileName: "invoice.pdf", PollTimeout: 10 * time.Second})
// Get extractions from our uploaded document
extractions, _ := doc.GetExtractions(false)
// Print IBAN
fmt.Printf("IBAN has been found: %s Woohoo!\n", extractions.GetValue("iban"))
//////////////////////////////////
// basic Auth
//////////////////////////////////
// Setup api connection
api, err = giniapi.NewClient(&giniapi.Config{
ClientID: "MY_CLIENT_ID",
ClientSecret: "********",
Authentication: giniapi.UseBasicAuth,
})
if err != nil {
log.Panicf("Gini API login failed: %s", err)
}
// Read a PDF document
document, _ = os.Open("/tmp/invoice.pdf")
// Upload document to gini without doctype hint and user identifier
doc, _ = api.Upload(document, giniapi.UploadOptions{FileName: "invoice.pdf", UserIdentifier: "user123", PollTimeout: 10 * time.Second})
// Get extractions from our uploaded document
extractions, _ = doc.GetExtractions(false)
// Print IBAN
fmt.Printf("IBAN has been found: %s Woohoo!\n", extractions.GetValue("iban"))
}