diff options
author | Frédéric Guillot <fred@miniflux.net> | 2017-12-02 19:32:14 -0800 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2017-12-02 19:32:14 -0800 |
commit | 2356ddad28d50aacc8bbb3e020792d3b92f2fb4d (patch) | |
tree | a881d13d2fcc2e0d0fef2f7d26cfd2d6b044209f /integration | |
parent | 2f1367a8d4c33e7c6ba459cfc6756e079c7a1af4 (diff) |
Add Pinboard integration
Diffstat (limited to 'integration')
-rw-r--r-- | integration/pinboard/pinboard.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/integration/pinboard/pinboard.go b/integration/pinboard/pinboard.go new file mode 100644 index 0000000..4179483 --- /dev/null +++ b/integration/pinboard/pinboard.go @@ -0,0 +1,45 @@ +// Copyright 2017 Frédéric Guillot. All rights reserved. +// Use of this source code is governed by the Apache 2.0 +// license that can be found in the LICENSE file. + +package pinboard + +import ( + "fmt" + "net/url" + + "github.com/miniflux/miniflux2/reader/http" +) + +// Client represents a Pinboard token. +type Client struct { + authToken string +} + +// AddBookmark sends a link to Pinboard. +func (c *Client) AddBookmark(link, title, tags string, markAsUnread bool) error { + toRead := "no" + if markAsUnread { + toRead = "yes" + } + + values := url.Values{} + values.Add("auth_token", c.authToken) + values.Add("url", link) + values.Add("description", title) + values.Add("tags", tags) + values.Add("toread", toRead) + + client := http.NewClient("https://api.pinboard.in/v1/posts/add?" + values.Encode()) + response, err := client.Get() + if response.HasServerFailure() { + return fmt.Errorf("unable to send bookmark to pinboard, status=%d", response.StatusCode) + } + + return err +} + +// NewClient returns a new Pinboard client. +func NewClient(authToken string) *Client { + return &Client{authToken: authToken} +} |