-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_storage.go
executable file
·98 lines (80 loc) · 2.75 KB
/
client_storage.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
package keboola
import (
"bytes"
"net/http"
)
const storageURL = "https://connection.keboola.com/v2/"
//Get request for a ProjectID
func (c *KBCClient) GetProjectID() (*http.Response, error) {
client := &http.Client{}
req, err := http.NewRequest("GET", "https://connection.keboola.com/v2/storage/tokens/verify", nil)
if err != nil {
return nil, err
}
req.Header.Set("X-StorageApi-Token", c.APIKey)
return client.Do(req)
}
// Update request for row storage
func (c *KBCClient) PutToRowStorage(endpoint string, formData *bytes.Buffer) (*http.Response, error) {
client := &http.Client{}
req, err := http.NewRequest("PUT", storageURL+endpoint, formData)
if err != nil {
return nil, err
}
req.Header.Set("X-StorageApi-Token", c.APIKey)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
return client.Do(req)
}
// Gets request for row storage
func (c *KBCClient) GetFromRowStorage(endpoint string) (*http.Response, error) {
client := &http.Client{}
req, err := http.NewRequest("GET", storageURL+endpoint, nil)
if err != nil {
return nil, err
}
req.Header.Add("content-type", "application/json")
req.Header.Set("X-StorageApi-Token", c.APIKey)
return client.Do(req)
}
//GetFromStorage requests an object from the Keboola Storage API.
func (c *KBCClient) GetFromStorage(endpoint string) (*http.Response, error) {
client := &http.Client{}
req, err := http.NewRequest("GET", storageURL+endpoint, nil)
if err != nil {
return nil, err
}
req.Header.Set("X-StorageApi-Token", c.APIKey)
return client.Do(req)
}
//PostToStorage posts a new object to the Keboola Storage API.
func (c *KBCClient) PostToStorage(endpoint string, formdata *bytes.Buffer) (*http.Response, error) {
client := &http.Client{}
req, err := http.NewRequest("POST", storageURL+endpoint, formdata)
if err != nil {
return nil, err
}
req.Header.Set("X-StorageApi-Token", c.APIKey)
req.Header.Add("content-type", "application/x-www-form-urlencoded")
return client.Do(req)
}
//PutToStorage puts an existing object to the Keboola Storage API for update.
func (c *KBCClient) PutToStorage(endpoint string, formData *bytes.Buffer) (*http.Response, error) {
client := &http.Client{}
req, err := http.NewRequest("PUT", storageURL+endpoint, formData)
if err != nil {
return nil, err
}
req.Header.Set("X-StorageApi-Token", c.APIKey)
req.Header.Add("content-type", "application/x-www-form-urlencoded")
return client.Do(req)
}
//DeleteFromStorage removes an existing object from the Keboola Storage API.
func (c *KBCClient) DeleteFromStorage(endpoint string) (*http.Response, error) {
client := &http.Client{}
req, err := http.NewRequest("DELETE", storageURL+endpoint, nil)
if err != nil {
return nil, err
}
req.Header.Set("X-StorageApi-Token", c.APIKey)
return client.Do(req)
}