-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattachements.go
49 lines (39 loc) · 1.21 KB
/
attachements.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
package goqonto
import (
"context"
"fmt"
"net/http"
"time"
)
// transactionsBasePath Qonto API Attachments Endpoint
const attachmentsBasePath = "v2/attachments"
// AttachmentsService provides access to the attachements in Qonto API
type AttachmentsService service
// Attachment struct
// https://api-doc.qonto.eu/2.0/attachments/show-attachment-1
type Attachment struct {
ID string `json:"id"`
CreatedAt time.Time `json:"created_at"`
FileName string `json:"file_name"`
FileSize string `json:"file_size"`
FileContentType string `json:"file_content_type"`
URL string `json:"url"`
}
// attachmentsRoot root key in the JSON response for attachments
type attachmentsRoot struct {
Attachment *Attachment `json:"attachment"`
}
// Get Attachment
func (a *AttachmentsService) Get(ctx context.Context, id string) (*Attachment, *Response, error) {
path := fmt.Sprintf("%s/%s", attachmentsBasePath, id)
req, err := a.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
root := new(attachmentsRoot)
resp, err := a.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
}
return root.Attachment, resp, nil
}