Documentation
¶
Overview ¶
Package writefreely provides the binding for the WriteFreely API
Index ¶
- type AuthUser
- type BatchPostResult
- type ClaimPostResult
- type Client
- func (c *Client) ClaimPosts(sp *[]OwnedPostParams) (*[]ClaimPostResult, error)
- func (c *Client) CreateCollection(sp *CollectionParams) (*Collection, error)
- func (c *Client) CreatePost(sp *PostParams) (*Post, error)
- func (c *Client) DeletePost(sp *PostParams) error
- func (c *Client) GetCollection(alias string) (*Collection, error)
- func (c *Client) GetCollectionPosts(alias string) (*[]Post, error)
- func (c *Client) GetPost(id string) (*Post, error)
- func (c *Client) GetUserCollections() (*[]Collection, error)
- func (c *Client) GetUserPosts() (*[]Post, error)
- func (c *Client) Login(username, pass string) (*AuthUser, error)
- func (c *Client) Logout() error
- func (c *Client) PinPost(alias string, pp *PinnedPostParams) error
- func (c *Client) SetToken(token string)
- func (c *Client) Token() string
- func (c *Client) UnpinPost(alias string, pp *PinnedPostParams) error
- func (c *Client) UpdatePost(sp *PostParams) (*Post, error)
- type Collection
- type CollectionParams
- type OwnedPostParams
- type PinnedPostParams
- type Post
- type PostParams
- type User
- type UserSubscription
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthUser ¶ added in v1.3.0
type AuthUser struct {
AccessToken string `json:"access_token,omitempty"`
Password string `json:"password,omitempty"`
User *User `json:"user"`
}
AuthUser represents a just-authenticated user. It contains information that'll only be returned once (now) per user session.
type BatchPostResult ¶ added in v1.3.0
type BatchPostResult struct {
ID string `json:"id,omitempty"`
Code int `json:"code,omitempty"`
ErrorMessage string `json:"error_msg,omitempty"`
}
BatchPostResult contains the post-specific result as part of a larger batch operation.
type ClaimPostResult ¶ added in v1.3.0
type ClaimPostResult struct {
ID string `json:"id,omitempty"`
Code int `json:"code,omitempty"`
ErrorMessage string `json:"error_msg,omitempty"`
Post *Post `json:"post,omitempty"`
}
ClaimPostResult contains the post-specific result for a request to associate a post to an account.
type Client ¶ added in v1.3.0
type Client struct {
// UserAgent overrides the default User-Agent header
UserAgent string
// contains filtered or unexported fields
}
Client is used to interact with the WriteFreely API. It can be used to make authenticated or unauthenticated calls.
func NewClient ¶ added in v1.3.0
NewClient creates a new API client. By default, all requests are made unauthenticated. To optionally make authenticated requests, call `SetToken`.
You have to set writefreely.InstanceURL in your code to make it useful
c := writefreely.NewClient("https://wf.laidback.moe")
c.SetToken("00000000-0000-0000-0000-000000000000")
func (*Client) ClaimPosts ¶ added in v1.3.0
func (c *Client) ClaimPosts(sp *[]OwnedPostParams) (*[]ClaimPostResult, error)
ClaimPosts associates anonymous posts with a user / account. https://developer.write.as/docs/api/#claim-posts.
func (*Client) CreateCollection ¶ added in v1.3.0
func (c *Client) CreateCollection(sp *CollectionParams) (*Collection, error)
CreateCollection creates a new collection, returning a user-friendly error if one comes up. Requires a Write.as subscription. With WriteFreely instances, the above requirement may or may not be applicable, depending on the provider. See https://developer.write.as/docs/api/#create-a-collection
func (*Client) CreatePost ¶ added in v1.3.0
func (c *Client) CreatePost(sp *PostParams) (*Post, error)
CreatePost publishes a new post, returning a user-friendly error if one comes up. See https://developer.write.as/docs/api/#publish-a-post.
Example ¶
c := NewClient()
// Publish a post
p, err := c.CreatePost(&PostParams{
Title: "Title!",
Content: "This is a post.",
Font: "sans",
})
if err != nil {
fmt.Printf("Unable to create: %v", err)
return
}
fmt.Printf("%s", p.Content)
Output: This is a post.
func (*Client) DeletePost ¶ added in v1.3.0
func (c *Client) DeletePost(sp *PostParams) error
DeletePost permanently deletes a published post. See https://developer.write.as/docs/api/#delete-a-post.
func (*Client) GetCollection ¶ added in v1.3.0
func (c *Client) GetCollection(alias string) (*Collection, error)
GetCollection retrieves a collection, returning the Collection and any error (in user-friendly form) that occurs. See https://developer.write.as/docs/api/#retrieve-a-collection
Example ¶
c := NewClient()
coll, err := c.GetCollection("blog")
if err != nil {
fmt.Printf("%v", err)
return
}
fmt.Printf("%s", coll.Title)
Output: write.as
func (*Client) GetCollectionPosts ¶ added in v1.3.0
GetCollectionPosts retrieves a collection's posts, returning the Posts and any error (in user-friendly form) that occurs. See https://developer.write.as/docs/api/#retrieve-collection-posts
func (*Client) GetPost ¶ added in v1.3.0
GetPost retrieves a published post, returning the Post and any error (in user-friendly form) that occurs. See https://developer.write.as/docs/api/#retrieve-a-post.
func (*Client) GetUserCollections ¶ added in v1.3.0
func (c *Client) GetUserCollections() (*[]Collection, error)
GetUserCollections retrieves the authenticated user's collections. See https://developers.write.as/docs/api/#retrieve-user-39-s-collections
func (*Client) GetUserPosts ¶ added in v1.3.0
GetUserPosts retrieves the authenticated user's posts. See https://developers.write.as/docs/api/#retrieve-user-39-s-posts
func (*Client) Login ¶ added in v1.3.1
Login authenticates a user with a WriteFreely instance. See https://developer.write.as/docs/api/#authenticate-a-user
func (*Client) Logout ¶ added in v1.3.1
Logout logs the current user out, making the Client's current access token invalid.
func (*Client) PinPost ¶ added in v1.3.0
func (c *Client) PinPost(alias string, pp *PinnedPostParams) error
PinPost pins a post in the given collection. See https://developers.write.as/docs/api/#pin-a-post-to-a-collection
func (*Client) SetToken ¶ added in v1.3.0
SetToken sets the user token for all future Client requests. Setting this to an empty string will change back to unauthenticated requests.
func (*Client) UnpinPost ¶ added in v1.3.0
func (c *Client) UnpinPost(alias string, pp *PinnedPostParams) error
UnpinPost unpins a post from the given collection. See https://developers.write.as/docs/api/#unpin-a-post-from-a-collection
func (*Client) UpdatePost ¶ added in v1.3.0
func (c *Client) UpdatePost(sp *PostParams) (*Post, error)
UpdatePost updates a published post with the given PostParams. See https://developer.write.as/docs/api/#update-a-post.
type Collection ¶ added in v1.3.0
type Collection struct {
Alias string `json:"alias"`
Title string `json:"title"`
Description string `json:"description"`
StyleSheet string `json:"style_sheet"`
Private bool `json:"private"`
Views int64 `json:"views"`
Domain string `json:"domain,omitempty"`
Email string `json:"email,omitempty"`
URL string `json:"url,omitempty"`
TotalPosts int `json:"total_posts"`
Posts *[]Post `json:"posts,omitempty"`
}
Collection represents a collection of posts. Blogs are a type of collection on Write.as.
type CollectionParams ¶ added in v1.3.0
CollectionParams holds values for creating a collection.
type OwnedPostParams ¶ added in v1.3.0
OwnedPostParams are, together, fields only the original post author knows.
type PinnedPostParams ¶ added in v1.3.0
PinnedPostParams holds values for pinning a post
type Post ¶ added in v1.3.0
type Post struct {
ID string `json:"id"`
Slug string `json:"slug"`
Token string `json:"token"`
Font string `json:"appearance"`
Language *string `json:"language"`
RTL *bool `json:"rtl"`
Listed bool `json:"listed"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
Title string `json:"title"`
Content string `json:"body"`
Views int64 `json:"views"`
Tags []string `json:"tags"`
Images []string `json:"images"`
OwnerName string `json:"owner,omitempty"`
Collection *Collection `json:"collection,omitempty"`
}
Post represents a published Write.as post, whether anonymous, owned by a user, or part of a collection.
type PostParams ¶ added in v1.3.0
type PostParams struct {
// Parameters only for updating
ID string `json:"-"`
Token string `json:"token,omitempty"`
// Parameters for creating or updating
Title string `json:"title,omitempty"`
Content string `json:"body,omitempty"`
Font string `json:"font,omitempty"`
IsRTL *bool `json:"rtl,omitempty"`
Language *string `json:"lang,omitempty"`
// Parameters only for creating
Crosspost []map[string]string `json:"crosspost,omitempty"`
// Parameters for collection posts
Collection string `json:"-"`
}
PostParams holds values for creating or updating a post.
type User ¶ added in v1.3.0
type User struct {
Username string `json:"username"`
Email string `json:"email"`
Created time.Time `json:"created"`
// Optional properties
Subscription *UserSubscription `json:"subscription"`
}
User represents a registered Write.as user.
type UserSubscription ¶ added in v1.3.0
type UserSubscription struct {
Name string `json:"name"`
Begin time.Time `json:"begin"`
End time.Time `json:"end"`
AutoRenew bool `json:"auto_renew"`
Active bool `json:"is_active"`
Delinquent bool `json:"is_delinquent"`
}
UserSubscription contains information about a user's Write.as subscription.