tumblr

package module
v0.0.0-...-e85a471 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2016 License: MIT Imports: 9 Imported by: 0

README

Tumblr

License MITGoDocBuild StatusCoverage Status

Installing

go get github.com/mattcunningham/gumblr

Creating a client

All Tumblr API calls will be made through the Tumblr type. To create a Tumblr client:

client := tumblr.New(
    "<Insert Consumer Key>",
    "<Insert Consumer Secret",
    "<Insert Oauth Key>",
    "<Insert Oauth Secret>"
)

A simple way to receive the necessary credentials is by accessing the Tumblr API console at https://api.tumblr.com/console.

Supported Methods

Blog Requests
client.BlogInfo("staff.tumblr.com")
client.BlogAvatar("staff.tumblr.com")
client.BlogAvatarAndSize("staff.tumblr.com", 24)
client.BlogLikes("staff.tumblr.com", make(map[string]string))
client.BlogFollowers("staff.tumblr.com", make(map[string]string))
client.BlogQueuedPosts("staff.tumblr.com", make(map[string]string))
client.BlogLikes("staff.tumblr.com", make(map[string]string))
Blog Actions
client.Post("staff.tumblr.com", make(map[string]string))
client.PostEdit("staff.tumblr.com", 12345, make(map[string]string))
client.PostReblog("staff.tumblr.com", 12344321, "r3bl0gk3y", make(map[string]string))
client.PostDelete("staff.tumblr.com", 4321234)
User Requests
client.UserInfo()
client.UserDashboard(make(map[string]string))
client.UserLikes(make(map[string]string))
client.UserFollowing(make(map[string]string))
User Actions
client.UserFollow("staff.tumblr.com")
client.UserUnfollow("staff.tumblr.com")
client.UserLike(1234431, "r3b10gk3y")
client.UserUnlike(4321234, "r3b10gk3y")

Tagged Posts

client.TaggedPosts("gifs", make(map[string]string))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlogAvatar

type BlogAvatar struct {
	AvatarURL string `json:"avatar_url"` // The URL of the avatar image.
}

/avatar — Retrieve a Blog Avatar

type BlogFollowers

type BlogFollowers struct {
	TotalUsers int `json:"total_users"` // The number of users currently following the blog
	Users      []struct {
		Name      string `json:"name"`      // The user's name on tumblr
		Following bool   `json:"following"` // Whether the caller is following the user
		URL       string `json:"url"`       // The URL of the user's primary blog
		Updated   int    `json:"updated"`   // The time of the user's most recent post, in seconds since the epoch
	} `json:"users"`
}

/followers — Retrieve a Blog's Followers

type BlogInfo

type BlogInfo struct {
	Blog struct {
		Title                string `json:"title"`                   // The display title of the blog
		PostCount            int    `json:"posts"`                   // The total number of posts to this blog
		Name                 string `json:"name"`                    // The short blog name that appears before tumblr.com in a standard blog hostname
		Updated              int    `json:"updated"`                 // The time of the most recent post, in seconds since the epoch
		Description          string `json:"description"`             // The blog's description
		Ask                  bool   `json:"ask"`                     // Indicates whether the blog allows questions
		AskAnon              bool   `json:"ask_anon"`                // Indicates whether the blog allows anonymous questions
		Likes                int    `json:"likes"`                   // Number of likes for this user
		IsBlockedFromPrimary bool   `json:"is_blocked_from_primary"` // Indicates whether this blog has been blocked by the calling user's primary blog
	} `json:"blog"`
}

/info — Retrieve Blog Info

type BlogList

type BlogList struct {
	Posts []Post `json:"posts"`
}

type BlogPosts

type BlogPosts struct {
	BlogInfo          // Each response includes a blog object that is the equivalent of an /info response.
	Posts      []Post `json:"posts"`
	TotalPosts int    `json:"total_posts"` // The total number of post available for this request, useful for paginating through results
}

/posts – Retrieve Published Posts

type Likes

