tumblr

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2016 License: Apache-2.0 Imports: 8 Imported by: 9

README

Tumblr API Go Client

Build Status GoDoc

This is the Tumblr API Golang client

Installation

Run go get github.com/tumblr/tumblr.go

Usage

The mechanics of this library send HTTP requests through a ClientInterface object. There is intentionally no concrete client defined in this library to allow for maximum flexibility. There is a separate repository with a client implementation and convenience methods if you do not require a custom client behavior.

Support/Questions

You can post a question in the Google Group or contact the Tumblr API Team at api@tumblr.com

License

Copyright 2016 Tumblr, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MixedPaginationMethodsError error = errors.New("Cannot mix pagination between SinceId and Offset")

Error generated when a Dashboard result set it attempting to change pagination methods

View Source
var NoNextPageError error = errors.New("No next page.")

Error returned for a collection's Next() invocation if no next page is possible

View Source
var NoPrevPageError error = errors.New("No prev page.")

Error returned for a collection's Prev() invocation if no previous page is possible

Functions

func DeletePost

func DeletePost(client ClientInterface, name string, postId uint64) error

Delete a given blog's post by ID, nil if successful, error on failure

func EditPost

func EditPost(client ClientInterface, blogName string, postId uint64, params url.Values) error

Edit a given post, returns nil if successful, error on failure

func Follow

func Follow(client ClientInterface, blogName string) error

Follow a blog

func GetAvatar

func GetAvatar(client ClientInterface, name string) (string, error)

Retrieve Blog's Avatar URI

func LikePost

func LikePost(client ClientInterface, postId uint64, reblogKey string) error

Like a post on behalf of a user

func Unfollow

func Unfollow(client ClientInterface, blogName string) error

Unfollow a blog

func UnlikePost

func UnlikePost(client ClientInterface, postId uint64, reblogKey string) error

Unlike a post on behalf of a user

Types

type AnswerPost

type AnswerPost struct {
	Post
	Answer     string `json:"answer"`
	AskingName string `json:"asking_name"`
	AskingUrl  string `json:"asking_url"`
	Publisher  string `json:"publisher"`
	Question   string `json:"question"`
}

Post subtype

type AudioPost

type AudioPost struct {
	Post
	AlbumArt       string `json:"album_art"`
	Artist         string `json:"artist"`
	AudioSourceUrl string `json:"audio_source_url"`
	AudioType      string `json:"audio_type"`
	AudioUrl       string `json:"audio_url"`
	Embed          string `json:"embed"`
	Player         string `json:"player"`
	Plays          uint64 `json:"plays"`
}

Post subtype

type Blog

type Blog struct {
	BlogRef
	Url                  string `json:"url"`
	Title                string `json:"title"`
	Posts                int64  `json:"posts"`
	Ask                  bool   `json:"ask"`
	AskAnon              bool   `json:"ask_anon"`
	AskAnonPageTitle     string `json:"ask_page_title"`
	CanSendFanMail       bool   `json:"can_send_fan_mail"`
	CanSubmit            bool   `json:"can_submit"`
	CanSubscribe         bool   `json:"can_subscribe"`
	Description          string `json:"description"`
	Followed             bool   `json:"followed"`
	IsBlockedFromPrimary bool   `json:"is_blocked_from_primary"`
	IsNSFW               bool   `json:"is_nsfw"`
	ShareLikes           bool   `json:"share_likes"`
	SubmissionPageTitle  string `json:"submission_page_title"`
	Subscribed           bool   `json:"subscribed"`
	TotalPosts           int64  `json:"total_posts"`
	Updated              int64  `json:"updated"`
}

Tumblelog struct

func GetBlogInfo

func GetBlogInfo(client ClientInterface, name string) (*Blog, error)

Retrieve information about a blog

func (*Blog) String

func (b *Blog) String() string

Convenience method converting a Blog into a JSON representation

type BlogRef

type BlogRef struct {
	Name string `json:"name"`
	// contains filtered or unexported fields
}

Reference to a blog which can be used to perform further blog actions

func NewBlogRef

func NewBlogRef(client ClientInterface, name string) *BlogRef

Create a BlogRef

func (*BlogRef) CreatePost

func (b *BlogRef) CreatePost(params url.Values) (*PostRef, error)

Creates a post on the blog represented by BlogRef

func (*BlogRef) Follow

func (b *BlogRef) Follow() error

Follows this blog for the current user (based on OAuth user token/secret)

func (*BlogRef) GetAvatar

func (b *BlogRef) GetAvatar() (string, error)

Retrieves blog avatar for the given blog reference

func (*BlogRef) GetDrafts

