wpcom

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

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

Go to latest
Published: Sep 18, 2014 License: GPL-2.0 Imports: 12 Imported by: 0

README

go-wpcom

A Go WordPress.com REST API client. If you require a bearer code for using (or testing) you can easily aquire one at the following location so long as you have a wpcom account:

https://rest-access.test.apokalyptik.com/

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

View Source
const PREFIX = "https://public-api.wordpress.com/rest/v1/"

Variables

This section is empty.

Functions

This section is empty.

Types

type Categories

type Categories struct {
	Found      int        `mapstructure:"found"`
	Categories []Category `mapstructure:"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

func New(access_token ...string) *Client

Generate a new WordPress.com REST API Client given an access token. See: https://developer.wordpress.com/docs/oauth2/

func (*Client) Clone

func (c *Client) Clone() *Client

Create a new client duplicating the settings 1:1 for the current client

func (*Client) Debug

func (c *Client) Debug(debug bool)

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

func (c *Client) InsecureSkipVerify(want bool)

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

func (c *Client) Me(fetch ...bool) (*Me, error)

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

func (c *Client) Prefix(prefix string)

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

func (*Client) SiteById

func (c *Client) SiteById(id int) (*Site, error)

Fetch a site struct using the site's integer ID.

func (*Client) SiteByString

func (c *Client) SiteByString(hostname string) (*Site, error)

Fetch a site struct using the site's string hostname.

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

func (m *Me) Get() error

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

func (m *Me) NotificationsRead(l map[int64]int64) (updated map[int64]bool, err error)

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

func (m *Me) NotificationsSeen(timestamp int64) (success bool, err error)

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 Meta

type Meta map[string]string

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 NotificationsSeenResponse

type NotificationsSeenResponse struct {
	LastSeen int64 `mapstructure:"last_seen_time"`
	Success  bool  `mapstructure:"success"`
}

type Options

type Options struct {
	url.Values
}

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

func (o *Options) Add(key string, value interface{}) *Options

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)

func (*Options) Empty

func (o *Options) Empty() bool

Determine whether any options have been set

func (*Options) Set

func (o *Options) Set(key string, value interface{}) *Options

Set an option. This mirrors url.Values.Set() in that if an option of the name exists it will be overwritten with the new value. Otherwise works the same as Add with regard to types, et al.

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

func (p *Post) Comments(o *Options) (comments *Comments, err error)

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/

func (*Post) Likes

func (p *Post) Likes(o *Options) (likes *Likes, err error)

Likes query on a Post. See the following URL for possible options. https://developer.wordpress.com/docs/api/1/get/sites/%24site/posts/%24post_ID/likes/

type PostAttachment

type PostAttachment struct {
	ID       int    `mapstructure:"ID"`
	URL      string `mapstructure:"URL"`
	GUID     string `mapstructure:"guid"`
	MimeType string `mapstructure:"mime_type"`
	Width    int    `mapstructure:"width"`
	Height   int    `mapstructure:"height"`
}

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 PostCategories 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"`
}

type PostTag

type PostTag struct {
	ID          int             `mapstructure:"ID"`
	Name        string          `mapstructure:"name"`
	Slug        string          `mapstructure:"slug"`
	Description string          `mapstructure:"description"`
	PostCount   int             `mapstructure:"post_count"`
	Meta        map[string]Meta `mapstructure:"meta"`
}

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

func (s *Site) Comment(id int) (comment *Comment, err error)

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

func (s *Site) GetComments(o *Options) (comments *Comments, err error)

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

func (s *Site) GetPost(id interface{}, o *Options) (rval *Post, err error)

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/

func (*Site) GetPosts

func (s *Site) GetPosts(o *Options) (rval *SitePosts, err error)

Get posts for a site. For possible options see the following documentation URL: https://developer.wordpress.com/docs/api/1/get/sites/%24site/posts/

type SiteMeta

type SiteMeta map[string]string

type SiteOptions

type SiteOptions map[string]string

type SitePosts

type SitePosts struct {
	Found int    `mapstructure:"found"`
	Posts []Post `mapstructure:"posts"`
}

Jump to

Keyboard shortcuts

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