type Likes struct {
	LikedPost  []Post `json:"liked_posts"` // An array of post objects (posts liked by the user)
	LikedCount int    `json:"liked_count"` // Total number of liked posts
}

/likes - Retrieve Blog's Likes

type Meta

type Meta struct {
	Status int    `json:"status"` // the 3-digit HTTP Status-Code (e.g., 200)
	Msg    string `json:"msg"`    // the HTTP Reason-Phrase (e.g., OK)
}

type Post

type Post struct {
	BlogName    string   `json:"blog_name"`    // The short name used to uniquely identify a blog
	ID          int      `json:"id"`           // The post's unique ID
	PostURL     string   `json:"post_url"`     // The location of the post
	Type        string   `json:"type"`         // The type of post
	Timestamp   int      `json:"timestamp"`    // The time of the post, in seconds since the epoch
	Date        string   `json:"date"`         // The GMT date and time of the post, as a string
	Format      string   `json:"format"`       // The post format: html or markdown
	ReblogKey   string   `json:"reblog_key"`   // The key used to reblog this post
	Tags        []string `json:"tags"`         // Tags applied to the post
	Bookmarklet bool     `json:"bookmarklet"`  // Indicates whether the post was created via the Tumblr bookmarklet
	Mobile      bool     `json:"mobile"`       // Indicates whether the post was created via mobile/email publishing
	SourceURL   string   `json:"source_url"`   // The URL for the source of the content (for quotes, reblogs, etc.)
	SourceTitle string   `json:"source_title"` // The title of the source site
	Liked       bool     `json:"liked"`        // Indicates if a user has already liked a post or not
	NoteCount   int      `json:"note_count"`   // Indicates total count of likes, reposts, etc...
	State       string   `json:"state"`        // Indicates the current state of the post
	// Text posts
	Title string `json:"title,omitempty"` // The optional title of the post
	Body  string `json:"body,omitempty"`  // The full post body
	// Photo posts
	Caption string `json:"caption,omitempty"` // The user-supplied caption
	Photos  []struct {
		Caption      string `json:"caption,omitempty"` // user supplied caption for the individual photo
		OriginalSize struct {
			Height int    `json:"height,omitempty"` // height of the image
			Width  int    `json:"width,omitempty"`  // width of the image
			URL    string `json:"url,omitempty"`    // location of the photo file
		} `json:"original_size,omitempty"`
		AlternateSizes []struct {
			Height int    `json:"height,omitempty"` // height of the photo
			Width  int    `json:"width,omitempty"`  // width of the photo
			URL    string `json:"url,omitempty"`    // Location of the photo file
		} `json:"alt_sizes,omitempty"` // alternate photo sizes
	} `json:"photos,omitempty"`
	// Quote posts
	Text   string `json:"text,omitempty"`   // The text of the quote
	Source string `json:"source,omitempty"` // Full HTML for the source of the quote
	// Link posts
	URL         string `json:"url,omitempty"`         // The link
	Author      string `json:"author,omitempty"`      // The author of the article the link points to
	Excerpt     string `json:"excerpt,omitempty"`     // An excerpt from the article the link points to
	Publisher   string `json:"publisher,omitempty"`   // The publisher of the article the link points to
	Description string `json:"description,omitempty"` // A user-supplied description
	// Chat posts
	Dialogue []struct {
		Name   string `json:"name,omitempty"`   // name of the speaker
		Label  string `json:"label,omitempty"`  // label of the speaker
		Phrase string `json:"phrase,omitempty"` // text
	} `json:"dialogue,omitempty"`
	// Audio posts
	AudioPlayer string `json:"player,omitempty"`       // HTML for embedding the audio player
	PlayCount   int    `json:"plays,omitempty"`        // Number of times the audio post has been played
	AlbumArt    string `json:"album_art,omitempty"`    // Location of the audio file's ID3 album art image
	Artist      string `json:"artist,omitempty"`       // The audio file's ID3 artist value
	Album       string `json:"album,omitempty"`        // The audio file's ID3 album value
	TrackName   string `json:"track_name,omitempty"`   // The audio file's ID3 title value
	TrackNumber int    `json:"track_number,omitempty"` // The audio file's ID3 track value
	Year        int    `json:"year,omitempty"`         // The audio file's ID3 year value
	// Video posts
	Player []struct {
		Width     int    `json:"width,omitempty"`      // the width of the video player
		EmbedCode string `json:"embed_code,omitempty"` // HTML for embedding the video player
	} `json:"player,omitempty"`
	// Answer posts
	AskingName string `json:"asking_name,omitempty"` // The blog name of the user asking the question
	AskingURL  string `json:"asking_url,omitempty"`  // The blog URL of the user asking the question
	Question   string `json:"question,omitempty"`    // The question being asked
	Answer     string `json:"answer,omitempty"`      // The answer given
}

