-
Notifications
You must be signed in to change notification settings - Fork 10
/
album.go
63 lines (56 loc) · 3.54 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
package imgur
import (
"encoding/json"
"errors"
"strconv"
"strings"
)
type albumInfoDataWrapper struct {
Ai *AlbumInfo `json:"data"`
Success bool `json:"success"`
Status int `json:"status"`
}
// AlbumInfo contains all album information provided by imgur
type AlbumInfo struct {
ID string `json:"id"` // The ID for the album
Title string `json:"title"` // The title of the album in the gallery
Description string `json:"description"` // The description of the album in the gallery
DateTime int `json:"datetime"` // Time inserted into the gallery, epoch time
Cover string `json:"cover"` // The ID of the album cover image
CoverWidth int `json:"cover_width"` // The width, in pixels, of the album cover image
CoverHeight int `json:"cover_height"` // The height, in pixels, of the album cover image
AccountURL string `json:"account_url"` // The account username or null if it's anonymous.
AccountID int `json:"account_id"` // The account ID or null if it's anonymous.
Privacy string `json:"privacy"` // The privacy level of the album, you can only view public if not logged in as album owner
Layout string `json:"layout"` // The view layout of the album.
Views int `json:"views"` // The number of album views
Link string `json:"link"` // The URL link to the album
Favorite bool `json:"favorite"` // Indicates if the current user favorited the image. Defaults to false if not signed in.
Nsfw bool `json:"nsfw"` // Indicates if the image has been marked as nsfw or not. Defaults to null if information is not available.
Section string `json:"section"` // If the image has been categorized by our backend then this will contain the section the image belongs in. (funny, cats, adviceanimals, wtf, etc)
Order int `json:"order"` // Order number of the album on the user's album page (defaults to 0 if their albums haven't been reordered)
Deletehash string `json:"deletehash,omitempty"` // OPTIONAL, the deletehash, if you're logged in as the album owner
ImagesCount int `json:"images_count"` // The total number of images in the album
Images []ImageInfo `json:"images"` // An array of all the images in the album (only available when requesting the direct album)
InGallery bool `json:"in_gallery"` // True if the image has been submitted to the gallery, false if otherwise.
Limit *RateLimit // Current rate limit
}
// GetAlbumInfo queries imgur for information on a album
// returns album info, status code of the request, error
func (client *Client) GetAlbumInfo(id string) (*AlbumInfo, int, error) {
body, rl, err := client.getURL("album/" + id)
if err != nil {
return nil, -1, errors.New("Problem getting URL for album info ID " + id + " - " + err.Error())
}
//client.Log.Debugf("%v\n", body)
dec := json.NewDecoder(strings.NewReader(body))
var alb albumInfoDataWrapper
if err := dec.Decode(&alb); err != nil {
return nil, -1, errors.New("Problem decoding json for albumID " + id + " - " + err.Error())
}
if !alb.Success {
return nil, alb.Status, errors.New("Request to imgur failed for albumID " + id + " - " + strconv.Itoa(alb.Status))
}
alb.Ai.Limit = rl
return alb.Ai, alb.Status, nil
}