func (b *BlogRef) GetDrafts(params url.Values) (*Posts, error)

Retrieves blog's drafts for the given blog reference

func (*BlogRef) GetFollowers

func (b *BlogRef) GetFollowers() (*FollowerList, error)

Retrieves blog's followers for the given blog reference

func (*BlogRef) GetInfo

func (b *BlogRef) GetInfo() (*Blog, error)

Retrieves blog info for the given blog reference

func (*BlogRef) GetPosts

func (b *BlogRef) GetPosts(params url.Values) (*Posts, error)

Retrieves blog's posts for the given blog reference

func (*BlogRef) GetQueue

func (b *BlogRef) GetQueue(params url.Values) (*Posts, error)

Retrieves blog's queue for the given blog reference

func (*BlogRef) ReblogPost

func (b *BlogRef) ReblogPost(p *PostRef, params url.Values) (*PostRef, error)

Reblogs a post to the blog represented by BlogRef

func (*BlogRef) Unfollow

func (b *BlogRef) Unfollow() error

Unfollows this blog for the current user (based on OAuth user token/secret)

type ChatPost

type ChatPost struct {
	Post
	Dialog []struct {
		Label  string `json:"label"`
		Name   string `json:"name"`
		Phrase string `json:"phrase"`
	} `json:"dialog"`
}

Post subtype

type ClientInterface

type ClientInterface interface {
	// Issue GET request to Tumblr API
	Get(endpoint string) (Response, error)
	// Issue GET request to Tumblr API with param values
	GetWithParams(endpoint string, params url.Values) (Response, error)
	// Issue POST request to Tumblr API
	Post(endpoint string) (Response, error)
	// Issue POST request to Tumblr API with param values
	PostWithParams(endpoint string, params url.Values) (Response, error)
	// Issue PUT request to Tumblr API
	Put(endpoint string) (Response, error)
	// Issue PUT request to Tumblr API with param values
	PutWithParams(endpoint string, params url.Values) (Response, error)
	// Issue DELETE request to Tumblr API
	Delete(endpoint string) (Response, error)
	// Issue DELETE request to Tumblr API with param values
	DeleteWithParams(endpoint string, params url.Values) (Response, error)
}

If you wish to use your own client, simply make sure it implements this interface

type Dashboard

type Dashboard struct {
	Posts []PostInterface `json:"posts"`
	// contains filtered or unexported fields
}

func GetDashboard

func GetDashboard(client ClientInterface, params url.Values) (*Dashboard, error)

Retreive a User's dashboard

func (*Dashboard) NextByOffset

func (d *Dashboard) NextByOffset() (*Dashboard, error)

Returns the next page of a user's dashboard using the current page's offset

func (*Dashboard) NextBySinceId

func (d *Dashboard) NextBySinceId() (*Dashboard, error)

Returns the next page of a user's dashboard using the current page's last Post id

type Follower

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

FollowerList substructure

type FollowerList

type FollowerList struct {
	Total     uint32     `json:"total_users"`
	Followers []Follower `json:"users"`
	// contains filtered or unexported fields
}

Object from the lsit of followers response

func GetFollowers

func GetFollowers(client ClientInterface, name string, offset, limit uint) (*FollowerList, error)

Retrieve User's followers

func (*FollowerList) Next

func (f *FollowerList) Next() (*FollowerList, error)

Get next page of a user's followers

func (*FollowerList) Prev

func (f *FollowerList) Prev() (*FollowerList, error)

Get previous page of a user's followers

type FollowingList

type FollowingList struct {
	Total uint32 `json:"total_blogs"`
	Blogs []Blog `json:"blogs"`
	// contains filtered or unexported fields
}

func GetFollowing

func GetFollowing(client ClientInterface, offset, limit uint) (*FollowingList, error)

Retrieves the list of blogs this user follows

func (*FollowingList) Next

func (f *FollowingList) Next() (*FollowingList, error)

Retrieves the next page of followers

func (*FollowingList) Prev

func (f *FollowingList) Prev() (*FollowingList, error)

Retrieves the previous page of followers

type Likes

type Likes struct {
	Posts      []MiniPost `json:"liked_posts"`
	TotalLikes uint64     `json:"liked_count"`
	// contains filtered or unexported fields
}

func GetLikes

func GetLikes(client ClientInterface, params url.Values) (*Likes, error)

Retrieves a Users's list of Posts they have liked URL values can include:

limit (int)
offset (int)
before (timestamp)
after (timestamp)

func (*Likes) Full

func (l *Likes) Full() ([]PostInterface, error)

Return an array of full post objects (instead of the default array of MiniPosts initially created)

