-
Notifications
You must be signed in to change notification settings - Fork 1
/
album.go
77 lines (65 loc) · 1.7 KB
/
album.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
package flickr
type AlbumPhoto struct {
Id string `json:"id"`
Title string `json:"title"`
Secret string `json:"secret"`
Server string `json:"server"`
Farm int `json:"farm"`
}
func (albumPhoto *AlbumPhoto) URLs() map[string]string {
return GenerateURLs(albumPhoto.Id, albumPhoto.Farm, albumPhoto.Secret, albumPhoto.Server, "jpg")
}
type Album struct {
Id string `json:"id"`
Title string `json:"title"`
Desc string `json:"desc"`
Primary string `json:"primary"`
Owner string `json:"owner"`
Photos []*AlbumPhoto `json:"photos"`
}
func (client *Client) Album(id string) (*Album, error) {
response, err := client.Request("photosets.getPhotos", Params{
"photoset_id": id,
})
if err != nil {
return nil, err
}
raw := &struct {
PhotoSet struct {
Id string `json:"id"`
Primary string `json:"primary"`
Owner string `json:"owner"`
Photos []*AlbumPhoto `json:"photo"`
} `json:"photoset"`
}{}
if err := Parse(response, raw); err != nil {
return nil, err
}
response, err = client.Request("photosets.getInfo", Params{
"photoset_id": id,
})
if err != nil {
return nil, err
}
info := &struct {
PhotoSet struct {
Title struct{
Content string `json:"_content"`
} `json:"title"`
Description struct{
Content string `json:"_content"`
} `json:"description"`
} `json:"photoset"`
}{}
if err := Parse(response, info); err != nil {
return nil, err
}
return &Album{
Id: raw.PhotoSet.Id,
Title: info.PhotoSet.Title.Content,
Desc: info.PhotoSet.Description.Content,
Primary: raw.PhotoSet.Primary,
Owner: raw.PhotoSet.Owner,
Photos: raw.PhotoSet.Photos,
}, nil
}