aboutsummaryrefslogtreecommitdiffhomepage
path: root/integration
diff options
context:
space:
mode:
Diffstat (limited to 'integration')
-rw-r--r--integration/integration.go9
-rw-r--r--integration/pocket/pocket.go52
2 files changed, 61 insertions, 0 deletions
diff --git a/integration/integration.go b/integration/integration.go
index 42e13f9..d853773 100644
--- a/integration/integration.go
+++ b/integration/integration.go
@@ -8,6 +8,7 @@ import (
"github.com/miniflux/miniflux/integration/instapaper"
"github.com/miniflux/miniflux/integration/nunuxkeeper"
"github.com/miniflux/miniflux/integration/pinboard"
+ "github.com/miniflux/miniflux/integration/pocket"
"github.com/miniflux/miniflux/integration/wallabag"
"github.com/miniflux/miniflux/logger"
"github.com/miniflux/miniflux/model"
@@ -60,4 +61,12 @@ func SendEntry(entry *model.Entry, integration *model.Integration) {
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
}
}
+
+ if integration.PocketEnabled {
+ client := pocket.NewClient(integration.PocketAccessToken, integration.PocketConsumerKey)
+ if err := client.AddURL(entry.URL, entry.Title); err != nil {
+ logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
+ }
+ }
+
}
diff --git a/integration/pocket/pocket.go b/integration/pocket/pocket.go
new file mode 100644
index 0000000..a46cd30
--- /dev/null
+++ b/integration/pocket/pocket.go
@@ -0,0 +1,52 @@
+// 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 pocket
+
+import (
+ "fmt"
+
+ "github.com/miniflux/miniflux/http/client"
+)
+
+// Client represents a Pocket client.
+type Client struct {
+ accessToken string
+ 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{
+ AccessToken: c.accessToken,
+ ConsumerKey: c.consumerKey,
+ Title: title,
+ URL: link,
+ }
+
+ clt := client.New("https://getpocket.com/v3/add")
+ response, err := clt.PostJSON(parameters)
+ if response.HasServerFailure() {
+ return fmt.Errorf("pocket: unable to send url, status=%d", response.StatusCode)
+ }
+
+ return err
+}
+
+// NewClient returns a new Pocket client.
+func NewClient(accessToken, consumerKey string) *Client {
+ return &Client{accessToken: accessToken, consumerKey: consumerKey}
+}