forked from masci/flickr
/
photos.go
152 lines (138 loc) · 4.61 KB
/
photos.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
package photos
import (
"github.com/denmark/flickr"
)
type PhotoInfo struct {
Id string `xml:"id,attr"`
Secret string `xml:"secret,attr"`
Server string `xml:"server,attr"`
Farm string `xml:"farm,attr"`
DateUploaded string `xml:"dateuploaded,attr"`
IsFavorite bool `xml:"isfavorite,attr"`
License string `xml:"license,attr"`
// NOTE: one less than safety level set on upload (ie, here 0 = safe, 1 = moderate, 2 = restricted)
// while on upload, 1 = safe, 2 = moderate, 3 = restricted
SafetyLevel int `xml:"safety_level,attr"`
Rotation int `xml:"rotation,attr"`
OriginalSecret string `xml:"originalsecret,attr"`
OriginalFormat string `xml:"originalformat,attr"`
Views int `xml:"views,attr"`
Media string `xml:"media,attr"`
Title string `xml:"title"`
Description string `xml:"description"`
Visibility struct {
IsPublic bool `xml:"ispublic,attr"`
IsFriend bool `xml:"isfriend,attr"`
IsFamily bool `xml:"isfamily,attr"`
} `xml:"visibility"`
Dates struct {
Posted string `xml:"posted,attr"`
Taken string `xml:"taken,attr"`
TakenGranularity string `xml:"takengranularity,attr"`
TakenUnknown string `xml:"takenunknown,attr"`
LastUpdate string `xml:"lastupdate,attr"`
} `xml:"dates"`
Permissions struct {
PermComment string `xml:"permcomment,attr"`
PermAdMeta string `xml:"permadmeta,attr"`
} `xml:"permissions"`
Editability struct {
CanComment string `xml:"cancomment,attr"`
CanAddMeta string `xml:"canaddmeta,attr"`
} `xml:"editability"`
PublicEditability struct {
CanComment string `xml:"cancomment,attr"`
CanAddMeta string `xml:"canaddmeta,attr"`
} `xml:"publiceditability"`
Usage struct {
CanDownload string `xml:"candownload,attr"`
CanBlog string `xml:"canblog,attr"`
CanPrint string `xml:"canprint,attr"`
CanShare string `xml:"canshare,attr"`
} `xml:"usage"`
Comments int `xml:"comments"`
// Notes XXX: not handled yet
// People XXX: not handled yet
// Tags XXX: not handled yet
// Urls XXX: not handled yet
}
type PhotoInfoResponse struct {
flickr.BasicResponse
Photo PhotoInfo `xml:"photo"`
}
type Size struct {
Label string `xml:"label,attr"`
Width string `xml:"width,attr"`
Height string `xml:"height,attr"`
Source string `xml:"source,attr"`
Url string `xml:"url,attr"`
Media string `xml:"media,attr"`
}
type PhotoSizes struct {
CanBlog string `xml:"canblog,attr"`
CanPrint string `xml:"canprint,attr"`
CanDownload string `xml:"candownload,attr"`
Sizes []Size `xml:"size"`
}
type PhotoSizesResponse struct {
flickr.BasicResponse
PhotoSizes PhotoSizes `xml:"sizes"`
}
// Delete a photo from Flickr
// This method requires authentication with 'delete' permission.
func Delete(client *flickr.FlickrClient, id string) (*flickr.BasicResponse, error) {
client.Init()
client.EndpointUrl = flickr.API_ENDPOINT
client.HTTPVerb = "POST"
client.Args.Set("method", "flickr.photos.delete")
client.Args.Set("photo_id", id)
client.OAuthSign()
response := &flickr.BasicResponse{}
err := flickr.DoPost(client, response)
return response, err
}
// Get information about a Flickr photo
func GetInfo(client *flickr.FlickrClient, id string, secret string) (*PhotoInfoResponse, error) {
client.Init()
client.EndpointUrl = flickr.API_ENDPOINT
client.HTTPVerb = "POST"
client.Args.Set("method", "flickr.photos.getInfo")
client.Args.Set("photo_id", id)
if secret != "" {
client.Args.Set("secret", secret)
}
client.OAuthSign()
response := &PhotoInfoResponse{}
err := flickr.DoPost(client, response)
return response, err
}
// Set date posted and date taken on a Flickr photo
// datePosted and dateTaken are optional and may be set to ""
func SetDates(client *flickr.FlickrClient, id string, datePosted string, dateTaken string) (*flickr.BasicResponse, error) {
client.Init()
client.EndpointUrl = flickr.API_ENDPOINT
client.HTTPVerb = "POST"
client.Args.Set("method", "flickr.photos.setDates")
client.Args.Set("photo_id", id)
if datePosted != "" {
client.Args.Set("date_posted", datePosted)
}
if dateTaken != "" {
client.Args.Set("date_taken", dateTaken)
}
client.OAuthSign()
response := &flickr.BasicResponse{}
err := flickr.DoPost(client, response)
return response, err
}
func GetSizes(client *flickr.FlickrClient, id string) (*PhotoSizesResponse, error) {
client.Init()
client.EndpointUrl = flickr.API_ENDPOINT
client.HTTPVerb = "POST"
client.Args.Set("method", "flickr.photos.getSizes")
client.Args.Set("photo_id", id)
client.OAuthSign()
response := &PhotoSizesResponse{}
err := flickr.DoPost(client, response)
return response, err
}