Version: v0.0.0-...-263d293 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2017 License: GPL-3.0 Imports: 7 Imported by: 0




View Source
const (
	ThumbSmallSquare = "s" // 90x90
	ThumbBigSquare   = "b" // 160x160
	ThumbSmall       = "t" // 160x160
	ThumbMedium      = "m" // 320x320
	ThumbLarge       = "l" // 640x640
	ThumbHuge        = "h" // 1024x1024


This section is empty.


func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. API error responses are expected to have either no response body, or a JSON response body that maps to ErrorResponse. Any other response body will be silently ignored.


type Client

type Client struct {
	BaseURL *url.URL

	// User agent used when communicating with the imgur API.
	UserAgent string

	// Rate specifies the current rate limit for the client as determined by the
	// most recent API call.  If the client is used in a multi-user application,
	// this rate may not always be up-to-date.  Call RateLimit() to check the
	// current rate.
	Rate Rate

	// Services used for talking to different parts of the API.
	Gallery *GalleryService
	Image   *ImageService
	// contains filtered or unexported fields

func NewClient

func NewClient(httpClient *http.Client, apiId, apiSecret string) *Client

NewClient returns a new Imgur API client. If a nil httpClient is provided, http.DefaultClient will be used. To use API methods which require authentication, provide an http.Client that will perform the authentication for you (such as that provided by the goauth2 library).

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*Response, error)

Do sends an API request and returns the API response. The API response is decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

func (*Client) RateLimit

func (c *Client) RateLimit() (*Rate, *Response, error)

RateLimit returns the rate limit for the current client.

type ErrorResponse

type ErrorResponse struct {
	Data struct {
		Error   string `json:"error"`
		Request string `json:"request"`
		Method  string `json:"method"`
	Status  int
	Success bool

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

type GalleryImageAlbum

type GalleryImageAlbum struct {
	// Common fields
	ID           string `json:"id,omitempty"`
	Title        string `json:"title,omitempty"`
	Description  string `json:"description,omitempty"`
	DateTime     int    `json:"datetime,omitempty"`
	Views        int    `json:"views,omitempty"`
	Vote         string `json:"vote,omitempty"`
	Section      string `json:"section,omitempty"`
	AccountUrl   string `json:"account_url,omitempty"`
	Ups          int    `json:"ups,omitempty"`
	Downs        int    `json:"downs,omitempty"`
	Score        int    `json:"score,omitempty"`
	Link         string `json:"link,omitempty"`
	IsAlbum      bool   `json:"is_album,omitempty"`
	Nsfw         bool   `json:"nsfw,omitempty"`
	CommentCount int    `json:"comment_count,omitempty"`

	// Image only fields
	Bandwidth  int    `json:"bandwidth,omitempty"`
	DeleteHash string `json:"deletehash,omitempty"`
	Animated   bool   `json:"animated,omitempty"`
	MimeType   string `json:"type,omitempty"`
	Width      int    `json:"width,omitempty"`
	Height     int    `json:"height,omitempty"`
	Size       int    `json:"size,omitempty"`
	Gifv       string `json:"gifv,omitempty"`
	Webm       string `json:"webm,omitempty"`

	// Album only fields
	Cover       string  `json:"cover,omitempty"`
	CoverWidth  int     `json:"cover_width,omitempty"`
	CoverHeight int     `json:"cover_height,omitempty"`
	Privacy     string  `json:"privacy,omitempty"`
	Layout      string  `json:"layout,omitempty"`
	ImagesCount int     `json:"images_count,omitempty"`
	Images      []Image `json:"images,omitempty"`

Many of the Gallery endpoints return mixtures of GalleryImage and GalleryAlbum, and these two structs share many elements, so they are combined into a single struct. Test the IsAlbum field to determine which type an instance is.

type GalleryService

type GalleryService struct {
	// contains filtered or unexported fields

GalleryService handles communication with the gallery related methods of the Imgur API.

API docs:

func (*GalleryService) Main

func (s *GalleryService) Main(section, sort, window string, page int) ([]GalleryImageAlbum, error)

Returns the main gallery, as if the user had simply navigated to

func (*GalleryService) Memes

func (s *GalleryService) Memes(sort, window string, page int) ([]GalleryImageAlbum, error)

Returns the memes gallery (requires clientID & clientSecret)

func (*GalleryService) Random

func (s *GalleryService) Random(page int) ([]GalleryImageAlbum, error)

Random returns a random set of gallery images.

func (*GalleryService) Search

func (s *GalleryService) Search(q string, sort string, page int) ([]GalleryImageAlbum, error)

Search searches the gallery with a given query string.

func (*GalleryService) Subreddit

func (s *GalleryService) Subreddit(subreddit, sort, window string, page int) ([]GalleryImageAlbum, error)

Returns a subreddit gallery (requires clientID & clientSecret)

type Image

type Image struct {
	Id          string // The ID for the image
	Title       string // The title of the image.
	Description string // Description of the image.
	DateTime    int    // Time inserted into the gallery, epoch time
	MimeType    string // Image MIME type.
	Animated    bool   // is the image animated
	Width       int    // The width of the image in pixels
	Height      int    // The height of the image in pixels
	Size        int    // The size of the image in bytes
	Views       int    // The number of image views
	Bandwidth   int    // Bandwidth consumed by the image in bytes
	DeleteHash  string // OPTIONAL, the deletehash, if you're logged in as the image owner
	Section     string // If the image has been categorized by our backend then this will contain the section the image belongs in. (funny, cats, adviceanimals, wtf, etc)
	Link        string // The direct link to the the image
	Nsfw        bool   // Is the link safe for work
	Gifv        string
	Mp4         string
	Webm        string
	Looping     bool

type ImageService

type ImageService struct {
	// contains filtered or unexported fields

ImageService handles communication with the image related methods of the Imgur API.

API docs:

func (*ImageService) Info

func (s *ImageService) Info(id string) (*Image, error)

Info retrieves information about an image.

type Rate

type Rate struct {
	// The number of requests per hour the client is currently limited to.
	UserLimit int

	// The number of remaining requests the client can make this hour.
	UserRemaining int

	// The time at which the current rate limit will reset.
	UserReset time.Time

	// The number of requests allowed for your application this month.
	ClientLimit int

	// The number of remaining requests your application can make this month.
	ClientRemaining int

Rate represents the rate limit for the current client. Each application can allow approximately 1,250 uploads per day or approximately 12,500 requests per day.

type Response

type Response struct {

	NextPage  int
	PrevPage  int
	FirstPage int
	LastPage  int


Response is a Imgur API response. This wraps the standard http.Response returned from Imgur and provides convenient access to things like pagination links.

type Result

type Result struct {
	Status  int
	Success bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL