imgur

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2022 License: MIT Imports: 12 Imported by: 7

README

go-imgur

Go GoDoc Go Report Card Coverage Status

Go library to use the imgur.com API. At the moment only the anonymous part of the API is supported, but that is used in a production environment.

Example

To see some simple example code please take a look at the command line client found in imgurcmd/main.go.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlbumInfo

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
}

AlbumInfo contains all album information provided by imgur

type Client

type Client struct {
	Log klogger.KLogger
	// contains filtered or unexported fields
}

Client used to for go-imgur

func NewClient added in v0.4.0

func NewClient(httpClient *http.Client, clientID string, rapidAPIKey string) (*Client, error)

NewClient simply creates an imgur client. RapidAPIKEY is "" if you are using the free API.

func (*Client) GetAlbumInfo

func (client *Client) GetAlbumInfo(id string) (*AlbumInfo, int, error)

GetAlbumInfo queries imgur for information on a album returns album info, status code of the request, error

func (*Client) GetGalleryAlbumInfo

func (client *Client) GetGalleryAlbumInfo(id string) (*GalleryAlbumInfo, int, error)

GetGalleryAlbumInfo queries imgur for information on a gallery album returns album info, status code of the request, error

func (*Client) GetGalleryImageInfo

func (client *Client) GetGalleryImageInfo(id string) (*GalleryImageInfo, int, error)

GetGalleryImageInfo queries imgur for information on a image returns image info, status code of the request, error

func (*Client) GetImageInfo

func (client *Client) GetImageInfo(id string) (*ImageInfo, int, error)

GetImageInfo queries imgur for information on a image returns image info, status code of the request, error

func (*Client) GetInfoFromURL

func (client *Client) GetInfoFromURL(url string) (*GenericInfo, int, error)

GetInfoFromURL tries to query imgur based on information identified in the URL. returns image/album info, status code of the request, error

func (*Client) GetRateLimit

func (client *Client) GetRateLimit() (*RateLimit, error)

GetRateLimit returns the current rate limit without doing anything else

func (*Client) RefreshAccessToken added in v0.4.0

func (c *Client) RefreshAccessToken(refreshToken string, clientSecret string) (string, error)

RefreshAccessToken let you reissue expired access_token

func (*Client) UploadImage

func (client *Client) UploadImage(image []byte, album string, dtype string, title string, description string) (*ImageInfo, int, error)

UploadImage uploads the image to imgur image Can be a binary file, base64 data, or a URL for an image. (up to 10MB) album optional The id of the album you want to add the image to.

For anonymous albums, album should be the deletehash that is returned at creation.

dtype The type of the file that's being sent; file, base64 or URL title optional The title of the image. description optional The description of the image. returns image info, status code of the upload, error

func (*Client) UploadImageFromFile

func (client *Client) UploadImageFromFile(filename string, album string, title string, description string) (*ImageInfo, int, error)

UploadImageFromFile uploads a file given by the filename string to imgur.

type ClientAccount added in v0.4.0

type ClientAccount struct {
	// contains filtered or unexported fields
}

ClientAccount describe authontification

type Comment

type Comment struct {
	ID         int       `json:"id"`          // The ID for the comment
	ImageID    string    `json:"image_id"`    //The ID of the image that the comment is for
	Comment    string    `json:"comment"`     // The comment itself.
	Author     string    `json:"author"`      // Username of the author of the comment
	AuthorID   int       `json:"author_id"`   // The account ID for the author
	OnAlbum    bool      `json:"on_album"`    // If this comment was done to an album
	AlbumCover string    `json:"album_cover"` // The ID of the album cover image, this is what should be displayed for album comments
	Ups        int       `json:"ups"`         //	Number of upvotes for the comment
	Downs      int       `json:"downs"`       // The number of downvotes for the comment
	Points     float32   `json:"points"`      // the number of upvotes - downvotes
	Datetime   int       `json:"datetime"`    // Timestamp of creation, epoch time
	ParentID   int       `json:"parent_id"`   // If this is a reply, this will be the value of the comment_id for the caption this a reply for.
	Deleted    bool      `json:"deleted"`     // Marked true if this caption has been deleted
	Vote       string    `json:"vote"`        // The current user's vote on the comment. null if not signed in or if the user hasn't voted on it.
	Children   []Comment `json:"children"`    // All of the replies for this comment. If there are no replies to the comment then this is an empty set.
}