type Response

type Response struct {
	Meta     Meta            `json:"meta"`     // HTTP response message
	Response json.RawMessage `json:"response"` // API-specific results
}

The following type corresponds to the response message

type Tumblr

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

func New

func New(consumerKey, consumerSecret, oauthKey, oauthSecret string) *Tumblr

This is the initialization method. An easy way to get the credentials is to access the interactive console: https://api.tumblr.com/console

func (Tumblr) BlogAvatar

func (api Tumblr) BlogAvatar(blogHostname string) []byte

This method returns a URL to a blog's avatar with default size 64 blogHostname - The standard or custom blog hostname (e.g., example.tumblr.com, example.com)

func (Tumblr) BlogAvatarAndSize

func (api Tumblr) BlogAvatarAndSize(blogHostname string, size int) []byte

This method returns a URL to a blog's avatar with a custom size blogHostname - The standard or custom blog hostname (e.g., example.tumblr.com, example.com) size - The size of the avatar (square, one value for both length and width).

Must be one of the values: 16, 24, 30, 40, 48, 64, 96, 128, 512

func (Tumblr) BlogFollowers

func (api Tumblr) BlogFollowers(blogHostname string, params map[string]string) BlogFollowers

This method retrieves a blog's followers blogHostname - The standard or custom blog hostname (e.g., example.tumblr.com, example.com) params - A map of the params that are included in this request. Possible parameters:

  • limit - The number of results to return. Default: 20 (1–20, inclusive)
  • offset - Liked post number to start at. Default: 0 (First follower)

func (Tumblr) BlogInfo

func (api Tumblr) BlogInfo(blogHostname string) BlogInfo

This method returns general information about the blog, such as the title, number of posts, and other high-level data. blogHostname - The standard or custom blog hostname (e.g., example.tumblr.com, example.com)

func (Tumblr) BlogLikes

func (api Tumblr) BlogLikes(blogHostname string, params map[string]string) Likes

This method can be used to retrieve the publicly exposed likes from a blog. blogHostname - The standard or custom blog hostname (e.g., example.tumblr.com, example.com) params - A map of the params that are included in this request. Possible parameters:

  • limit - The number of results to return. Default: 20 (1–20, inclusive)
  • offset - Liked post number to start at. Default: 0 (First post)
  • before - Retrieve posts liked before the specified timestamp. Default: None
  • after - Retrieve posts liked after the specified timestamp. Default: None

func (Tumblr) BlogPosts

func (api Tumblr) BlogPosts(blogHostname string, params map[string]string) BlogPosts

This method retrieves a list of a blog's published posts blogHostname - The standard or custom blog hostname (e.g., example.tumblr.com, example.com) params - A map of the params that are included in this request. Possible parameters:

  • type - The type of post to return. text, quote, link, answer, video, audio, photo, chat
  • id - A specific post ID
  • tag - Limits the response to posts with the specified tag
  • limit - The number of posts to return: 1–20, inclusive
  • offset - Post number to start at
  • reblog_info - Indicates whether to return reblog information (specify true or false)
  • notes_info - Indicates whether to return notes information (specify true or false).
  • filter - Specifies the post format to return, other than HTML (text or raw)

func (Tumblr) BlogQueuedPosts

