-
Notifications
You must be signed in to change notification settings - Fork 23
/
compliance_documents.go
270 lines (248 loc) · 11.1 KB
/
compliance_documents.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
package plivo
import (
"bytes"
"fmt"
"io/ioutil"
"mime/multipart"
"net/http"
"os"
"reflect"
"strings"
"time"
)
type ComplianceDocumentService struct {
client *Client
}
type GetComplianceDocumentResponse struct {
APIID string `json:"api_id"`
DocumentID string `json:"document_id"`
EndUserID string `json:"end_user_id"`
DocumentTypeID string `json:"document_type_id"`
Alias string `json:"alias"`
FileName string `json:"file_name,omitempty"`
MetaInformation struct {
LastName string `json:"last_name,omitempty"`
FirstName string `json:"first_name,omitempty"`
DateOfBirth string `json:"date_of_birth,omitempty"`
AddressLine1 string `json:"address_line_1,omitempty"`
AddressLine2 string `json:"address_line_2,omitempty"`
City string `json:"city,omitempty"`
Country string `json:"country,omitempty"`
PostalCode string `json:"postal_code,omitempty"`
UniqueIdentificationNumber string `json:"unique_identification_number,omitempty"`
Nationality string `json:"nationality,omitempty"`
PlaceOfBirth string `json:"place_of_birth,omitempty"`
DateOfIssue string `json:"date_of_issue,omitempty"`
DateOfExpiration string `json:"date_of_expiration,omitempty"`
TypeOfUtility string `json:"type_of_utility,omitempty"`
BillingId string `json:"billing_id,omitempty"`
BillingDate string `json:"billing_date,omitempty"`
BusinessName string `json:"business_name,omitempty"`
TypeOfId string `json:"type_of_id,omitempty"`
SupportPhoneNumber string `json:"support_phone_number,omitempty"`
SupportEmail string `json:"support_email,omitempty"`
AuthorizedRepresentativeName string `json:"authorized_representative_name,omitempty"`
BillDate string `json:"bill_date,omitempty"`
BillId string `json:"bill_id,omitempty"`
UseCaseDescription string `json:"use_case_description,omitempty"`
} `json:"meta_information"`
CreatedAt string `json:"created_at"`
}
type ComplianceDocumentListParams struct {
Limit int `json:"limit,omitempty" url:"limit,omitempty"`
Offset int `json:"offset,omitempty" url:"offset,omitempty"`
EndUserID string `json:"end_user_id,omitempty" url:"end_user_id,omitempty"`
DocumentTypeID string `json:"document_type_id,omitempty" url:"document_type_id,omitempty"`
Alias string `json:"alias,omitempty" url:"alias,omitempty"`
}
type ListComplianceDocumentResponse struct {
APIID string `json:"api_id"`
Meta struct {
Limit int `json:"limit"`
Next string `json:"next"`
Offset int `json:"offset"`
Previous interface{} `json:"previous"`
TotalCount int `json:"total_count"`
} `json:"meta"`
Objects []struct {
CreatedAt time.Time `json:"created_at"`
ComplianceDocumentID string `json:"compliance_document_id"`
Alias string `json:"alias"`
MetaInformation struct {
LastName string `json:"last_name,omitempty"`
FirstName string `json:"first_name,omitempty"`
DateOfBirth string `json:"date_of_birth,omitempty"`
AddressLine1 string `json:"address_line_1,omitempty"`
AddressLine2 string `json:"address_line_2,omitempty"`
City string `json:"city,omitempty"`
Country string `json:"country,omitempty"`
PostalCode string `json:"postal_code,omitempty"`
UniqueIdentificationNumber string `json:"unique_identification_number,omitempty"`
Nationality string `json:"nationality,omitempty"`
PlaceOfBirth string `json:"place_of_birth,omitempty"`
DateOfIssue string `json:"date_of_issue,omitempty"`
DateOfExpiration string `json:"date_of_expiration,omitempty"`
TypeOfUtility string `json:"type_of_utility,omitempty"`
BillingId string `json:"billing_id,omitempty"`
BillingDate string `json:"billing_date,omitempty"`
BusinessName string `json:"business_name,omitempty"`
TypeOfId string `json:"type_of_id,omitempty"`
SupportPhoneNumber string `json:"support_phone_number,omitempty"`
SupportEmail string `json:"support_email,omitempty"`
AuthorizedRepresentativeName string `json:"authorized_representative_name,omitempty"`
BillDate string `json:"bill_date,omitempty"`
BillId string `json:"bill_id,omitempty"`
UseCaseDescription string `json:"use_case_description,omitempty"`
} `json:"meta_information"`
File string `json:"file,omitempty"`
EndUserID string `json:"end_user_id"`
DocumentTypeID string `json:"document_type_id"`
} `json:"objects"`
}
type CreateComplianceDocumentParams struct {
File string `json:"file,omitempty"`
EndUserID string `json:"end_user_id,omitempty"`
DocumentTypeID string `json:"document_type_id,omitempty"`
Alias string `json:"alias,omitempty"`
LastName string `json:"last_name,omitempty"`
FirstName string `json:"first_name,omitempty"`
DateOfBirth string `json:"date_of_birth,omitempty"`
AddressLine1 string `json:"address_line_1,omitempty"`
AddressLine2 string `json:"address_line_2,omitempty"`
City string `json:"city,omitempty"`
Country string `json:"country,omitempty"`
PostalCode string `json:"postal_code,omitempty"`
UniqueIdentificationNumber string `json:"unique_identification_number,omitempty"`
Nationality string `json:"nationality,omitempty"`
PlaceOfBirth string `json:"place_of_birth,omitempty"`
DateOfIssue string `json:"date_of_issue,omitempty"`
DateOfExpiration string `json:"date_of_expiration,omitempty"`
TypeOfUtility string `json:"type_of_utility,omitempty"`
BillingId string `json:"billing_id,omitempty"`
BillingDate string `json:"billing_date,omitempty"`
BusinessName string `json:"business_name,omitempty"`
TypeOfId string `json:"type_of_id,omitempty"`
SupportPhoneNumber string `json:"support_phone_number,omitempty"`
SupportEmail string `json:"support_email,omitempty"`
AuthorizedRepresentativeName string `json:"authorized_representative_name,omitempty"`
BillDate string `json:"bill_date,omitempty"`
BillId string `json:"bill_id,omitempty"`
UseCaseDescription string `json:"use_case_description,omitempty"`
}
type UpdateComplianceDocumentParams struct {
ComplianceDocumentID string `json:"compliance_document_id"`
CreateComplianceDocumentParams
}
type UpdateComplianceDocumentResponse BaseResponse
func (service *ComplianceDocumentService) Get(complianceDocumentId string) (response *GetComplianceDocumentResponse, err error) {
req, err := service.client.NewRequest("GET", nil, "ComplianceDocument/%s", complianceDocumentId)
if err != nil {
return
}
response = &GetComplianceDocumentResponse{}
err = service.client.ExecuteRequest(req, response)
return
}
func (service *ComplianceDocumentService) List(params ComplianceDocumentListParams) (response *ListComplianceDocumentResponse, err error) {
request, err := service.client.NewRequest("GET", params, "ComplianceDocument")
if err != nil {
return
}
response = &ListComplianceDocumentResponse{}
err = service.client.ExecuteRequest(request, response)
return
}
func newfileUploadRequest(uri string, params map[string]string, paramName, path string) (*http.Request, error) {
body := new(bytes.Buffer)
writer := multipart.NewWriter(body)
if path != "" {
file, err := os.Open(path)
if err != nil {
return nil, err
}
fileContents, err := ioutil.ReadAll(file)
if err != nil {
return nil, err
}
fi, err := file.Stat()
if err != nil {
return nil, err
}
file.Close()
part, err := writer.CreateFormFile(paramName, fi.Name())
if err != nil {
return nil, err
}
if _, err := part.Write(fileContents); err != nil {
return nil, err
}
}
for key, val := range params {
_ = writer.WriteField(key, val)
}
err := writer.Close()
if err != nil {
return nil, err
}
request, err := http.NewRequest("POST", uri, body)
if err != nil {
return request, err
}
request.Header.Set("Content-Type", writer.FormDataContentType())
return request, nil
}
func (service *ComplianceDocumentService) Create(params CreateComplianceDocumentParams) (response *GetComplianceDocumentResponse, err error) {
requestUrl := service.client.BaseUrl
requestUrl.Path = fmt.Sprintf(baseRequestString, fmt.Sprintf(service.client.AuthId+"/ComplianceDocument"))
requestParams := make(map[string]string)
fields := reflect.TypeOf(params)
values := reflect.ValueOf(params)
num := fields.NumField()
for i := 0; i < num; i++ {
field := strings.Split(fields.Field(i).Tag.Get("json"), ",")[0]
value := values.Field(i)
if field != "file" {
requestParams[field] = value.String()
}
}
request, err := newfileUploadRequest(requestUrl.String(), requestParams, "file", params.File)
//request, err := service.client.NewRequest("POST", params, "ComplianceDocument/")
if err != nil {
return
}
request.SetBasicAuth(service.client.AuthId, service.client.AuthToken)
response = &GetComplianceDocumentResponse{}
err = service.client.ExecuteRequest(request, response)
return
}
func (service *ComplianceDocumentService) Update(params UpdateComplianceDocumentParams) (response *UpdateComplianceDocumentResponse, err error) {
requestUrl := service.client.BaseUrl
requestUrl.Path = fmt.Sprintf(baseRequestString, fmt.Sprintf(service.client.AuthId+"/ComplianceDocument/"+params.ComplianceDocumentID))
requestParams := make(map[string]string)
fields := reflect.TypeOf(params)
values := reflect.ValueOf(params)
num := fields.NumField()
for i := 0; i < num; i++ {
field := strings.Split(fields.Field(i).Tag.Get("json"), ",")[0]
value := values.Field(i)
if field != "file" {
requestParams[field] = value.String()
}
}
request, err := newfileUploadRequest(requestUrl.String(), requestParams, "file", params.File)
if err != nil {
return
}
request.SetBasicAuth(service.client.AuthId, service.client.AuthToken)
response = &UpdateComplianceDocumentResponse{}
err = service.client.ExecuteRequest(request, response)
return
}
func (service *ComplianceDocumentService) Delete(complianceDocumentId string) (err error) {
req, err := service.client.NewRequest("DELETE", nil, "ComplianceDocument/%s", complianceDocumentId)
if err != nil {
return
}
err = service.client.ExecuteRequest(req, nil)
return
}