1
0
Fork 0
miniflux/integration/pinboard/pinboard.go

46 lines
1.1 KiB
Go
Raw Normal View History

2017-12-02 22:32:14 -05:00
// 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"
2017-12-13 00:48:13 -05:00
"github.com/miniflux/miniflux/http"
2017-12-02 22:32:14 -05:00
)
2017-12-03 00:12:03 -05:00
// Client represents a Pinboard client.
2017-12-02 22:32:14 -05:00
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() {
2017-12-18 23:52:46 -05:00
return fmt.Errorf("pinboard: unable to send bookmark, status=%d", response.StatusCode)
2017-12-02 22:32:14 -05:00
}
return err
}
// NewClient returns a new Pinboard client.
func NewClient(authToken string) *Client {
return &Client{authToken: authToken}
}