pinboard

package module
v0.0.0-...-668caef Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2015 License: MIT Imports: 9 Imported by: 0

README

Pinboard

Package pinboard is a GO library, which uses the Pinboard API to interact programatically with your bookmarks, notes and other Pinboard data.

Note: This project is not affiliated with Pinboard.in in any way.

Installation

You will need to set up and configure the Go tool chain.

go get github.com/umahmood/pinboard

cd $GOPATH/src/github.com/umahmood/pinboard

go test ./...

Usage

import (
    "fmt"
    "github.com/umahmood/pinboard"
)
pin := pinboard.New()
token, err := pin.Auth("username:TOKEN")
if err := nil {
    ...
}
// get all tags in users account.
tags, err := pin.Tags()
if err := nil {
    ...
}
for _, t := range tags {
    fmt.Println("Name:", t.Name, "# of tagged:", t.Count)
}

Documentation

http://godoc.org/github.com/umahmood/pinboard

License

See the LICENSE file for license rights and limitations (MIT).

Documentation

Overview

Package pinboard uses the Pinboard API to interact programatically with your bookmarks, notes and other Pinboard data.

To start, you must authenticate using the users API token:

import (
   "github.com/umahmood/pinboard"
)

pin := pinboard.New()

token, err := pin.Auth("username:TOKEN")
...

Last time users account had activity:

t, err := pin.LastUpdate()

if err != nil {
    ...
}

fmt.Println("Last Update:", t)

Add a bookmark:

b := pinboard.Bookmark{URL: "https://www.eff.org/",
    Title:   "Electronic Frontier Foundation",
    Desc:    "Defending your rights in the digital world",
    Tags:    []string{"privacy", "rights", "encryption"},
    Created: time.Now(),
    Replace: true,
    Shared:  true,
    ToRead:  false,
}

ok, err := pin.Add(b)

if err != nil {
    ...
}

if ok {
    fmt.Println("bookmark added!")
}

Deleting a bookmark:

ok, err := pin.Del("https://www.eff.org/")

if err != nil {
    ...
}

if ok {
    fmt.Println("bookmark deleted!")
}

Get the bookmarks added today:

bmarks, err := pin.Get(time.Time{}, "", nil, false)

if err != nil {
    ...
}

for _, b := range bmarks {
    fmt.Println(b.Title)
}

Get bookmarks added on April 1st 2015:

date := time.Date(2015, 4, 1, 0, 0, 0, 0, time.UTC)
bmarks, err := pin.Get(date, "", nil, false)
...

Get bookmarks added on April 1st 2015 which have the tags:

date := time.Date(2015, 4, 1, 0, 0, 0, 0, time.UTC)
tags := []string{"python", "maths"}
bmarks, err := pin.Get(date, "", tags, false)
...

Get bookmark for this url:

bmarks, err := pin.Get(time.Time{}, "https://www.eff.org/", nil, false)
...

Number of posts on each date:

posts, err := pin.Dates(nil)

if err != nil {
    ...
}

for _, p := range posts {
    fmt.Println("Date:", p.Date, "# of posts:", p.Count)
}

Number of posts on each date for given tags:

tags := []string{"recipe", "cooking"}

posts, err := pin.Dates(tags)
...

Users 5 most recent posts:

bmarks, err := pin.Recent(nil, 5)

if err != nil {
    ...
}

for _, b := range bmarks {
    fmt.Println(b.Title)
}

Users most recent posts filtered by tag:

tags := []string{"economics"}
bmarks, err := pin.Recent(tags, 0)
...

Get all bookmarks in the users account:

bmarks, err := pin.Bookmarks(nil, 0, 0, time.Time{}, time.Time{}, false)

if err != nil {
    ...
}

for _, b := range bmarks {
    fmt.Println(b.Title)
}

Get 10 days worth of bookmarks:

start := time.Now().AddDate(0, 0, -10)
end := time.Now()
bmarks, err := pin.Bookmarks(nil, 0, 0, start, end, false)
...

Get all bookmarks which have the tags:

tags := []string{"ruby", "tutorials"}
bmarks, err := pin.Bookmarks(tags, 0, 0, time.Time{}, time.Time{}, false)
...

Get suggestions for tags based on a URL:

pop, rec, err := pin.Suggest("https://www.eff.org/")

if err != nil {
    ...
}

fmt.Println("Popular tags:")
for _, i := range pop {
    fmt.Println(i)
}

fmt.Println("Recommended tags:")
for _, i := range rec {
    fmt.Println(i)
}

Get a list of all tags in the users account:

tags, err := pin.Tags()

if err != nil {
    ...
}

for _, t := range tags {
    fmt.Println("Name:", t.Name, "# of tagged:", t.Count)
}

Delete a tag:

ok, err := pin.DelTag("fonts")

if err != nil {
    ...
}

if ok {
    fmt.Println("tag deleted.")
}

Rename a tag:

ok, err := pin.RenTag("fonts", "typography")

if err != nil {
    ...
}

if ok {
    fmt.Println("tag renamed.")
}

Get a list of all notes in the users account:

notes, err := pin.Notes()

if err != nil {
    ...
}

for _, n := range notes {
    fmt.Println("ID", n.ID, "Title", n.Title)
}

Get an individual note:

notes, err := pin.Notes()

if err != nil {
    ...
}

for _, m := range notes {
    n, err := pin.NoteID(m.ID)
    if err != nil {
        ...
    }
    fmt.Println(n.Title)
    fmt.Println(n.Text)
}

