From 0f3f5e442f81d37a03618d0df5ea8f0524a24029 Mon Sep 17 00:00:00 2001 From: Allan Reyes Date: Sun, 20 May 2018 13:31:56 -0700 Subject: Add Pocket integration --- integration/integration.go | 9 +++++++ integration/pocket/pocket.go | 52 +++++++++++++++++++++++++++++++++++++++++ locale/translations.go | 2 +- model/integration.go | 3 +++ sql/schema_version_17.sql | 3 +++ sql/sql.go | 7 +++++- storage/integration.go | 20 ++++++++++++---- storage/migration.go | 2 +- template/common.go | 2 +- template/html/integrations.html | 15 +++++++++++- template/views.go | 19 ++++++++++++--- ui/form/integration.go | 9 +++++++ ui/integration_show.go | 3 +++ ui/static/bin.go | 2 +- ui/static/css.go | 2 +- ui/static/js.go | 2 +- 16 files changed, 137 insertions(+), 15 deletions(-) create mode 100644 integration/pocket/pocket.go create mode 100644 sql/schema_version_17.sql 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} +} diff --git a/locale/translations.go b/locale/translations.go index e828234..d5c4e16 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 721c701..e4282a4 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 0000000..b4cc848 --- /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 d576d8d..4dcf761 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 6a389de..5a7ef19 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 d7d40e8..ab44d17 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 f573ba1..8519d0c 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 7e3d2f4..b4a70a5 100644 --- a/template/html/integrations.html +++ b/template/html/integrations.html @@ -94,7 +94,7 @@ - +

Nunux Keeper

+

Pocket

+
+ + + + + + + +
+
diff --git a/template/views.go b/template/views.go index 3c2167a..57031bb 100644 --- a/template/views.go +++ b/template/views.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2018-04-29 17:36:50.450844913 -0700 PDT m=+0.015510475 +// 2018-05-20 11:35:19.495047296 -0700 PDT m=+0.006881961 package template @@ -907,7 +907,7 @@ var templateViewsMap = map[string]string{ - +

Nunux Keeper

+

Pocket

+
+ + + + + + + +
+
@@ -1246,7 +1259,7 @@ var templateViewsMapChecksums = map[string]string{ "feeds": "2a5abe37968ea34a0576dbef52341645cb1fc9562e351382fbf721491da6f4fa", "history_entries": "451f0b202f47c9db5344d3e73862f5b7afbd4323fbdba21b6087866c40f045d3", "import": "73b5112e20bfd232bf73334544186ea419505936bc237d481517a8622901878f", - "integrations": "979193f39c2a3b43cec192aa119713cc9cbe2d5fdaedf8d2b3573c752823446c", + "integrations": "919b73a7dec91c2973db840eecf709de1e2e004f5a592d7e377ef1cb0926adce", "login": "7d83c3067c02f1f6aafdd8816c7f97a4eb5a5a4bdaaaa4cc1e2fbb9c17ea65e8", "sessions": "3fa79031dd883847eba92fbafe5f535fa3a4e1614bb610f20588b6f8fc8b3624", "settings": "ea2505b9d0a6d6bb594dba87a92079de19baa6d494f0651693a7685489fb7de9", diff --git a/ui/form/integration.go b/ui/form/integration.go index f8cadaf..db095aa 100644 --- a/ui/form/integration.go +++ b/ui/form/integration.go @@ -31,6 +31,9 @@ type IntegrationForm struct { NunuxKeeperEnabled bool NunuxKeeperURL string NunuxKeeperAPIKey string + PocketEnabled bool + PocketAccessToken string + PocketConsumerKey string } // Merge copy form values to the model. @@ -54,6 +57,9 @@ func (i IntegrationForm) Merge(integration *model.Integration) { integration.NunuxKeeperEnabled = i.NunuxKeeperEnabled integration.NunuxKeeperURL = i.NunuxKeeperURL integration.NunuxKeeperAPIKey = i.NunuxKeeperAPIKey + integration.PocketEnabled = i.PocketEnabled + integration.PocketAccessToken = i.PocketAccessToken + integration.PocketConsumerKey = i.PocketConsumerKey } // NewIntegrationForm returns a new AuthForm. @@ -78,5 +84,8 @@ func NewIntegrationForm(r *http.Request) *IntegrationForm { NunuxKeeperEnabled: r.FormValue("nunux_keeper_enabled") == "1", NunuxKeeperURL: r.FormValue("nunux_keeper_url"), NunuxKeeperAPIKey: r.FormValue("nunux_keeper_api_key"), + PocketEnabled: r.FormValue("pocket_enabled") == "1", + PocketAccessToken: r.FormValue("pocket_access_token"), + PocketConsumerKey: r.FormValue("pocket_consumer_key"), } } diff --git a/ui/integration_show.go b/ui/integration_show.go index 703f610..d368d85 100644 --- a/ui/integration_show.go +++ b/ui/integration_show.go @@ -50,6 +50,9 @@ func (c *Controller) ShowIntegrations(w http.ResponseWriter, r *http.Request) { NunuxKeeperEnabled: integration.NunuxKeeperEnabled, NunuxKeeperURL: integration.NunuxKeeperURL, NunuxKeeperAPIKey: integration.NunuxKeeperAPIKey, + PocketEnabled: integration.PocketEnabled, + PocketAccessToken: integration.PocketAccessToken, + PocketConsumerKey: integration.PocketConsumerKey, } sess := session.New(c.store, ctx) diff --git a/ui/static/bin.go b/ui/static/bin.go index 4db4b0a..a5c0ed0 100644 --- a/ui/static/bin.go +++ b/ui/static/bin.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2018-02-24 17:47:34.994475549 +0000 GMT +// 2018-05-20 11:35:19.492969127 -0700 PDT m=+0.004803782 package static diff --git a/ui/static/css.go b/ui/static/css.go index f29d789..8e28baf 100644 --- a/ui/static/css.go +++ b/ui/static/css.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2018-05-19 15:45:16.654304958 -0700 PDT m=+0.017095824 +// 2018-05-20 11:35:19.493979584 -0700 PDT m=+0.005814260 package static diff --git a/ui/static/js.go b/ui/static/js.go index aefa198..b507236 100644 --- a/ui/static/js.go +++ b/ui/static/js.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2018-02-24 17:47:34.995856638 +0000 GMT +// 2018-05-20 11:35:19.494515654 -0700 PDT m=+0.006350329 package static -- cgit v1.2.3