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
- Variables
- func Version() string
- type Bookmark
- type Note
- type NoteMetadata
- type Pinboard
- func (p *Pinboard) Add(b Bookmark) (bool, error)
- func (p *Pinboard) Auth(token string) (string, error)
- func (p Pinboard) Bookmarks(tags []string, offset int, count int, start time.Time, end time.Time, ...) ([]Bookmark, error)
- func (p Pinboard) Dates(tags []string) ([]Post, error)
- func (p Pinboard) Del(URL string) (bool, error)
- func (p Pinboard) DelTag(tag string) (bool, error)
- func (p Pinboard) Get(dt time.Time, URL string, tags []string, meta bool) ([]Bookmark, error)
- func (p Pinboard) IsAuthed() bool
- func (p Pinboard) LastUpdate() (time.Time, error)
- func (p *Pinboard) NoteID(id string) (Note, error)
- func (p Pinboard) Notes() ([]NoteMetadata, error)
- func (p Pinboard) Recent(tags []string, count int) ([]Bookmark, error)
- func (p Pinboard) RenTag(oldTag, newTag string) (bool, error)
- func (p Pinboard) Suggest(URL string) (Popular, Recommended, error)
- func (p Pinboard) Tags() ([]Tag, error)
- func (p Pinboard) Token() string
- type Popular
- type Post
- type Recommended
- type Tag
Constants ¶
const ( Major = 1 Minor = 0 Patch = 0 )
Semantic versioning - http://semver.org/
Variables ¶
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 ¶
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 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 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 (*Pinboard) Auth ¶
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) DelTag ¶
DelTag delete an existing tag, returns true if the delete operation succeeds.
func (Pinboard) Get ¶
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 ¶
IsAuthed checks if the user has been authenticated with the Pinboard service
func (Pinboard) LastUpdate ¶
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) Notes ¶
func (p Pinboard) Notes() ([]NoteMetadata, error)
Notes returns a list of the user's notes
func (Pinboard) Recent ¶
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 ¶
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.