gotumblr

package module
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

README

gotumblr

GoDoc Go Report Card

This is a fork of gotumblr by Maria Terzieva. A Go Tumblr API v2 Client.

func main() {
	t := gotumblr.New("consumerKey", "consumerSecret", "accessToken", "accessTokenSecret")
	info, err := t.Info()
	if err != nil {
		return log.Fatal(err)
	}
	info, err := t.Info()
	if err != nil {
		return log.Fatal(err)
	}
	fmt.Pritnf("Hello %s!", info.User)
}

Caching

You can use gotumblr.SetClient and gotumblr.SetHeaders to cache responses with something like httpcache.

func main() {
	t = gotumblr.New("consumerKey", "consumerSecret", "accessToken", "accessTokenSecret",
		gotumblr.SetClient(httpcache.NewTransport(diskcache.New("cache"))),
		gotumblr.SetHeaders(map[string]string{"cache-control": "max-stale=60"}),
	)

	// ...
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AltSize

type AltSize struct {
	Width  int64  `json:"width"`
	Height int64  `json:"height"`
	URL    string `json:"url"`
}

type AnswerPost

type AnswerPost struct {
	BasePost
	AskingName string `json:"asking_name"`
	AskingURL  string `json:"asking_url"`
	Question   string `json:"question"`
	Answer     string `json:"answer"`
}

type AudioPost

type AudioPost struct {
	BasePost
	Caption     string `json:"caption"`
	Player      string `json:"player"`
	Plays       int64  `json:"plays"`
	AlbumArt    string `json:"album_art"`
	Artist      string `json:"artist"`
	Album       string `json:"album"`
	TrackName   string `json:"track_name"`
	TrackNumber int64  `json:"track_number"`
	Year        int64  `json:"year"`
}

type AvatarResponse

type AvatarResponse struct {
	AvatarURL string `json:"avatar_url"`
}

type BasePost

type BasePost struct {
	BlogName                string        `json:"blog_name"`
	ID                      json.Number   `json:"id"`
	PostURL                 string        `json:"post_url"`
	PostType                string        `json:"type"`
	Timestamp               int64         `json:"timestamp"`
	Date                    string        `json:"date"`
	Format                  string        `json:"format"`
	ReblogKey               string        `json:"reblog_key"`
	Tags                    []string      `json:"tags"`
	Bookmarklet             bool          `json:"bookmarklet"`
	Mobile                  bool          `json:"mobile"`
	SourceURL               string        `json:"source_url"`
	SourceTitle             string        `json:"source_title"`
	Liked                   bool          `json:"liked"`
	State                   string        `json:"state"`
	TotalPosts              int64         `json:"total_posts"`
	NoteCount               int64         `json:"note_count"`
	Notes                   []Note        `json:"notes"`
	Reblog                  ReblogComment `json:"reblog"`
	RebloggedFromID         json.Number   `json:"reblogged_from_id"`
	RebloggedFromURL        string        `json:"reblogged_from_url"`
	RebloggedFromName       string        `json:"reblogged_from_name"`
	RebloggedFromTitle      string        `json:"reblogged_from_title"`
	RebloggedFromUUID       string        `json:"reblogged_from_uuid"`
	RebloggedFromCanMessage bool          `json:"reblogged_from_can_message"`
	RebloggedRootID         json.Number   `json:"reblogged_root_id"`
	RebloggedRootURL        string        `json:"reblogged_root_url"`
	RebloggedRootName       string        `json:"reblogged_root_name"`
	RebloggedRootTitle      string        `json:"reblogged_root_title"`
	RebloggedRootUUID       string        `json:"reblogged_root_uuid"`
	RebloggedRootCanMessage bool          `json:"reblogged_root_can_message"`
}

type BlogInfo

type BlogInfo struct {
	Title       string `json:"title"`
	Posts       int64  `json:"posts"`
	Name        string `json:"name"`
	URL         string `json:"url"`
	Updated     int64  `json:"updated"`
	Description string `json:"description"`
	Ask         bool   `json:"ask"`
	AskAnon     bool   `json:"ask_anon"`
	Likes       int64  `json:"likes"`
}

type BlogInfoResponse

type BlogInfoResponse struct {
	Blog BlogInfo `json:"blog"`
}

type ChatPost

type ChatPost struct {
	BasePost
	Title    string         `json:"title"`
	Body     string         `json:"body"`
	Dialogue []DialogueInfo `json:"dialogue"`
}

type Client

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

Client defines a Go Client for the Tumblr API.

func New

func New(consumerKey, consumerSecret, oauthToken, oauthSecret string, setters ...Setter) *Client

New initializes the Client. consumerKey is the consumer key of your Tumblr Application. consumerSecret is the consumer secret of your Tumblr Application. oauthToken is the user specific token, received from the /access_token endpoint. oauthSecret is the user specific secret, received from the /access_token endpoint. host is the host that you are tryng to send information to (e.g. https://api.tumblr.com).

func (*Client) Avatar

func (c *Client) Avatar(blogname string, size int) (AvatarResponse, error)

Avatar retrieves the url of the blog's avatar. size can be: 16, 24, 30, 40, 48, 64, 96, 128 or 512.

func (*Client) BlogInfo

func (c *Client) BlogInfo(blogname string) (BlogInfoResponse, error)

BlogInfo gets general information about the blog. blogname: name of the blog you want to get information about(e.g. mgterzieva.tumblr.com).

func (*Client) BlogLikes

func (c *Client) BlogLikes(blogname string, options url.Values) (LikesResponse, error)

BlogLikes gets the likes of blog given. blogname: name of the blog whose likes you want to get. options can be: limit: how many likes do you want to get; offset: the number of the like you want to start from.

func (*Client) CreateAudio

func (c *Client) CreateAudio(blogname string, options url.Values) error

CreateAudio creates an audio post on a blog. blogname: the url of the blog you want to post to. options can be: (with * are marked required options) state: the state of the post(e.g. published, draft, queue, private); tags: a list of tags you want applied to the post; tweet: manages the autotweet 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 the post(html or markdown); slug: add a short text summary to the end of the post url; caption: the caption of the post; *externalURL: the url of the site that hosts the audio file.

func (*Client) CreateChatPost

func (c *Client) CreateChatPost(blogname string, options url.Values) error

CreateChatPost creates a chat post on a blog. blogname: the url of the blog you want to post to. options can be: (with * are marked required options) state: the state of the post(e.g. published, draft, queue, private); tags: a list of tags you want applied to the post; tweet: manages the autotweet 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 the post(html or markdown); slug: add a short text summary to the end of the post url; title: the title of the chat; *conversation: the text of the conversation/chat, with dialogue labels.

func (c *Client) CreateLink(blogname string, options url.Values) error

CreateLink creates a link post on a blog. blogname: the url of the blog you want to post to. options can be: (with * are marked required options) state: the state of the post(e.g. published, draft, queue, private); tags: a list of tags you want applied to the post; tweet: manages the autotweet 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 the post(html or markdown); slug: add a short text summary to the end of the post url; title: the title of the page the link points to; *url: the link you are posting; description: the description of the link you are posting.

func (*Client) CreatePhoto

func (c *Client) CreatePhoto(blogname string, options url.Values) error

CreatePhoto creates a photo post or photoset on a blog. blogname: the url of the blog you want to post to. options can be: (with * are marked required options) state: the state of the post(e.g. published, draft, queue, private); tags: a list of tags you want applied to the post; tweet: manages the autotweet 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 the post(html or markdown); slug: add a short text summary to the end of the post url; caption: the caption that you want applied to the photo; link: the 'click-through' url for the photo; *source: the photo source url.

func (*Client) CreateQuote

func (c *Client) CreateQuote(blogname string, options url.Values) error

CreateQuote creates a quote post on a blog. blogname: the url of the blog you want to post to. options can be: (with * are marked required options) state: the state of the post(e.g. published, draft, queue, private); tags: a list of tags you want applied to the post; tweet: manages the autotweet 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 the post(html or markdown); slug: add a short text summary to the end of the post url; *quote: the full text of the quote; source: the cited source of the quote.

func (*Client) CreateText

func (c *Client) CreateText(blogname string, options url.Values) error

CreateText creates a text post on a blog. blogname: the url of the blog you want to post to. options can be: (with * are marked required options) state: the state of the post(e.g. published, draft, queue, private); tags: a list of tags you want applied to the post; tweet: manages the autotweet 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 the post(html or markdown); slug: add a short text summary to the end of the post url; title: the optional title of the post; *body: the full text body.

func (*Client) CreateVideo

func (c *Client) CreateVideo(blogname string, options url.Values) error

CreateVideo creates a video post on a blog. blogname: the url of the blog you want to post to. options can be: (with * are marked required options) state: the state of the post(e.g. published, draft, queue, private); tags: a list of tags you want applied to the post; tweet: manages the autotweet 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 the post(html or markdown); slug: add a short text summary to the end of the post url; caption: the caption for the post; *embed: the html embed code for the video.

func (*Client) Dashboard

func (c *Client) Dashboard(options url.Values) (DraftsResponse, error)

Dashboard gets the dashboard of the user. options can be: limit: number of results to return; offset: post number to start at; type: the type of posts to return(text, photo, quote, link, chat, audio, video, answer); sinceID: return posts that have apeared after this id; reblog_info: whether to return reblog information about the posts; notes_info: whether to return notes information about the posts.

func (*Client) DeletePost

func (c *Client) DeletePost(blogname, id string) error

DeletePost deletes a post with a given id. blogname: the url of the blog you want to delete from. id: the id of the post you want to delete.

func (*Client) Drafts

func (c *Client) Drafts(blogname string, options url.Values) (DraftsResponse, error)

Drafts gets posts that are currently in the blog's drafts. options can be: filter: specify posts' format(e.g. format="html", format="text", format="raw").

func (*Client) EditPost

func (c *Client) EditPost(blogname string, options url.Values) error

EditPost edits a post with a given id. blogname: the url of the blog you want to post to. options can be: (with * are marked required options) tags: a list of tags you want applied to the post; tweet: manages the autotweet 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 the post(html or markdown); slug: add a short text summary to the end of the post url; *id: the id of the post. The other options are specific to the type of post you want to edit.

func (*Client) Follow

func (c *Client) Follow(blogname string) error

Follow the url of a given blog. blogname: the url of the blog to follow.

func (*Client) Followers

func (c *Client) Followers(blogname string, options url.Values) (FollowersResponse, error)

Followers gets the followers of the blog given. blogname: name of the blog whose followers you want to get. optons can be: limit: the number of results to return, inclusive; offset: result to start at.

func (*Client) Following

func (c *Client) Following(options url.Values) (FollowingResponse, error)

Following gets the blogs that the user is following. options can be: limit: the number of results to return; offset: result number to start at.

func (*Client) Get

func (c *Client) Get(requestURL string, values url.Values) (CompleteResponse, error)

Get makes a GET request to the API with properly formatted parameters. requestURL: the url you are making the request to. values: the parameters needed for the request.

func (*Client) Info

func (c *Client) Info() (UserInfoResponse, error)

Info gets the user information.

func (*Client) Like

func (c *Client) Like(id, reblogKey string) error

Like post of a given blog. id: the id of the post you want to like. reblog_key: the reblog key for the post id.

func (*Client) Likes

func (c *Client) Likes(options url.Values) (LikesResponse, error)

Likes gets the likes of the given user. options can be: limit: the number of results to return, inclusive; offset: liked post number to start at.

func (*Client) Notes

func (c *Client) Notes(blogname, postID string, options url.Values) (NotesResponse, error)

Notes gets a list of notes on a post. options can be: mode: likes, reblogs_with_tags or rollup before_timestamp: return only notes created before the given timestamp

func (*Client) Post

func (c *Client) Post(requestURL string, values url.Values) (CompleteResponse, error)

Post makes a POST request to the API, allows for multipart data uploads. requestURL: the url you are making the request to. values: all the parameters needed for the request.

func (*Client) Posts

func (c *Client) Posts(blogname, postsType string, options url.Values) (PostsResponse, error)

Posts gets a list of posts from a blog. blogname: the name of the blog you want to get posts from (e.g. mgterzieva.tumblr.com). postsType: the type of the posts you want to get (e.g. text, quote, link, answer, video, audio, photo, chat, all). options can be: id: the id of the post you are looking for; tag: return only posts with this tag; limit: the number of posts to return; offset: the number of the post you want to start from; filter: return only posts with a specific format(e.g. html, text, raw).

func (*Client) Queue

func (c *Client) Queue(blogname string, options url.Values) (DraftsResponse, error)

Queue gets posts that are currently in the blog's queue. options can be: limit: the number of results to return; offset: post number to start at; filter: specify posts' format(e.g. format="html", format="text", format="raw").

func (*Client) Reblog

func (c *Client) Reblog(blogname string, options url.Values) error

Reblog creates a reblog on the given blog. blogname: the url of the blog you want to reblog to. options should be: (with * are marked required options) *id: the id of the reblogged post; *reblog_key: the reblog key of the rebloged post.

func (*Client) Submission

func (c *Client) Submission(blogname string, options url.Values) (DraftsResponse, error)

Submission retrieve submission posts. options can be: offset: post number to start at; filter: specify posts' format(e.g. format="html", format="text", format="raw").

func (*Client) Tagged

func (c *Client) Tagged(tag string, options url.Values) ([]json.RawMessage, error)

Tagged gets a list of posts with the given tag. tag: the tag you want to look for. options can be: before: the timestamp of when you'd like to see posts before; limit: the number of results to return; filter: the post format you want to get(e.g html, text, raw).

func (*Client) Unfollow

func (c *Client) Unfollow(blogname string) error

Unfollow the url of a given blog. blogname: the url of the blog to unfollow.

func (*Client) Unlike

func (c *Client) Unlike(id, reblogKey string) error

Unlike a post of a given blog. id: the id of the post you want to unlike. reblog_key: the reblog key for the post id.

type CompleteResponse

type CompleteResponse struct {
	Meta     MetaInfo        `json:"meta"`
	Response json.RawMessage `json:"response"`
}

type DialogueInfo

type DialogueInfo struct {
	Name   string `json:"name"`
	Label  string `json:"label"`
	Phrase string `json:"phrase"`
}

type DraftsResponse

type DraftsResponse struct {
	Posts []json.RawMessage `json:"posts"`
}

type FollowedBlog

type FollowedBlog struct {
	Name        string `json:"name"`
	URL         string `json:"url"`
	Updated     int64  `json:"updated"`
	Title       string `json:"title"`
	Description string `json:"description"`
}

type FollowersResponse

type FollowersResponse struct {
	TotalUsers int64  `json:"total_users"`
	Users      []User `json:"users"`
}

type FollowingResponse

type FollowingResponse struct {
	TotalBlogs int64          `json:"total_blogs"`
	Blogs      []FollowedBlog `json:"blogs"`
}

type LikesResponse

type LikesResponse struct {
	LikedPosts []json.RawMessage `json:"liked_posts"`
	LikedCount int64             `json:"liked_count"`
}

type LinkPost

type LinkPost struct {
	BasePost
	Title       string `json:"title"`
	URL         string `json:"url"`
	Description string `json:"description"`
}

type MetaInfo

type MetaInfo struct {
	Status int64  `json:"status"`
	Msg    string `json:"msg"`
}

type Note

type Note struct {
	Type                 string      `json:"type"`
	Timestamp            int64       `json:"timestamp"`
	BlogName             string      `json:"blog_name"`
	BlogUUID             string      `json:"blog_uuid"`
	BlogURL              string      `json:"blog_url"`
	Followed             bool        `json:"followed"`
	AvatarShape          string      `json:"avatar_shape"`
	ReplyText            string      `json:"reply_text"`
	PostID               json.Number `json:"post_id"`
	ReblogParentBlogName string      `json:"reblog_parent_blog_name"`
}

type NotesResponse

type NotesResponse struct {
	Notes []Note `json:"notes"`
}

type OwnedBlog

type OwnedBlog struct {
	Name        string `json:"name"`
	URL         string `json:"url"`
	Title       string `json:"title"`
	Description string `json:"description"`
	Primary     bool   `json:"primary"`
	Followers   int64  `json:"followers"`
	Tweet       string `json:"tweet"`
	Facebook    string `json:"facebook"`
	Type        string `json:"type"`
}

type PhotoObject

type PhotoObject struct {
	Caption  string    `json:"caption"`
	AltSizes []AltSize `json:"alt_sizes"`
}

type PhotoPost

type PhotoPost struct {
	BasePost
	Photos  []PhotoObject `json:"photos"`
	Caption string        `json:"caption"`
	Width   int64         `json:"width"`
	Height  int64         `json:"height"`
}

type PlayerInfo

type PlayerInfo struct {
	Width     int64  `json:"width"`
	EmbedCode string `json:"embed_code"`
}

type PostsResponse

type PostsResponse struct {
	Blog       BlogInfo          `json:"blog"`
	Posts      []json.RawMessage `json:"posts"`
	TotalPosts int64             `json:"total_posts"`
}

type QuotePost

type QuotePost struct {
	BasePost
	Text   string `json:"text"`
	Source string `json:"source"`
}

type ReblogComment

type ReblogComment struct {
	Comment  string `json:"comment"`
	TreeHTML string `json:"tree_html"`
}

type Setter

type Setter func(*Client)

Setter funcs are executed at the end of NewClient.

func SetCallbackURL

func SetCallbackURL(cb string) Setter

SetCallbackURL sets the callback URL.

func SetClient

func SetClient(hc *http.Client) Setter

SetClient sets the used HTTP client. This can be used for caching.

func SetHeaders

func SetHeaders(hs map[string]string) Setter

SetHeaders sets headers that are send with every request.

func SetHost

func SetHost(h string) Setter

SetHost sets the host URL of Tumblrs API.

type TextPost

type TextPost struct {
	BasePost
	Title string `json:"title"`
	Body  string `json:"body"`
}

type User

type User struct {
	Name      string `json:"name"`
	Following bool   `json:"following"`
	URL       string `json:"url"`
	Updated   int64  `json:"updated"`
}

type UserInfo

type UserInfo struct {
	Following         int64       `json:"following"`
	DefaultPostFormat string      `json:"default_post_format"`
	Name              string      `json:"name"`
	Likes             int64       `json:"likes"`
	Blogs             []OwnedBlog `json:"blogs"`
}

type UserInfoResponse

type UserInfoResponse struct {
	User UserInfo `json:"user"`
}

type VideoPost

type VideoPost struct {
	BasePost
	Caption string       `json:"caption"`
	Player  []PlayerInfo `json:"player"`
}

Jump to

Keyboard shortcuts

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