This repository was archived by the owner on Dec 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsnapshots.go
More file actions
75 lines (60 loc) · 1.9 KB
/
snapshots.go
File metadata and controls
75 lines (60 loc) · 1.9 KB
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
package appoptics
import (
"fmt"
"time"
)
// Snapshot represents a portrait of a Chart at a specific point in time
type Snapshot struct {
Href string `json:"href,omitempty"`
JobHref string `json:"job_href,omitempty"`
ImageHref string `json:"image_href,omitempty"`
Duration int `json:"duration,omitempty"`
EndTime time.Time `json:"end_time,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
Subject map[string]SnapshotChart `json:"subject"`
}
// SnapshotChart contains the metadata for the chart requested in the Snapshot
type SnapshotChart struct {
ID int `json:"id"`
Sources []string `json:"sources"`
Type string `json:"type"`
}
type SnapshotsCommunicator interface {
Create(*Snapshot) (*Snapshot, error)
Retrieve(int) (*Snapshot, error)
}
type SnapshotsService struct {
client *Client
}
func NewSnapshotsService(c *Client) *SnapshotsService {
return &SnapshotsService{c}
}
// Create requests the creation of a new Snapshot for later retrieval
func (ss *SnapshotsService) Create(s *Snapshot) (*Snapshot, error) {
path := fmt.Sprintf("snapshots")
req, err := ss.client.NewRequest("POST", path, s)
if err != nil {
return nil, err
}
newSnapshot := &Snapshot{}
_, err = ss.client.Do(req, newSnapshot)
if err != nil {
return nil, err
}
return newSnapshot, nil
}
// Retrieve fetches data about a Snapshot, including a fully qualified URL for fetching the image asset itself
func (ss *SnapshotsService) Retrieve(id int) (*Snapshot, error) {
path := fmt.Sprintf("snapshots/%d", id)
req, err := ss.client.NewRequest("GET", path, nil)
if err != nil {
return nil, err
}
snapshot := &Snapshot{}
_, err = ss.client.Do(req, snapshot)
if err != nil {
return nil, err
}
return snapshot, nil
}