Index

Constants

View Source
const (
	Major = 1
	Minor = 0
	Patch = 0
)

Semantic versioning - http://semver.org/

Variables

View Source
var BaseURL = "https://api.pinboard.in/v1/%s/?%s"

BaseURL points to and specifies the format of the Pinboard API endpoint. ** Note ** ideally this URI would be marked as const and only visible inside the package. However for testing purposes, the unit tests need to set this URI to point to a mock server. ** Do not ** change this URI.

Functions

func Version

func Version() string

Version returns library version.

Types

type Bookmark

type Bookmark struct {
	URL   string
	Title string
	Desc  string
	Tags  []string

	// Creation time for this bookmark.
	Created time.Time
	// Replace any existing bookmark with this URL.
	Replace bool
	// Make bookmark public.
	Shared bool
	// Marks the bookmarks as unread.
	ToRead bool

	Hash []byte // 32 character hexadecimal MD5 hash.
	Meta []byte // 32 character hexadecimal MD5 hash.
}

Bookmark represents a Pinboard bookmark

type Note

type Note struct {
	NoteMetadata
	Text string
}

Note represents a Pinboard note

type NoteMetadata

type NoteMetadata struct {
	ID      string
	Title   string
	Length  int       // Size of the note in bytes.
	Hash    []byte    // 20 character long sha1 hash of note text.
	Created time.Time // Time note was created. UTC time.
	Updated time.Time // Time note was last updated. UTC time.
}

NoteMetadata represents Pinboard note meta data

type Pinboard

type Pinboard struct {
	// contains filtered or unexported fields
}

Pinboard a single instance to interact with bookmarks and other data

func New

func New() *Pinboard

New returns a new unauthorized instance of Pinboard.

func (*Pinboard) Add

func (p *Pinboard) Add(b Bookmark) (bool, error)

Add adds a bookmark.

func (*Pinboard) Auth

func (p *Pinboard) Auth(token string) (string, error)

Auth validates the provided 'token' with the Pinboard service and returns the user's API token, The API token must be in the format: username:TOKEN.

func (Pinboard) Bookmarks

func (p Pinboard) Bookmarks(tags []string, offset int, count int,
	start time.Time, end time.Time, meta bool) ([]Bookmark, error)

Bookmarks returns all bookmarks in the user's account. Provides the ability to: - 'tags' Filter by tags. - 'offset' Set offset value. - 'count' Set the number of results to return. Default is all. - 'start' Return only bookmarks created after this time. - 'end' Return only bookmarks created before this time. - 'meta' A meta flag to include a change detection signature for each bookmark.

func (Pinboard) Dates

func (p Pinboard) Dates(tags []string) ([]Post, error)

Dates returns a list of dates with the number of posts at each date.

func (Pinboard) Del

func (p Pinboard) Del(URL string) (bool, error)

Del deletes a bookmark.

func (Pinboard) DelTag

func (p Pinboard) DelTag(tag string) (bool, error)

DelTag delete an existing tag, returns true if the delete operation succeeds.

func (Pinboard) Get

func (p Pinboard) Get(dt time.Time, URL string, tags []string, meta bool) ([]Bookmark, error)

Get returns one or more posts on a single day matching the arguments. If no date or URL is given, date of most recent bookmark will be used. The meta flag allows the ability to include a change detection signature for each bookmark.

func (Pinboard) IsAuthed

func (p Pinboard) IsAuthed() bool

IsAuthed checks if the user has been authenticated with the Pinboard service

func (Pinboard) LastUpdate

func (p Pinboard) LastUpdate() (time.Time, error)

LastUpdate returns the last time a bookmark was added, updated or deleted. Use this before calling Bookmarks() to see if the data has changed since the last fetch.

func (*Pinboard) NoteID

func (p *Pinboard) NoteID(id string) (Note, error)

NoteID given a notes ID, returns an individual user note.

func (Pinboard) Notes

func (p Pinboard) Notes() ([]NoteMetadata, error)

Notes returns a list of the user's notes

func (Pinboard) Recent

func (p Pinboard) Recent(tags []string, count int) ([]Bookmark, error)

Recent returns a list of the user's most recent posts, filtered by tag. count indicates the number results to return, default is 15 max is 100.

func (Pinboard) RenTag

func (p Pinboard) RenTag(oldTag, newTag string) (bool, error)

RenTag rename a tag, or fold it in to an existing tag. Match is not case sensitive, returns true if the rename operation succeeds.

func (Pinboard) Suggest

func (p Pinboard) Suggest(URL string) (Popular, Recommended, error)

Suggest returns a list of popular tags and recommended tags for a given URL. Popular tags are tags used site-wide for the url; recommended tags are drawn from the user's own tags.

func (Pinboard) Tags

func (p Pinboard) Tags() ([]Tag, error)

Tags returns a full list of the user's tags along with the number of times they were used.

func (Pinboard) Token

func (p Pinboard) Token() string

Token returns the users token in the format username:TOKEN.

type Popular []string

Popular represents Pinboard popular tags

type Post

type Post struct {
	Date  time.Time
	Count int
}

Post represents a Pinboard post

type Recommended []string

Recommended represents Pinboard recommended tags

type Tag

type Tag struct {
	Name  string
	Count int
}

Tag represents a Pinboard tag

Jump to

Keyboard shortcuts

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