type LinkPost

type LinkPost struct {
	Post
	Description string `json:"description"`
	Excerpt     string `json:"excerpt"`
	LinkAuthor  string `json:"link_author"`
	Title       string `json:"title"`
	Url         string `json:"url"`
}

Post subtype

type MiniPost

type MiniPost struct {
	Id        uint64 `json:"id"`
	Type      string `json:"type"`
	BlogName  string `json:"blog_name"`
	ReblogKey string `json:"reblog_key"`
}

The basics for what is needed in a Post

type Photo

type Photo struct {
	AltSizes     []PhotoSize `json:"alt_sizes"`
	Caption      string      `json:"caption"`
	OriginalSize PhotoSize   `json:"original_size"`
}

Photo post substructure

type PhotoPost

type PhotoPost struct {
	Post
	ImagePermalink string  `json:"image_permalink"`
	Photos         []Photo `json:"photos"`
}

Post subtype

type PhotoSize

type PhotoSize struct {
	Height uint32 `json:"height"`
	Width  uint32 `json:"width"`
	Url    string `json:"url"`
}

Photo substructure

type Post

type Post struct {
	PostRef
	Body             string        `json:"body"`
	CanLike          bool          `json:"can_like"`
	CanReblog        bool          `json:"can_reblog"`
	CanReply         bool          `json:"can_reply"`
	CanSendInMessage bool          `json:"can_send_in_message"`
	Caption          string        `json:"caption"`
	Date             string        `json:"date"`
	DisplayAvatar    bool          `json:"display_avatar"`
	Followed         bool          `json:"followed"`
	Format           string        `json:"format"`
	Highlighted      []interface{} `json:"highlighted"`
	Liked            bool          `json:"liked"`
	NoteCount        uint64        `json:"note_count"`
	PermalinkUrl     string        `json:"permalink_url"`
	PostUrl          string        `json:"post_url"`
	Reblog           struct {
		Comment  string `json:"comment"`
		TreeHTML string `json:"tree_html"`
	} `json:"reblog"`
	RecommendedColor  string            `json:"recommended_color"`
	RecommendedSource bool              `json:"recommended_source"`
	ShortUrl          string            `json:"short_url"`
	Slug              string            `json:"slug"`
	SourceTitle       string            `json:"source_title"`
	SourceUrl         string            `json:"source_url"`
	State             string            `json:"state"`
	Summary           string            `json:"summary"`
	Tags              []string          `json:"tags"`
	Timestamp         uint64            `json:"timestamp"`
	FeaturedTimestamp uint64            `json:"featured_timestamp,omitempty"`
	TrackName         string            `json:"track_name,omitempty"`
	Trail             []ReblogTrailItem `json:"trail"`
}

The common fields on any post, no matter what type

func (*Post) GetProperty

func (p *Post) GetProperty(key string) (interface{}, error)

Convenience method for easy retrieval of one-off values

func (*Post) GetSelf

func (p *Post) GetSelf() *Post

Useful for converting a PostInterface into a Post

func (*Post) String

func (p *Post) String() string

Convenience method for ease of use- renders a Post as a JSON string

type PostInterface

type PostInterface interface {
	GetProperty(key string) (interface{}, error)
	GetSelf() *Post
}

PostInterface for use in typed structures which could contain any of the below subtypes

type PostRef

type PostRef struct {
	MiniPost
	// contains filtered or unexported fields
}

Starting point for performing operations on a post

func CreatePost

func CreatePost(client ClientInterface, name string, params url.Values) (*PostRef, error)

Create a post, return the ID on success, error on failure

func NewPostRef

func NewPostRef(client ClientInterface, post *MiniPost) *PostRef

Creates a PostRef with the given properties set

func NewPostRefById

func NewPostRefById(client ClientInterface, id uint64) *PostRef

Creates a PostRef with the given properties set

func ReblogPost

func ReblogPost(client ClientInterface, blogName string, postId uint64, reblogKey string, params url.Values) (*PostRef, error)

Reblog a given post to the given blog, returns the reblog's post id if successful, else the error

func (*PostRef) Delete

func (p *PostRef) Delete() error

Convenience method to allow calling post.Delete()

func (*PostRef) Edit

func (p *PostRef) Edit(params url.Values) error

Convenience method to allow calling post.Edit(params)

func (*PostRef) Like

func (p *PostRef) Like() error

Likes a Post on behalf of the current user

func (*PostRef) ReblogOnBlog

func (p *PostRef) ReblogOnBlog(name string, params url.Values) (*PostRef, error)

Convenience method to allow calling post.Reblog(params)

func (*PostRef) SetClient

