diff --git a/integration/integration.go b/integration/integration.go index 42e13f98..d853773f 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 00000000..a46cd301 --- /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} +} diff --git a/locale/translations.go b/locale/translations.go index e828234a..d5c4e163 100755 --- a/locale/translations.go +++ b/locale/translations.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2018-04-29 16:59:49.591693595 -0700 PDT m=+0.022587229 +// 2018-05-20 11:35:19.498340382 -0700 PDT m=+0.010175046 package locale diff --git a/model/integration.go b/model/integration.go index 721c701f..e4282a48 100644 --- a/model/integration.go +++ b/model/integration.go @@ -27,4 +27,7 @@ type Integration struct { NunuxKeeperEnabled bool NunuxKeeperURL string NunuxKeeperAPIKey string + PocketEnabled bool + PocketAccessToken string + PocketConsumerKey string } diff --git a/sql/schema_version_17.sql b/sql/schema_version_17.sql new file mode 100644 index 00000000..b4cc8487 --- /dev/null +++ b/sql/schema_version_17.sql @@ -0,0 +1,3 @@ +alter table integrations add column pocket_enabled bool default 'f'; +alter table integrations add column pocket_access_token text default ''; +alter table integrations add column pocket_consumer_key text default ''; diff --git a/sql/sql.go b/sql/sql.go index d576d8d6..4dcf761c 100644 --- a/sql/sql.go +++ b/sql/sql.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2018-04-06 23:00:49.983090069 +0100 BST m=+0.002610702 +// 2018-05-20 11:35:19.489434225 -0700 PDT m=+0.001268896 package sql @@ -131,6 +131,10 @@ alter table integrations add column nunux_keeper_url text default ''; alter table integrations add column nunux_keeper_api_key text default '';`, "schema_version_15": `alter table enclosures alter column size set data type bigint;`, "schema_version_16": `alter table entries add column comments_url text default '';`, + "schema_version_17": `alter table integrations add column pocket_enabled bool default 'f'; +alter table integrations add column pocket_access_token text default ''; +alter table integrations add column pocket_consumer_key text default ''; +`, "schema_version_2": `create extension if not exists hstore; alter table users add column extra hstore; create index users_extra_idx on users using gin(extra); @@ -178,6 +182,7 @@ var SqlMapChecksums = map[string]string{ "schema_version_14": "4622e42c4a5a88b6fe1e61f3d367b295968f7260ab5b96481760775ba9f9e1fe", "schema_version_15": "13ff91462bdf4cda5a94a4c7a09f757761b0f2c32b4be713ba4786a4837750e4", "schema_version_16": "9d006faca62fd7ab787f64aef0e0a5933d142466ec4cab0e096bb920d2797e34", + "schema_version_17": "b9f15d6217275fedcf6d948dd85ebe978b869bf37f42a86fd5b50a51919fa0e1", "schema_version_2": "e8e9ff32478df04fcddad10a34cba2e8bb1e67e7977b5bd6cdc4c31ec94282b4", "schema_version_3": "a54745dbc1c51c000f74d4e5068f1e2f43e83309f023415b1749a47d5c1e0f12", "schema_version_4": "216ea3a7d3e1704e40c797b5dc47456517c27dbb6ca98bf88812f4f63d74b5d9", diff --git a/storage/integration.go b/storage/integration.go index 6a389de9..5a7ef193 100644 --- a/storage/integration.go +++ b/storage/integration.go @@ -70,7 +70,10 @@ func (s *Storage) Integration(userID int64) (*model.Integration, error) { wallabag_password, nunux_keeper_enabled, nunux_keeper_url, - nunux_keeper_api_key + nunux_keeper_api_key, + pocket_enabled, + pocket_access_token, + pocket_consumer_key FROM integrations WHERE user_id=$1 ` @@ -97,6 +100,9 @@ func (s *Storage) Integration(userID int64) (*model.Integration, error) { &integration.NunuxKeeperEnabled, &integration.NunuxKeeperURL, &integration.NunuxKeeperAPIKey, + &integration.PocketEnabled, + &integration.PocketAccessToken, + &integration.PocketConsumerKey, ) switch { case err == sql.ErrNoRows: @@ -131,8 +137,11 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error { wallabag_password=$17, nunux_keeper_enabled=$18, nunux_keeper_url=$19, - nunux_keeper_api_key=$20 - WHERE user_id=$21 + nunux_keeper_api_key=$20, + pocket_enabled=$21, + pocket_access_token=$22, + pocket_consumer_key=$23 + WHERE user_id=$24 ` _, err := s.db.Exec( query, @@ -156,6 +165,9 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error { integration.NunuxKeeperEnabled, integration.NunuxKeeperURL, integration.NunuxKeeperAPIKey, + integration.PocketEnabled, + integration.PocketAccessToken, + integration.PocketConsumerKey, integration.UserID, ) @@ -182,7 +194,7 @@ func (s *Storage) HasSaveEntry(userID int64) (result bool) { query := ` SELECT true FROM integrations WHERE user_id=$1 AND - (pinboard_enabled='t' OR instapaper_enabled='t' OR wallabag_enabled='t' OR nunux_keeper_enabled='t') + (pinboard_enabled='t' OR instapaper_enabled='t' OR wallabag_enabled='t' OR nunux_keeper_enabled='t' OR pocket_enabled='t') ` if err := s.db.QueryRow(query, userID).Scan(&result); err != nil { diff --git a/storage/migration.go b/storage/migration.go index d7d40e83..ab44d175 100644 --- a/storage/migration.go +++ b/storage/migration.go @@ -12,7 +12,7 @@ import ( "github.com/miniflux/miniflux/sql" ) -const schemaVersion = 16 +const schemaVersion = 17 // Migrate run database migrations. func (s *Storage) Migrate() { diff --git a/template/common.go b/template/common.go index f573ba15..8519d0cb 100644 --- a/template/common.go +++ b/template/common.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2018-04-29 17:36:50.459886967 -0700 PDT m=+0.024552529 +// 2018-05-20 11:35:19.497832269 -0700 PDT m=+0.009666945 package template diff --git a/template/html/integrations.html b/template/html/integrations.html index 7e3d2f4a..b4a70a55 100644 --- a/template/html/integrations.html +++ b/template/html/integrations.html @@ -94,7 +94,7 @@ - +