-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocument.go
More file actions
82 lines (73 loc) · 2.28 KB
/
document.go
File metadata and controls
82 lines (73 loc) · 2.28 KB
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
76
77
78
79
80
81
82
package checkr
import (
"fmt"
"net/http"
"time"
)
// Document ...
// https://docs.checkr.com/#document
type Document struct {
ID string `json:"id"`
Object string `json:"object"`
CreatedAt time.Time `json:"created_at"`
DownloadURI string `json:"download_uri"`
Filesize int `json:"filesize"`
Filename string `json:"filename"`
Type string `json:"type"`
ContentType string `json:"content_type"`
}
// Documents ...
type Documents struct {
Document []Document `json:"data"`
Object string `json:"object"`
Count int `json:"count"`
}
// RetrieveDocument ...
func (c *Client) RetrieveDocument(documentID string) (*Document, error) {
// Handle Request
resp, err := c.R().SetResult(&Document{}).SetError(&ErrorResponse{}).Get("/documents/" + documentID)
if err != nil {
return nil, err
}
// Check for expected response
if resp.StatusCode() != http.StatusOK {
errResp := resp.Error().(*ErrorResponse)
err = fmt.Errorf("Checkr Error: %s", errResp.Error)
return nil, err
}
return resp.Result().(*Document), nil
}
// RetrieveCandidateDocuments ...
func (c *Client) RetrieveCandidateDocuments(candidateID string) (*Documents, error) {
// Handle Request
resp, err := c.R().SetResult(&Documents{}).SetError(&ErrorResponse{}).Get("/candidates/" + candidateID + "/documents/")
if err != nil {
return nil, err
}
// Check for expected response
if resp.StatusCode() != http.StatusOK {
errResp := resp.Error().(*ErrorResponse)
err = fmt.Errorf("Checkr Error: %s", errResp.Error)
return nil, err
}
return resp.Result().(*Documents), nil
}
// UploadCandidateDocumentFile ...
func (c *Client) UploadCandidateDocumentFile(candidateID, documentType, filepath string) (*Document, error) {
// f, err := os.Open(filepath)
// if err != nil {
// return nil, err
// }
// Handle Request
resp, err := c.R().SetQueryString("type="+documentType).SetFile("file", filepath).SetResult(&Document{}).SetError(&ErrorResponse{}).Post("/candidates/" + candidateID + "/documents")
if err != nil {
return nil, err
}
// Check for expected response
if resp.StatusCode() != http.StatusCreated {
errResp := resp.Error().(*ErrorResponse)
err = fmt.Errorf("Checkr Error: %s", errResp.Error)
return nil, err
}
return resp.Result().(*Document), nil
}