Comment is an imgur comment

type GalleryAlbumInfo

type GalleryAlbumInfo 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
	Ups          int         `json:"ups"`              // Upvotes for the image
	Downs        int         `json:"downs"`            // Number of downvotes for the image
	Points       int         `json:"points"`           // Upvotes minus downvotes
	Score        int         `json:"score"`            // Imgur popularity score
	IsAlbum      bool        `json:"is_album"`         // if it's an album or not
	Vote         string      `json:"vote"`             // The current user's vote on the album. null if not signed in or if the user hasn't voted on it.
	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.
	CommentCount int         `json:"comment_count"`    // Number of comments on the gallery album.
	Topic        string      `json:"topic"`            // Topic of the gallery album.
	TopicID      int         `json:"topic_id"`         // Topic ID of the gallery album.
	ImagesCount  int         `json:"images_count"`     // The total number of images in the album
	Images       []ImageInfo `json:"images,omitempty"` // An array of all the images in the album (only available when requesting the direct album)
	InMostViral  bool        `json:"in_most_viral"`    // Indicates if the album is in the most viral gallery or not.
	Limit        *RateLimit  // Current rate limit
}

GalleryAlbumInfo contains all information provided by imgur of a gallery album

type GalleryImageInfo

type GalleryImageInfo struct {
	ID           string     `json:"id"`                   // The ID for the image
	Title        string     `json:"title"`                // The title of the image.
	Description  string     `json:"description"`          // Description of the image.
	Datetime     int        `json:"datetime"`             // Time uploaded, epoch time
	MimeType     string     `json:"type"`                 // Image MIME type.
	Animated     bool       `json:"animated"`             // is the image animated
	Width        int        `json:"width"`                // The width of the image in pixels
	Height       int        `json:"height"`               // The height of the image in pixels
	Size         int        `json:"size"`                 // The size of the image in bytes
	Views        int        `json:"views"`                // The number of image views
	Bandwidth    int        `json:"bandwidth"`            // Bandwidth consumed by the image in bytes
	Deletehash   string     `json:"deletehash,omitempty"` // OPTIONAL, the deletehash, if you're logged in as the image owner
	Link         string     `json:"link"`                 // The direct link to the the image. (Note: if fetching an animated GIF that was over 20MB in original size, a .gif thumbnail will be returned)
	Gifv         string     `json:"gifv,omitempty"`       // OPTIONAL, The .gifv link. Only available if the image is animated and type is 'image/gif'.
	Mp4          string     `json:"mp4,omitempty"`        // OPTIONAL, The direct link to the .mp4. Only available if the image is animated and type is 'image/gif'.
	Mp4Size      int        `json:"mp4_size,omitempty"`   // OPTIONAL, The Content-Length of the .mp4. Only available if the image is animated and type is 'image/gif'. Note that a zero value (0) is possible if the video has not yet been generated
	Looping      bool       `json:"looping,omitempty"`    // OPTIONAL, Whether the image has a looping animation. Only available if the image is animated and type is 'image/gif'.
	Vote         string     `json:"vote"`                 // The current user's vote on the album. null if not signed in or if the user hasn't voted on it.
	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.
	CommentCount int        `json:"comment_count"`        // Number of comments on the gallery album.
	Topic        string     `json:"topic"`                // Topic of the gallery album.
	TopicID      int        `json:"topic_id"`             // Topic ID of the gallery album.
	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)
	AccountURL   string     `json:"account_url"`          // The username of the account that uploaded it, or null.
	AccountID    int        `json:"account_id"`           // The account ID of the account that uploaded it, or null.
	Ups          int        `json:"ups"`                  // Upvotes for the image
	Downs        int        `json:"downs"`                // Number of downvotes for the image
	Points       int        `json:"points"`               // Upvotes minus downvotes
	Score        int        `json:"score"`                // Imgur popularity score
	IsAlbum      bool       `json:"is_album"`             // if it's an album or not
	InMostViral  bool       `json:"in_most_viral"`        // Indicates if the album is in the most viral gallery or not.
	Limit        *RateLimit // Current rate limit
}

