aboutsummaryrefslogtreecommitdiffhomepage
path: root/integration
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2017-12-02 21:12:03 -0800
committerGravatar Frédéric Guillot <fred@miniflux.net>2017-12-02 21:12:03 -0800
commitae62e543d3a1173cd39f1910cb67c95a56a7a6a4 (patch)
treee086a53f0ad609b648e523dc5198a4d48430ab91 /integration
parent6f5350a4978c7ef6fa68e526ec8a2ba917d33953 (diff)
Add Instapaper integration
Diffstat (limited to 'integration')
-rw-r--r--integration/instapaper/instapaper.go39
-rw-r--r--integration/integration.go32
-rw-r--r--integration/pinboard/pinboard.go2
3 files changed, 72 insertions, 1 deletions
diff --git a/integration/instapaper/instapaper.go b/integration/instapaper/instapaper.go
new file mode 100644
index 0000000..c484573
--- /dev/null
+++ b/integration/instapaper/instapaper.go
@@ -0,0 +1,39 @@
+// 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 instapaper
+
+import (
+ "fmt"
+ "net/url"
+
+ "github.com/miniflux/miniflux2/http"
+)
+
+// Client represents an Instapaper client.
+type Client struct {
+ username string
+ password string
+}
+
+// AddURL sends a link to Instapaper.
+func (c *Client) AddURL(link, title string) error {
+ values := url.Values{}
+ values.Add("url", link)
+ values.Add("title", title)
+
+ apiURL := "https://www.instapaper.com/api/add?" + values.Encode()
+ client := http.NewClientWithCredentials(apiURL, c.username, c.password)
+ response, err := client.Get()
+ if response.HasServerFailure() {
+ return fmt.Errorf("unable to send bookmark to instapaper, status=%d", response.StatusCode)
+ }
+
+ return err
+}
+
+// NewClient returns a new Instapaper client.
+func NewClient(username, password string) *Client {
+ return &Client{username: username, password: password}
+}
diff --git a/integration/integration.go b/integration/integration.go
new file mode 100644
index 0000000..074ce6d
--- /dev/null
+++ b/integration/integration.go
@@ -0,0 +1,32 @@
+// 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 integration
+
+import (
+ "log"
+
+ "github.com/miniflux/miniflux2/integration/instapaper"
+ "github.com/miniflux/miniflux2/integration/pinboard"
+ "github.com/miniflux/miniflux2/model"
+)
+
+// SendEntry send the entry to the activated providers.
+func SendEntry(entry *model.Entry, integration *model.Integration) {
+ if integration.PinboardEnabled {
+ client := pinboard.NewClient(integration.PinboardToken)
+ err := client.AddBookmark(entry.URL, entry.Title, integration.PinboardTags, integration.PinboardMarkAsUnread)
+ if err != nil {
+ log.Println("[Pinboard]", err)
+ }
+ }
+
+ if integration.InstapaperEnabled {
+ client := instapaper.NewClient(integration.InstapaperUsername, integration.InstapaperPassword)
+ err := client.AddURL(entry.URL, entry.Title)
+ if err != nil {
+ log.Println("[Instapaper]", err)
+ }
+ }
+}
diff --git a/integration/pinboard/pinboard.go b/integration/pinboard/pinboard.go
index d965458..7e33065 100644
--- a/integration/pinboard/pinboard.go
+++ b/integration/pinboard/pinboard.go
@@ -11,7 +11,7 @@ import (
"github.com/miniflux/miniflux2/http"
)
-// Client represents a Pinboard token.
+// Client represents a Pinboard client.
type Client struct {
authToken string
}