1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-01 17:38:37 +00:00

Add Pocket authorization flow in the user interface

This commit is contained in:
Frédéric Guillot 2018-05-20 15:29:14 -07:00
parent 0f3f5e442f
commit 7f2fd1fdd8
18 changed files with 286 additions and 54 deletions

View file

@ -1,4 +1,4 @@
// Copyright 2017 Frédéric Guillot. All rights reserved.
// Copyright 2018 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.
@ -16,21 +16,20 @@ type Client struct {
consumerKey string
}
// Parameters for a Pocket add call.
type Parameters struct {
AccessToken string `json:"access_token"`
ConsumerKey string `json:"consumer_key"`
Title string `json:"title,omitempty"`
URL string `json:"url,omitempty"`
}
// AddURL sends a single link to Pocket.
func (c *Client) AddURL(link, title string) error {
if c.consumerKey == "" || c.accessToken == "" {
return fmt.Errorf("pocket: missing credentials")
}
parameters := &Parameters{
type body struct {
AccessToken string `json:"access_token"`
ConsumerKey string `json:"consumer_key"`
Title string `json:"title,omitempty"`
URL string `json:"url"`
}
data := &body{
AccessToken: c.accessToken,
ConsumerKey: c.consumerKey,
Title: title,
@ -38,12 +37,16 @@ func (c *Client) AddURL(link, title string) error {
}
clt := client.New("https://getpocket.com/v3/add")
response, err := clt.PostJSON(parameters)
response, err := clt.PostJSON(data)
if err != nil {
return fmt.Errorf("pocket: unable to send url: %v", err)
}
if response.HasServerFailure() {
return fmt.Errorf("pocket: unable to send url, status=%d", response.StatusCode)
}
return err
return nil
}
// NewClient returns a new Pocket client.