func (api Tumblr) BlogQueuedPosts(blogHostname string, params map[string]string) BlogList

This method retrieves a list of a blog's queued posts. blogHostname - The standard or custom blog hostname (e.g., example.tumblr.com, example.com) params - A map of the params that are included in this request. Possible parameters:

  • offset - Post number to start at (Default: 0)
  • limit - The number of results to return: 1–20, inclusive.
  • filter - Specifies the post format to return, other than HTML (text or raw)

func (Tumblr) Post

func (api Tumblr) Post(blogHostname string, params map[string]string) Meta

This method is used to post a blog post to a blog blogHostname - The standard or custom blog hostname (e.g., example.tumblr.com, example.com) params - A map of the params that are included in this request. Possible parameters:

  • type - The type of post to create. Specify one of the following: text, photo, quote, link, chat, audio, video
  • state - The state of the post. Specify one of the following: published, draft, queue, private
  • tags - Comma-separated tags for this post
  • tweet - Manages the autotweet (if enabled) for this post: set to off for no tweet, or enter text to override the default tweet
  • date - The GMT date and time of the post, as a string
  • format - Sets the format type of post. Supported formats are: html & markdown
  • slug - Add a short text summary to the end of the post URL TEXT POSTS
  • title - The optional title of the post, HTML entities must be escaped
  • body - The full post body, HTML allowed PHOTO POSTS
  • caption - The user-supplied caption, HTML allowed
  • link - The "click-through URL" for the photo
  • source - The photo source URL
  • data - One or more image files (submit multiple times to create a slide show) QUOTE POSTS
  • quote - The full text of the quote, HTML entities must be escpaed
  • source - Cited source, HTML allowed LINK POSTS
  • title - The title of the page the link points to, HTML entities should be escaped.
  • url - The link
  • description - A user-supplied description, HTML allowed. CHAT POSTS
  • title - The title of the chat
  • conversation - The text of the conversation/chat, with dialogue labels (no HTML). AUDIO POSTS
  • caption - The user-supplied caption
  • external_url - The URL of the site that hosts the audio file (not tumblr)
  • data - An audio file VIDEO POSTS
  • caption - The user-supplied caption
  • embed - HTML embed code for the video
  • data - A video file

func (Tumblr) PostDelete

func (api Tumblr) PostDelete(blogHostname string, id int) Meta

This method is used to delete a blog post from a blog blogHostname - The standard or custom blog hostname (e.g., example.tumblr.com, example.com) id - The ID of the post to delete

func (Tumblr) PostEdit

func (api Tumblr) PostEdit(blogHostname string, id int, params map[string]string) Meta

This method is used to edit a blog post to a blog blogHostname - The standard or custom blog hostname (e.g., example.tumblr.com, example.com) id - The id of the blog post params - The list of possible parameters are listed above the Post method

func (Tumblr) PostReblog

func (api Tumblr) PostReblog(blogHostname string, id int, reblogKey string, params map[string]string) Meta

This method is used to reblog a blog post to a blog blogHostname - The standard or custom blog hostname (e.g., example.tumblr.com, example.com) id - The ID of the reblogged post reblogKey - The reblog key for the reblogged post – get the reblog key with a BlogPosts request params - The list of possible parameters are listed above the Post method, along with:

  • comment - A comment added to the reblogged post

func (Tumblr) TaggedPosts

func (api Tumblr) TaggedPosts(tag string, params map[string]string) []Post

This method is used to retrieve posts that are tagged with a specified tag. tag - The tag on the posts you'd like to retrieve. params - A map of the params that are included in this request. Possible parameters:

  • before - The timestamp of when you'd like to see posts before. If the Tag is a "featured" tag, use the "featured_timestamp" on the post object for pagination.
  • limit - The number of results to return: 1–20, inclusive
  • filter - Specifies the post format to return, other than HTML (text or raw)

func (Tumblr) UserDashboard

func (api Tumblr) UserDashboard(params map[string]string) BlogList

