-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.go
131 lines (109 loc) · 3.9 KB
/
report.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package onfido
import (
"context"
"encoding/json"
"time"
)
// Supported report names, results, subresults, and variants
const (
ReportNameIdentity ReportName = "identity"
ReportNameDocument ReportName = "document"
ReportNameFacialSimilarity ReportName = "facial_similarity"
ReportNameStreetLevel ReportName = "street_level"
ReportNameProofOfAddress ReportName = "proof_of_address"
ReportResultClear ReportResult = "clear"
ReportResultConsider ReportResult = "consider"
ReportResultUnidentified ReportResult = "unidentified"
ReportSubResultClear ReportSubResult = "clear"
ReportSubResultRejected ReportSubResult = "rejected"
ReportSubResultSuspected ReportSubResult = "suspected"
ReportSubResultCaution ReportSubResult = "caution"
ReportVariantStandard ReportVariant = "standard"
ReportVariantKYC ReportVariant = "kyc"
ReportVariantVideo ReportVariant = "video"
)
// ReportName represents a report type name
type ReportName string
// ReportResult represents a report result
type ReportResult string
// ReportSubResult represents a report sub result
type ReportSubResult string
// ReportVariant represents a report variant
type ReportVariant string
// Report represents a report from the Onfido API
type Report struct {
ID string `json:"id,omitempty"`
Name ReportName `json:"name,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
Status string `json:"status,omitempty"`
Result ReportResult `json:"result,omitempty"`
SubResult ReportSubResult `json:"sub_result,omitempty"`
Variant ReportVariant `json:"variant,omitempty"`
Href string `json:"href,omitempty"`
Options map[string]interface{} `json:"options,omitempty"`
Breakdown Breakdowns `json:"breakdown,omitempty"`
Properties Properties `json:"properties,omitempty"`
}
// Reports represents a list of reports from the Onfido API
type Reports struct {
Reports []*Report `json:"reports"`
}
// GetReport retrieves a report for the provided check by its ID.
// see https://documentation.onfido.com/?shell#retrieve-report
func (c *Client) GetReport(ctx context.Context, checkID, id string) (*Report, error) {
req, err := c.newRequest("GET", "/checks/"+checkID+"/reports/"+id, nil)
if err != nil {
return nil, err
}
var resp Report
_, err = c.do(ctx, req, &resp)
return &resp, err
}
// ResumeReport resumes a paused report by its ID.
// see https://documentation.onfido.com/?shell#resume-report
func (c *Client) ResumeReport(ctx context.Context, checkID, id string) error {
req, err := c.newRequest("POST", "/checks/"+checkID+"/reports/"+id+"/resume", nil)
if err != nil {
return err
}
_, err = c.do(ctx, req, nil)
return err
}
// CancelReport cancels a report by its ID.
// see https://documentation.onfido.com/?shell#cancel-report
func (c *Client) CancelReport(ctx context.Context, checkID, id string) error {
req, err := c.newRequest("POST", "/checks/"+checkID+"/reports/"+id+"/cancel", nil)
if err != nil {
return err
}
_, err = c.do(ctx, req, nil)
return err
}
// ReportIter represents a document iterator
type ReportIter struct {
*iter
}
// Report returns the current item in the iterator as a Report.
func (i *ReportIter) Report() *Report {
return i.Current().(*Report)
}
// ListReports retrieves the list of reports for the provided check.
// see https://documentation.onfido.com/?shell#list-reports
func (c *Client) ListReports(checkID string) *ReportIter {
handler := func(body []byte) ([]interface{}, error) {
var r Reports
if err := json.Unmarshal(body, &r); err != nil {
return nil, err
}
values := make([]interface{}, len(r.Reports))
for i, v := range r.Reports {
values[i] = v
}
return values, nil
}
return &ReportIter{&iter{
c: c,
nextURL: "/checks/" + checkID + "/reports",
handler: handler,
}}
}