func (r *PostRef) SetClient(c ClientInterface)

Sets PostRef's client

func (*PostRef) Unlike

func (p *PostRef) Unlike() error

Unlikes a Post on behalf of the current user

type Posts

type Posts struct {
	Posts      []MiniPost `json:"posts"`
	TotalPosts int64      `json:"total_posts"`
	// contains filtered or unexported fields
}

Representation of a list of Posts

func GetDrafts

func GetDrafts(client ClientInterface, name string, params url.Values) (*Posts, error)

Retrieve a blog's drafts

func GetPosts

func GetPosts(client ClientInterface, name string, params url.Values) (*Posts, error)

Retrieve a blog's posts, in the API docs you can find how to filter by ID, type, etc

func GetQueue

func GetQueue(client ClientInterface, name string, params url.Values) (*Posts, error)

Retrieve a blog's Queue

func GetSubmissions

func GetSubmissions(client ClientInterface, name string, params url.Values) (*Posts, error)

Retrieve a blog's submsisions

func (*Posts) All

func (p *Posts) All() ([]PostInterface, error)

Method to retrieve fully fleshed post data from stubs and cache result

func (*Posts) Get

func (p *Posts) Get(index uint) PostInterface

Method to retrieve a single Post entity at a given index; returns nil if index is out of bounds

type QuotePost

type QuotePost struct {
	Post
	Source string `json:"source,omitempty"`
	Text   string `json:"text"`
}

Post subtype

type ReblogTrailItem

type ReblogTrailItem struct {
	Blog          Blog   `json:"blog"`
	Content       string `json:"content"`
	ContentRaw    string `json:"content_raw"`
	IsCurrentItem bool   `json:"is_current_item"`
	Post          struct {
		// sometimes an actual int, sometimes a numeric string, always a headache
		Id interface{} `json:"id"`
	} `json:"post"`
}

Post substructure

type Response

type Response struct {
	Headers http.Header
	Meta    map[string]interface{} `json:"meta"`
	Result  map[string]interface{} `json:"response"`
	Errors  map[string]interface{} `json:"errors"`
	// contains filtered or unexported fields
}

API Response structure which we'll use to pass back to behaviors

func NewResponse

func NewResponse(body []byte, headers http.Header) *Response

Create a response object from the body bytestream and the headers structure

func (*Response) GetBody

func (r *Response) GetBody() []byte

Get the raw response body

func (*Response) PopulateFromBody

func (r *Response) PopulateFromBody() error

Utility function for populating the Response's fields

type SearchResults

type SearchResults struct {
	Posts []PostInterface `json:"response"`
	// contains filtered or unexported fields
}

func TaggedSearch

func TaggedSearch(client ClientInterface, tag string, params url.Values) (*SearchResults, error)

gets page of posts

func (*SearchResults) Next

func (s *SearchResults) Next() (*SearchResults, error)

returns next page of results

type ShortBlog

type ShortBlog struct {
	BlogRef
	Url            string `json:"url"`
	Title          string `json:"title"`
	IsPrimary      bool   `json:"primary"`
	FollowerCount  uint32 `json:"followers"`
	PostToTwitter  string `json:"tweet"`
	PostToFacebook string `json:"facebook"`
	Visibility     string `json:"type"`
}

Subset of blog information, returned in the list of blogs belonging to a user (see: GetUserInfo)

type TextPost

type TextPost struct {
	Post
	Title string `json:"title"`
}

Post subtype

type User

type User struct {
	Following         uint32      `json:"following"`
	DefaultPostFormat string      `json:"default_post_format"`
	Name              string      `json:"name"`
	Likes             uint64      `json:"likes"`
	Blogs             []ShortBlog `json:"blogs"`
}

func GetUserInfo

func GetUserInfo(client ClientInterface) (*User, error)

Retrieves the current user's info (based on the client's token/secret values)

type VideoPost

type VideoPost struct {
	Post
	Html5Capable bool   `json:"html5_capable"`
	PermalinkUrl string `json:"permalink_url"`
	Players      []struct {
		EmbedCode string      `json:"embed_code"`
		Width     interface{} `json:"width"`
	} `json:"player"`
	ThumbnailHeight uint32 `json:"thumbnail_height"`
	ThumbnailUrl    string `json:"thumbnail_url"`
	ThumbnailWidth  uint32 `json:"thumbnail_width"`
	Video           map[string]struct {
		Height  uint32 `json:"height"`
		Width   uint32 `json:"width"`
		VideoId string `json:"video_id"`
	} `json:"video"`
	VideoType string `json:"video_type"`
}

Post subtype

Jump to

Keyboard shortcuts

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