GalleryImageInfo contains all gallery image information provided by imgur

type GenerateAccessTokenRequest added in v0.4.0

type GenerateAccessTokenRequest struct {
	RefreshToken string `json:"refresh_token"` // The refresh token returned from the authorization code exchange
	ClientID     string `json:"client_id"`     // The client_id obtained during application registration
	ClientSecret string `json:"client_secret"` // The client secret obtained during application registration
	GrandType    string `json:"grant_type"`    // As defined in the OAuth2 specification, this field must contain a value of: refresh_token
}

type GenerateAccessTokenResponse added in v0.4.0

type GenerateAccessTokenResponse struct {
	AccessToken     string `json:"access_token"` // TNew access token to use
	ExpiresIn       uint64 `json:"expires_in"`   // These parameters describe the lifetime of the token in seconds, and the kind of token that is being returned
	TokenType       string `json:"token_type"`
	Scope           string `json:"scope,omitempty"`            // Scope which were provided earlier during creation access_token
	RefreshToken    string `json:"refresh_token"`              // New refresh token
	AccountID       int    `json:"account_id,omitempty"`       // not specified in documentation
	AccountUserName string `json:"account_username,omitempty"` // not specified in documentation
}

type GenericInfo

type GenericInfo struct {
	Image  *ImageInfo
	Album  *AlbumInfo
	GImage *GalleryImageInfo
	GAlbum *GalleryAlbumInfo
	Limit  *RateLimit
}

GenericInfo is returned from functions for which the final result type is not known beforehand. Only one pointer is != nil

type ImageInfo

type ImageInfo struct {
	ID          string     `json:"id"`                   // The ID for the image
	Title       string     `json:"title"`                // The title of the image.
	Description string     `json:"description"`          // Description of the image.
	Datetime    int        `json:"datetime"`             // Time uploaded, epoch time
	MimeType    string     `json:"type"`                 // Image MIME type.
	Animated    bool       `json:"animated"`             // is the image animated
	Width       int        `json:"width"`                // The width of the image in pixels
	Height      int        `json:"height"`               // The height of the image in pixels
	Size        int        `json:"size"`                 // The size of the image in bytes
	Views       int        `json:"views"`                // The number of image views
	Bandwidth   int        `json:"bandwidth"`            // Bandwidth consumed by the image in bytes
	Deletehash  string     `json:"deletehash,omitempty"` // OPTIONAL, the deletehash, if you're logged in as the image owner
	Name        string     `json:"name,omitempty"`       // OPTIONAL, the original filename, if you're logged in as the image owner
	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)
	Link        string     `json:"link"`                 // The direct link to the the image. (Note: if fetching an animated GIF that was over 20MB in original size, a .gif thumbnail will be returned)
	Gifv        string     `json:"gifv,omitempty"`       // OPTIONAL, The .gifv link. Only available if the image is animated and type is 'image/gif'.
	Mp4         string     `json:"mp4,omitempty"`        // OPTIONAL, The direct link to the .mp4. Only available if the image is animated and type is 'image/gif'.
	Mp4Size     int        `json:"mp4_size,omitempty"`   // OPTIONAL, The Content-Length of the .mp4. Only available if the image is animated and type is 'image/gif'. Note that a zero value (0) is possible if the video has not yet been generated
	Looping     bool       `json:"looping,omitempty"`    // OPTIONAL, Whether the image has a looping animation. Only available if the image is animated and type is 'image/gif'.
	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.
	Vote        string     `json:"vote"`                 // The current user's vote on the album. null if not signed in, if the user hasn't voted on it, or if not submitted to the gallery.
	InGallery   bool       `json:"in_gallery"`           // True if the image has been submitted to the gallery, false if otherwise.
	Limit       *RateLimit // Current rate limit
}

ImageInfo contains all image information provided by imgur

type RateLimit

type RateLimit struct {
	// Total credits that can be allocated.
	UserLimit int64
	// Total credits available.
	UserRemaining int64
	// Timestamp for when the credits will be reset.
	UserReset time.Time
	// Total credits that can be allocated for the application in a day.
	ClientLimit int64
	// Total credits remaining for the application in a day.
	ClientRemaining int64
}

RateLimit details can be found here: https://api.imgur.com/#limits

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL