2021-01-17 02:45:06 +00:00
|
|
|
package imgur
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Response struct {
|
|
|
|
Images []*Image `json:"data"`
|
|
|
|
Success bool `json:"success"`
|
|
|
|
Status int `json:"status"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Image struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
Title string `json:"title"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
Datetime int `json:"datetime"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
Animated bool `json:"animated"`
|
|
|
|
Width int `json:"width"`
|
|
|
|
Height int `json:"height"`
|
|
|
|
Size int `json:"size"`
|
|
|
|
Views int `json:"views"`
|
|
|
|
Bandwidth int `json:"bandwidth"`
|
|
|
|
Deletehash string `json:"deletehash"`
|
|
|
|
Section string `json:"section"`
|
|
|
|
Link string `json:"link"`
|
|
|
|
}
|
|
|
|
|
2021-05-14 02:54:38 +00:00
|
|
|
func Get(clientID, albumID string) ([]*Image, error) {
|
2021-01-17 02:45:06 +00:00
|
|
|
|
2021-05-14 02:54:38 +00:00
|
|
|
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("https://api.imgur.com/3/album/%s/images", albumID), nil)
|
2021-01-17 02:45:06 +00:00
|
|
|
if err != nil {
|
2021-05-14 02:54:38 +00:00
|
|
|
return nil, err
|
2021-01-17 02:45:06 +00:00
|
|
|
}
|
|
|
|
req.Header.Set("Authorization", fmt.Sprintf("Client-ID %s", clientID))
|
|
|
|
|
|
|
|
resp, err := http.DefaultClient.Do(req)
|
|
|
|
if err != nil {
|
2021-05-14 02:54:38 +00:00
|
|
|
return nil, err
|
2021-01-17 02:45:06 +00:00
|
|
|
}
|
2021-05-14 02:54:38 +00:00
|
|
|
defer resp.Body.Close()
|
2021-01-17 02:45:06 +00:00
|
|
|
|
|
|
|
var imgurResp Response
|
2021-05-14 02:54:38 +00:00
|
|
|
return imgurResp.Images, json.NewDecoder(resp.Body).Decode(&imgurResp)
|
2021-01-17 02:45:06 +00:00
|
|
|
}
|