Documentation
¶
Overview ¶
A client for accessing the WordPress.com (WPCOM) REST API V1 See: http://developer.wordpress.com/docs/api/
Usage Example:
package main import "github.com/apokalyptik/go-wpcom" import "fmt" func main() { c := wpcom.New() site, _ := c.SiteByString("en.blog.wordpress.com") fmt.Printf("Site ID: %d\n", site.ID) }
Index ¶
- Constants
- type Categories
- type Category
- type Client
- func (c *Client) Clone() *Client
- func (c *Client) Debug(debug bool)
- func (c *Client) FreshlyPressed() (rval FreshlyPressedResponse, err error)
- func (c *Client) InsecureSkipVerify(want bool)
- func (c *Client) Me(fetch ...bool) (*Me, error)
- func (c *Client) Prefix(prefix string)
- func (c *Client) SiteById(id int) (*Site, error)
- func (c *Client) SiteByString(hostname string) (*Site, error)
- type Comment
- type CommentPost
- type Comments
- type FreshlyPressedDateRange
- type FreshlyPressedResponse
- type Like
- type Likes
- type Me
- func (m *Me) Get() error
- func (m *Me) Notification(id int64) (Notification, error)
- func (m *Me) Notifications(opt *Options) (NotificationsResponse, error)
- func (m *Me) NotificationsRead(l map[int64]int64) (updated map[int64]bool, err error)
- func (m *Me) NotificationsSeen(timestamp int64) (success bool, err error)
- type Meta
- type Notification
- type NotificationsResponse
- type NotificationsSeenResponse
- type Options
- type Post
- type PostAttachment
- type PostAuthor
- type PostCategories
- type PostTag
- type Site
- func (s *Site) Categories() (categories *Categories, err error)
- func (s *Site) Comment(id int) (comment *Comment, err error)
- func (s *Site) GetComments(o *Options) (comments *Comments, err error)
- func (s *Site) GetPost(id interface{}, o *Options) (rval *Post, err error)
- func (s *Site) GetPosts(o *Options) (rval *SitePosts, err error)
- type SiteMeta
- type SiteOptions
- type SitePosts
Constants ¶
const PREFIX = "https://public-api.wordpress.com/rest/v1/"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Categories ¶
type Category ¶
type Category struct { ID int `mapstructure:"ID"` Name string `mapstructure:"name"` Slug string `mapstructure:"slug"` Description string `mapstructure:"description"` PostCount int `mapstructure:"post_count"` Parent int `mapstructure:"parent"` Meta map[string]Meta `mapstructure:"meta"` // contains filtered or unexported fields }
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func New ¶
Generate a new WordPress.com REST API Client given an access token. See: https://developer.wordpress.com/docs/oauth2/
func (*Client) Debug ¶
Turn debugging on or off. When set to true request and response information will be logged using log.Printf()
func (*Client) FreshlyPressed ¶
func (c *Client) FreshlyPressed() (rval FreshlyPressedResponse, err error)
Fetch WordPress.com "Freshly Pressed" Posts. See: https://developer.wordpress.com/docs/api/1/get/freshly-pressed/
func (*Client) InsecureSkipVerify ¶
Enable or Disable Verification of the remote SSL Certificate. The client verifies by default, however, for Automattic developers with test environments the cert hostname does not match the request hostname. This function can be used to tell the client that This is OK. This option should *never* be disabled outside this specific circumstance
func (*Client) Me ¶
Create a Me struct. See the documentation for Me for more information about it and its members and methods. By default an API call is made to prepopulate information in the Me struct. But for times when you don't actually need or want to make that call those would be wasted resources (cpu cycles, wall clock time, bandwidth, etc) and so you can disable this functionality by passing false to this method
func (*Client) Prefix ¶
Set the URL Prefix for the API client. This should normally not change unless you are an Automattic developer with a WordPress.com development environment testing changes. This option should *never* be overridden outside this specific circumstance
type Comment ¶
type Comment struct { ID int `mapstructure:"ID"` Post CommentPost `mapstructure:"post"` Author PostAuthor `mapstructure:"author"` Date string `mapstructure:"date"` URL string `mapstructure:"URL"` ShortURL string `mapstructure:"short_URL"` Content string `mapstructure:"content"` Status string `mapstructure:"status"` Parent bool `mapstructure:"parent"` Type string `mapstructure:"type"` Meta map[string]Meta `mapstructure:"meta"` }
The structure for a single comment
type CommentPost ¶
type CommentPost struct { ID int `mapstructure:"ID"` Type string `mapstructure:"type"` Link string `mapstructure:"link"` }
The structure for comment details about the post for which the comment was made
type Comments ¶
type Comments struct { Found int `mapstructure:"found"` Comments []Comment `mapstructure:"comments"` }
The structure for a response to a query for multiple comments
type FreshlyPressedDateRange ¶
type FreshlyPressedDateRange struct { Newest string `mapstructure:"newest"` Oldest string `mapstructure:"oldest"` }
A structure Representing the date range part of the responce from a freshly-pressed API call response
type FreshlyPressedResponse ¶
type FreshlyPressedResponse struct { DateRange FreshlyPressedDateRange `mapstructure:"date_range"` Number int `mapstructure:"number"` Posts []Post `mapstructure:"posts"` }
A structure representing the response of a freshly-pressed API call response.
type Like ¶
type Like struct { ID int `mapstructure:"ID"` Author string `mapstructure:"login"` Email string `mapstructure:"email"` URL string `mapstructure:"URL"` // contains filtered or unexported fields }
Like is the structure for a single post like
type Likes ¶
type Likes struct { Found int `mapstructure:"found"` Likes []Like `mapstructure:"likes"` ILike bool `mapstructure:"i_like"` }
Likes is the structure for a response to a query for multiple post likes
type Me ¶
type Me struct { ID int `mapstructure:"ID"` DisplayName string `mapstructure:"display_name"` Username string `mapstructure:"username"` Email string `mapstructure:"email"` PrimaryBlog int `mapstructure:"primary_blog"` TokenSiteID int `mapstructure:"token_site_id"` Avatar string `mapstructure:"avatar_URL"` Profile string `mapstructure:"profile_URL"` Verified bool `mapstructure:"verified"` Meta map[string]interface{} `mapstructure:"meta"` Error string `mapstructure:"error"` ErrorMessage string `mapstructure:"message"` // contains filtered or unexported fields }
A structure representing the user (or lack thereof for anonymous API usage) associated with the API calls. Several API functions are attached to this structure when it makes sense for those API calls in no other context than that they are attached to an authenticated user. Notifications for example. You should not create a Me struct directly but instead use the Me() method on a Client struct. The reason for this is that a proper client for API calls will be embedded in the Me struct only when initialized in this fashion. The embedded client will retain the key debug, etc, settings from the creating Client.
func (*Me) Get ¶
Fetch, or re-fetch, details about the current API user. The method updates the existing struct with new data where applicable from the results of this function call. This is especially useful for Me structs initially created without fetching the user info (which is possible by passing false to the Me method on a Client struct) see: https://developer.wordpress.com/docs/api/1/get/me/
func (*Me) Notification ¶
func (m *Me) Notification(id int64) (Notification, error)
Fetch information about a specific notification via it's note ID. See: https://developer.wordpress.com/docs/api/1/get/notifications/%24note_ID/
func (*Me) Notifications ¶
func (m *Me) Notifications(opt *Options) (NotificationsResponse, error)
Fetch the notifications for a user. The opt argument allows you to specify query parameters to attach to the API call. See https://developer.wordpress.com/docs/api/1/get/notifications/ for possible options, and information about the data it returns
func (*Me) NotificationsRead ¶
Mark a set of notifications as read. The l map being passed matches the "counts" request parameter 1:1 from the Api documentation. See: https://developer.wordpress.com/docs/api/1/post/notifications/read/
func (*Me) NotificationsSeen ¶
Set the timestamp of the most recently seen notification for the current user See: https://developer.wordpress.com/docs/api/1/post/notifications/seen/
type Notification ¶
type Notification struct { ID int64 `mapstructure:"id"` Type string `mapstructure:"type"` Unread int64 `mapstructure:"unread"` Noticon string `mapstructure:"noticon"` Timestamp int64 `mapstructure:"timestamp"` Body map[string]interface{} `mapstructure:"body"` Subject map[string]interface{} `mapstructure:"subject"` }
The structure of data representing a single notification. This is used for both Notifications() and Notification() calls on Me structs
type NotificationsResponse ¶
type NotificationsResponse struct { Notifications []Notification `mapstructure:"notes"` LastSeen int64 `mapstructure:"last_seen_time"` Number int `mapstructure:"number"` }
The struture for the data returned from a Notifications() call on a Me struct
type Options ¶
A wrapper for url.Values which enables us to easily configure API calls. Typically you would create a reference to this struct with the exported O() function. An example of this would be something like the following:
O().Add("foo", "bar").Add("baz[]", "bazone").Add("baz[]", "baztwo").Set("ID",123)
func O ¶
func O() *Options
Convenience function to return a reference to an Options struct. See the documentation for the Options struct for example usage.
func (*Options) Add ¶
Add an option. This mirrors url.Values.Add() in that if called multiple times it will be added (and retained) multiple times. Additionally for convenience you can pass things like integers, booleans, floats, directly and they will be translated into something workable for iether GET or POST parameters (which are not statically typed over the wire due to how HTTP works)
type Post ¶
type Post struct { ID int `mapstructure:"ID"` SiteId int `mapstructure:"site_ID"` Author PostAuthor `mapstructure:"author"` Date string `mapstructure:"date"` Modified string `mapstructure:"modified"` Title string `mapstructure:"title"` URL string `mapstructure:"URL"` ShortURL string `mapstructure:"short_URL"` Content string `mapstructure:"content"` Excerpt string `mapstructure:"excerpt"` Slug string `mapstructure:"slug"` GUID string `mapstructure:"guid"` Status string `mapstructure:"status"` Password string `mapstructure:"password"` Parent bool `mapstructure:"parent"` CommentsOpen bool `mapstructure:"comments_open"` LikeCount int `mapstructure:"like_count"` ILike bool `mapstructure:"i_like"` Reblogged bool `mapstructure:"is_reblogged"` Following bool `mapstructure:"is_following"` GlobalID string `mapstructure:"global_ID"` FeaturedImage string `mapstructure:"featured_image"` Geo bool `mapstructure:"mapstructure"` // ?? maybe not bool? PublicizeURLs []string `mapstructure:"publicize_URLs"` // ?? maybe not strings? Tags map[string]PostTag `mapstructure:"tags"` Categories map[string]PostCategories `mapstructure:"categories"` Attachments map[int]PostAttachment `mapstructure:"attachments"` Metadata []Meta `mapstructure:"metadata"` Meta map[string]Meta `mapstructure:"meta"` FeaturedMedia interface{} `mapstructure:"featured_media"` // contains filtered or unexported fields }
func (*Post) Comments ¶
Query for comments on a Post. See the following URL for possible options. https://developer.wordpress.com/docs/api/1/get/sites/%24site/posts/%24post_ID/replies/
type PostAttachment ¶
type PostAuthor ¶
type PostAuthor struct { ID int Email string `mapstructure:"email"` Name string `mapstructure:"name"` NiceName string `mapstructure:"nice_name"` URL string `mapstructure:"URL"` AvatarURL string `mapstructure:"avatar_URL"` ProfileURL string `mapstructure:"profile_url"` SiteID int `mapstructure:"site_ID"` }
type PostCategories ¶
type Site ¶
type Site struct { ID int `mapstructure:"ID"` Name string `mapstructure:"name"` Description string `mapstructure:"description"` URL string `mapstructure:"URL"` Posts int `mapstructure:"post_count"` Subscribers int `mapstructure:"subscribers_count"` Lang string `mapstructure:"lang"` Visible string `mapstructure:"visible"` Options map[string]SiteOptions `mapstructure:"options"` Meta map[string]SiteMeta `mapstructure:"meta"` Error string `mapstructure:"error"` ErrorMessage string `mapstructure:"message"` Jetpack bool `mapstructure:"jetpack"` Private bool `mapstructure:"is_private"` Following bool `mapstructure:"is_following"` // contains filtered or unexported fields }
A site object to act upon
func (*Site) Categories ¶
func (s *Site) Categories() (categories *Categories, err error)
func (*Site) Comment ¶
Query for a comment on a site. See the following URL for possible options. https://developer.wordpress.com/docs/api/1/get/sites/%24site/comments/%24comment_ID/
func (*Site) GetComments ¶
Query for comments on a site. See the following URL for possible options. http://developer.wordpress.com/docs/api/1/get/sites/%24site/comments/
func (*Site) GetPost ¶
Get a site by ID, or by slug. The function accepts both an integer type, or a string type for the id parameter. Any other type will return an error and a nil reference. For possible options see the following documentation URLs: https://developer.wordpress.com/docs/api/1/get/sites/%24site/posts/%24post_ID/ https://developer.wordpress.com/docs/api/1/get/sites/%24site/posts/slug:%24post_slug/