This method is used to retrieve the dashboard that matches the OAuth credentials submitted with the request. params - A map of the params that are included in this request. Possible parameters:

  • limit - The number of results to return: 1–20, inclusive
  • offset - Post number to start at
  • type - The type of post to return. text, photo, quote, link, chat, audio, video, answer
  • since_id - Return posts that have appeared after this ID
  • reblog_info - Indicates whether to return reblog information (specify true or false).
  • notes_info - Indicates whether to return notes information (specify true or false).

func (Tumblr) UserFollow

func (api Tumblr) UserFollow(followURL string) Meta

This method is used to follow a specific URL followURL - The url to follow, formatted (blogname.tumblr.com, blogname.com)

func (Tumblr) UserFollowing

func (api Tumblr) UserFollowing(params map[string]string) UserFollowing

This method is used to retrieve the blogs followed by the user whose OAuth credentials are submitted with the request. params - A map of the params that are included in this request. Possible parameters:

  • limit - The number of results to return. Default: 20 (1–20, inclusive)
  • offset - Liked post number to start at. Default: 0 (First post)

func (Tumblr) UserInfo

func (api Tumblr) UserInfo() UserInfo

This method is used to retrieve the user's account information that matches the OAuth credentials submitted with the request.

func (Tumblr) UserLike

func (api Tumblr) UserLike(id int, reblogKey string) Meta

This method is used to like a specific blog post id - The ID of the blog post to be liked reblogKey - The reblog key string

func (Tumblr) UserLikes

func (api Tumblr) UserLikes(params map[string]string) Likes

This method can be used to retrieve the publicly exposed likes from a blog. params - A map of the params that are included in this request. Possible parameters:

  • limit - The number of results to return. Default: 20 (1–20, inclusive)
  • offset - Liked post number to start at. Default: 0 (First post)
  • before - Retrieve posts liked before the specified timestamp. Default: None
  • after - Retrieve posts liked after the specified timestamp. Default: None

func (Tumblr) UserUnfollow

func (api Tumblr) UserUnfollow(unfollowURL string) Meta

This method is used to unfollow a specific URL unfollowURL - The url to unfollow, formatted (blogname.tumblr.com, blogname.com)

func (Tumblr) UserUnlike

func (api Tumblr) UserUnlike(id int, reblogKey string) Meta

This method is used to unlike a specific blog post id - The ID of the blog post to be unliked reblogKey - The reblog key string

type UserFollowing

type UserFollowing struct {
	TotalBlogs int `json:"total_blogs"` // The number of blogs the user is following
	Blogs      []struct {
		Name        string `json:"name"`        // the user name attached to the blog that's being followed
		URL         string `json:"url"`         // the URL of the blog that's being followed
		Updated     int    `json:"updated"`     // the time of the most recent post, in seconds since the epoch
		Title       string `json:"title"`       // the title of the blog
		Description string `json:"description"` // the description of the blog
	} `json:"blogs"`
}

/user/following

type UserInfo

type UserInfo struct {
	User struct {
		Following         int    `json:"following"`           // The number of blogs the user is following
		DefaultPostFormat string `json:"default_post_format"` // The default posting format - html, markdown or raw
		Name              string `json:"name"`                // The user's tumblr short name
		Likes             int    `json:"likes"`               // The total count of the user's likes
		Blogs             []struct {
			Name      string `json:"name"`      // the short name of the blog
			URL       string `json:"url"`       // the URL of the blog
			Title     string `json:"title"`     // the title of the blog
			Primary   bool   `json:"primary"`   // indicates if this is the user's primary blog
			Followers int    `json:"followers"` // total count of followers for this blog
			Tweet     string `json:"tweet"`     // indicate if posts are tweeted auto, Y, N
			Facebook  string `json:"facebook"`  // indicate if posts are sent to facebook Y, N
			Type      string `json:"type"`      // indicates whether a blog is public or private
		} `json:"blogs"` // Each item is a blog the user has permissions to post to
	} `json:"user"`
}

/user/info – Get a User's Information

Jump to

Keyboard shortcuts

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