-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.go
70 lines (61 loc) · 2.15 KB
/
scripts.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
package paperspace
import (
"net/http"
"time"
)
// ScriptsService manages Scripts for the Paperspace API.
// Paperspace API docs: https://paperspace.github.io/paperspace-node/scripts.html
type ScriptsService struct {
client *Client
}
// Scripts represents a Paperspace Script.
type Scripts struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
OwnerType string `json:"ownerType,omitempty"`
OwnerID string `json:"ownerId,omitempty"`
Description string `json:"description,omitempty"`
DtCreated time.Time `json:"dtCreated,omitempty"`
IsEnabled bool `json:"isEnabled,omitempty"`
RunOnce bool `json:"runOnce,omitempty"`
}
// ScriptsRequest represents a request to create a Paperspace Script.
type ScriptsRequest struct {
MachineID string `json:"machineId,omitempty"`
ScriptName string `json:"scriptName,omitempty"`
ScriptFile string `json:"scriptFile,omitempty"`
ScriptText string `json:"scriptText,omitempty"`
ScriptDescription string `json:"scriptDescription,omitempty"`
IsEnabled bool `json:"isEnabled,omitempty"`
RunOnce bool `json:"runOnce,omitempty"`
}
// Create creates a new Paperspace Script based on given parameters.
// https://paperspace.github.io/paperspace-node/scripts.html#.create
func (s *ScriptsService) Create(options *ScriptsRequest) (*Scripts, *Response, error) {
apiEndpoint := "scripts/createScript"
req, err := s.client.NewRequest(http.MethodPost, apiEndpoint, options)
if err != nil {
return nil, nil, err
}
scripts := new(Scripts)
resp, err := s.client.Do(req, scripts)
if err != nil {
return nil, resp, err
}
return scripts, resp, nil
}
// List lists all scripts from Paperspace.
// https://paperspace.github.io/paperspace-node/scripts.html#.list
func (s *ScriptsService) List() (*Scripts, *Response, error) {
apiEndpoint := "scripts/getScripts"
req, err := s.client.NewRequest(http.MethodGet, apiEndpoint, nil)
if err != nil {
return nil, nil, err
}
scriptsList := new(Scripts)
resp, err := s.client.Do(req, &scriptsList)
if err != nil {
return nil, resp, err
}
return scriptsList, resp, nil
}