-
Notifications
You must be signed in to change notification settings - Fork 0
/
photosets.go
292 lines (250 loc) · 9.11 KB
/
photosets.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
// Package implementing methods: flickr.photosets.*
package photosets
import (
"strconv"
"strings"
"github.com/masci/flickr"
)
type Photoset struct {
Id string `xml:"id,attr"`
Primary string `xml:"primary,attr"`
Secret string `xml:"secret,attr"`
Server string `xml:"server,attr"`
Farm string `xml:"farm,attr"`
Photos int `xml:"photos,attr"`
Videos int `xml:"videos,attr"`
NeedsInterstitial bool `xml:"needs_interstitial,attr"`
VisCanSeeSet bool `xml:"visibility_can_see_set,attr"`
CountViews int `xml:"count_views,attr"`
CountComments int `xml:"count_comments,attr"`
CanComment bool `xml:"can_comment,attr"`
DateCreate int `xml:"date_create,attr"`
DateUpdate int `xml:"date_update,attr"`
Title string `xml:"title"`
Description string `xml:"description"`
Url string `xml:"url,attr"`
Owner string `xml:"owner,attr"`
}
type Photo struct {
Id string `xml:"id,attr"`
Title string `xml:"title,attr"`
}
type PhotosetsListResponse struct {
flickr.BasicResponse
Photosets struct {
Page int `xml:"page,attr"`
Pages int `xml:"pages,attr"`
Perpage int `xml:"perpage,attr"`
Total int `xml:"total,attr"`
Items []Photoset `xml:"photoset"`
} `xml:"photosets"`
}
type PhotosetResponse struct {
flickr.BasicResponse
Set Photoset `xml:"photoset"`
}
type PhotosListResponse struct {
flickr.BasicResponse
Photoset struct {
Page int `xml:"page,attr"`
Pages int `xml:"pages,attr"`
Perpage int `xml:"perpage,attr"`
Total int `xml:"total,attr"`
Photos []Photo `xml:"photo"`
} `xml:"photoset"`
}
// Return the public sets belonging to the user with userId.
// If userId is not provided it defaults to the caller user but call needs to be authenticated.
// This method requires authentication to retrieve private sets.
func GetList(client *flickr.FlickrClient, authenticate bool, userId string, page int) (*PhotosetsListResponse, error) {
client.Init()
client.Args.Set("method", "flickr.photosets.getList")
if userId != "" {
client.Args.Set("user_id", userId)
}
// if not provided, flickr defaults this argument to 1
if page > 1 {
client.Args.Set("page", strconv.Itoa(page))
}
// perform authentication if requested
if authenticate {
client.OAuthSign()
} else {
client.ApiSign()
}
response := &PhotosetsListResponse{}
err := flickr.DoGet(client, response)
return response, err
}
// Add a photo to a photoset
// This method requires authentication with 'write' permission.
func AddPhoto(client *flickr.FlickrClient, photosetId, photoId string) (*flickr.BasicResponse, error) {
client.Init()
client.HTTPVerb = "POST"
client.Args.Set("method", "flickr.photosets.addPhoto")
client.Args.Set("photoset_id", photosetId)
client.Args.Set("photo_id", photoId)
client.OAuthSign()
response := &flickr.BasicResponse{}
err := flickr.DoPost(client, response)
return response, err
}
// Create a photoset specifying its primary photo
// This method requires authentication with 'write' permission.
func Create(client *flickr.FlickrClient, title, description, primaryPhotoId string) (*PhotosetResponse, error) {
client.Init()
client.HTTPVerb = "POST"
client.Args.Set("method", "flickr.photosets.create")
client.Args.Set("title", title)
client.Args.Set("description", description)
client.Args.Set("primary_photo_id", primaryPhotoId)
client.OAuthSign()
response := &PhotosetResponse{}
err := flickr.DoPost(client, response)
return response, err
}
// Delete a photoset
// This method requires authentication with 'write' permission.
func Delete(client *flickr.FlickrClient, photosetId string) (*flickr.BasicResponse, error) {
client.Init()
client.HTTPVerb = "POST"
client.Args.Set("method", "flickr.photosets.delete")
client.Args.Set("photoset_id", photosetId)
client.OAuthSign()
response := &flickr.BasicResponse{}
err := flickr.DoPost(client, response)
return response, err
}
// Remove a photo from a photoset
// This method requires authentication with 'write' permission.
func RemovePhoto(client *flickr.FlickrClient, photosetId, photoId string) (*flickr.BasicResponse, error) {
client.Init()
client.HTTPVerb = "POST"
client.Args.Set("method", "flickr.photosets.removePhoto")
client.Args.Set("photoset_id", photosetId)
client.Args.Set("photo_id", photoId)
client.OAuthSign()
response := &flickr.BasicResponse{}
err := flickr.DoPost(client, response)
return response, err
}
// Get the photos in a set
// This method requires authentication to retrieve photos from private sets
func GetPhotos(client *flickr.FlickrClient, authenticate bool, photosetId, ownerID string, page int) (*PhotosListResponse, error) {
client.Init()
client.Args.Set("method", "flickr.photosets.getPhotos")
client.Args.Set("photoset_id", photosetId)
// this argument is optional but increases query performances
if ownerID != "" {
client.Args.Set("user_id", ownerID)
}
// if not provided, flickr defaults this argument to 1
if page > 1 {
client.Args.Set("page", strconv.Itoa(page))
}
// sign the client for authentication and authorization
if authenticate {
client.OAuthSign()
} else {
client.ApiSign()
}
response := &PhotosListResponse{}
err := flickr.DoGet(client, response)
return response, err
}
// Edit set name and description
// This method requires authentication with 'write' permission.
func EditMeta(client *flickr.FlickrClient, photosetId, title, description string) (*flickr.BasicResponse, error) {
client.Init()
client.HTTPVerb = "POST"
client.Args.Set("method", "flickr.photosets.editMeta")
client.Args.Set("photoset_id", photosetId)
client.Args.Set("title", title)
if description != "" {
client.Args.Set("description", description)
}
client.OAuthSign()
response := &flickr.BasicResponse{}
err := flickr.DoPost(client, response)
return response, err
}
// Modify the photos in a photoset. Use this method to add, remove and re-order photos.
// This method requires authentication with 'write' permission.
func EditPhotos(client *flickr.FlickrClient, photosetId, primaryId string, photoIds []string) (*flickr.BasicResponse, error) {
client.Init()
client.HTTPVerb = "POST"
client.Args.Set("method", "flickr.photosets.editPhotos")
client.Args.Set("photoset_id", photosetId)
client.Args.Set("primary_photo_id", primaryId)
photos := strings.Join(photoIds, ",")
client.Args.Set("photo_ids", photos)
client.OAuthSign()
response := &flickr.BasicResponse{}
err := flickr.DoPost(client, response)
return response, err
}
// Gets information about a photoset.
// This method does not require authentication unless you want to access a private set
func GetInfo(client *flickr.FlickrClient, authenticate bool, photosetId, ownerID string) (*PhotosetResponse, error) {
client.Init()
client.Args.Set("method", "flickr.photosets.getInfo")
client.Args.Set("photoset_id", photosetId)
// this argument is optional but increases query performances
if ownerID != "" {
client.Args.Set("user_id", ownerID)
}
// sign the client for authentication and authorization
if authenticate {
client.OAuthSign()
} else {
client.ApiSign()
}
response := &PhotosetResponse{}
err := flickr.DoGet(client, response)
return response, err
}
// Set the order of photosets for the calling user.
// Any set IDs not given in the list will be set to appear at the end of the list, ordered by their IDs.
// This method requires authentication with 'write' permission.
func OrderSets(client *flickr.FlickrClient, photosetIds []string) (*flickr.BasicResponse, error) {
client.Init()
client.HTTPVerb = "POST"
client.Args.Set("method", "flickr.photosets.orderSets")
sets := strings.Join(photosetIds, ",")
client.Args.Set("photoset_ids", sets)
client.OAuthSign()
response := &flickr.BasicResponse{}
err := flickr.DoPost(client, response)
return response, err
}
// Remove multiple photos from a photoset.
// This method requires authentication with 'write' permission.
func RemovePhotos(client *flickr.FlickrClient, photosetId string, photoIds []string) (*flickr.BasicResponse, error) {
client.Init()
client.HTTPVerb = "POST"
client.Args.Set("method", "flickr.photosets.removePhotos")
client.Args.Set("photoset_id", photosetId)
photos := strings.Join(photoIds, ",")
client.Args.Set("photo_ids", photos)
client.OAuthSign()
response := &flickr.BasicResponse{}
err := flickr.DoPost(client, response)
return response, err
}
// Alias for EditPhotos
func ReorderPhotos(client *flickr.FlickrClient, photosetId, primaryId string, photoIds []string) (*flickr.BasicResponse, error) {
return EditPhotos(client, photosetId, primaryId, photoIds)
}
// Set photoset primary photo
// This method requires authentication with 'write' permission.
func SetPrimaryPhoto(client *flickr.FlickrClient, photosetId, primaryId string) (*flickr.BasicResponse, error) {
client.Init()
client.HTTPVerb = "POST"
client.Args.Set("method", "flickr.photosets.setPrimaryPhoto")
client.Args.Set("photoset_id", photosetId)
client.Args.Set("photo_id", primaryId)
client.OAuthSign()
response := &flickr.BasicResponse{}
err := flickr.DoPost(client, response)
return response, err
}