writeas.v1: go.code.as/writeas.v1 Index | Examples | Files

package writeas

import "go.code.as/writeas.v1"

Package writeas provides the binding for the Write.as API

Index

Examples

Package Files

auth.go collection.go post.go user.go writeas.go

type AuthUser Uses

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 ClaimPostResult Uses

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 Uses

type Client struct {

    // UserAgent overrides the default User-Agent header
    UserAgent string
    // contains filtered or unexported fields
}

Client is used to interact with the Write.as API. It can be used to make authenticated or unauthenticated calls.

func NewClient Uses

func NewClient() *Client

NewClient creates a new API client. By default, all requests are made unauthenticated. To optionally make authenticated requests, call `SetToken`.

c := writeas.NewClient()
c.SetToken("00000000-0000-0000-0000-000000000000")

func NewDevClient Uses

func NewDevClient() *Client

NewDevClient creates a new API client for development and testing. It'll communicate with our development servers, and SHOULD NOT be used in production.

func NewTorClient Uses

func NewTorClient(port int) *Client

NewTorClient creates a new API client for communicating with the Write.as Tor hidden service, using the given port to connect to the local SOCKS proxy.

func (*Client) ClaimPosts Uses

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 Uses

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. See https://developer.write.as/docs/api/#create-a-collection

func (*Client) CreatePost Uses

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.

Code:

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 Uses

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 Uses

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

Code:

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 Uses

func (c *Client) GetCollectionPosts(alias string) (*[]Post, error)

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 Uses

func (c *Client) GetPost(id string) (*Post, error)

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) LogIn Uses

func (c *Client) LogIn(username, pass string) (*AuthUser, error)

LogIn authenticates a user with Write.as. See https://developer.write.as/docs/api/#authenticate-a-user

func (*Client) SetToken Uses

func (c *Client) SetToken(token string)

SetToken sets the user token for all future Client requests. Setting this to an empty string will change back to unauthenticated requests.

func (*Client) UpdatePost Uses

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 Uses

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

    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 Uses

type CollectionParams struct {
    Alias string `json:"alias"`
    Title string `json:"title"`
}

CollectionParams holds values for creating a collection.

type OwnedPostParams Uses

type OwnedPostParams struct {
    ID    string `json:"-"`
    Token string `json:"token,omitempty"`
}

OwnedPostParams are, together, fields only the original post author knows.

type Post Uses

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"`
    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 Uses

type PostParams struct {
    // Parameters only for updating
    OwnedPostParams

    // 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 Uses

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 Uses

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.

Package writeas imports 8 packages (graph). Updated 2018-09-25. Refresh now. Tools for package owners.