-
Notifications
You must be signed in to change notification settings - Fork 0
/
shots.go
167 lines (152 loc) · 4.73 KB
/
shots.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
package dribbble
import (
"encoding/json"
"fmt"
"time"
)
// Shots instance
type Shots struct {
*Client
}
// ShotOut single schema
type ShotOut struct {
ID int `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
Width int `json:"width"`
Height int `json:"height"`
Images struct {
Hidpi interface{} `json:"hidpi"`
Normal string `json:"normal"`
Teaser string `json:"teaser"`
} `json:"images"`
PublishedAt time.Time `json:"published_at"`
UpdatedAt time.Time `json:"updated_at"`
HTMLURL string `json:"html_url"`
Animated bool `json:"animated"`
Tags []string `json:"tags"`
Attachments []struct {
ID int `json:"id"`
URL string `json:"url"`
ThumbnailURL string `json:"thumbnail_url"`
Size int `json:"size"`
ContentType string `json:"content_type"`
CreatedAt time.Time `json:"created_at"`
} `json:"attachments"`
Projects []struct {
ID int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
ShotsCount int `json:"shots_count"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
} `json:"projects"`
Team struct {
ID int `json:"id"`
Name string `json:"name"`
Login string `json:"login"`
HTMLURL string `json:"html_url"`
AvatarURL string `json:"avatar_url"`
Bio string `json:"bio"`
Location string `json:"location"`
Links struct {
Web string `json:"web"`
Twitter string `json:"twitter"`
} `json:"links"`
Type string `json:"type"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
} `json:"team"`
Video struct {
ID int `json:"id"`
Duration int `json:"duration"`
VideoFileName string `json:"video_file_name"`
VideoFileSize int `json:"video_file_size"`
Width int `json:"width"`
Height int `json:"height"`
Silent bool `json:"silent"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
URL string `json:"url"`
SmallPreviewURL string `json:"small_preview_url"`
LargePreviewURL string `json:"large_preview_url"`
XlargePreviewURL string `json:"xlarge_preview_url"`
} `json:"video"`
LowProfile bool `json:"low_profile"`
}
// PopularShotOut schema
type PopularShotOut struct {
ID int `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
Images struct {
Hidpi interface{} `json:"hidpi"`
Normal string `json:"normal"`
Teaser string `json:"teaser"`
} `json:"images"`
PublishedAt time.Time `json:"published_at"`
HTMLURL string `json:"html_url"`
Height int `json:"height"`
Width int `json:"width"`
}
// UpdateShotIn for updating shot
type UpdateShotIn struct {
Title string `json:"title"`
Description string `json:"description"`
Tags []string `json:"tags"`
}
// GetShots of authenticated user
func (c *Shots) GetShots() (out *[]ShotOut, err error) {
body, err := c.call("GET", "/user/shots", nil)
if err != nil {
return nil, err
}
defer body.Close()
err = json.NewDecoder(body).Decode(&out)
return
}
// GetPopularShots overall
// Note: This is available only to select applications with our approval
func (c *Shots) GetPopularShots() (out *[]PopularShotOut, err error) {
body, err := c.call("GET", "/popular_shots", nil)
if err != nil {
return nil, err
}
defer body.Close()
err = json.NewDecoder(body).Decode(&out)
return
}
// GetShot with given id
// This method returns only shots owned by the currently authenticated user
func (c *Shots) GetShot(id int) (out *ShotOut, err error) {
body, err := c.call("GET", fmt.Sprintf("/shots/%d", id), nil)
if err != nil {
return nil, err
}
defer body.Close()
err = json.NewDecoder(body).Decode(&out)
return
}
// UpdateShot with given id and payload
// Updating a shot requires the user to be authenticated with the upload scope
// The authenticated user must also own the shot
func (c *Shots) UpdateShot(id int, in *UpdateShotIn) (out *ShotOut, err error) {
body, err := c.call("PUT", fmt.Sprintf("/shots/%d", id), in)
if err != nil {
return nil, err
}
defer body.Close()
err = json.NewDecoder(body).Decode(&out)
return
}
// DeleteShot with given id
// Deleting a shot requires the user to be authenticated with the upload scope
// The authenticated user must also own the shot
func (c *Shots) DeleteShot(id int) error {
body, err := c.call("DELETE", fmt.Sprintf("/shots/%d", id), nil)
if err != nil {
return err
}
defer body.Close()
return nil
}