diff --git a/integration/doc.go b/integration/doc.go deleted file mode 100644 index 8f83a9e5..00000000 --- a/integration/doc.go +++ /dev/null @@ -1,10 +0,0 @@ -// 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. - -/* - -Package integration implements API clients for third-party services. - -*/ -package integration // import "miniflux.app/integration" diff --git a/integration/instapaper/doc.go b/integration/instapaper/doc.go deleted file mode 100644 index d7c10e02..00000000 --- a/integration/instapaper/doc.go +++ /dev/null @@ -1,10 +0,0 @@ -// 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. - -/* - -Package instapaper provides an integration with Instapaper. - -*/ -package instapaper // import "miniflux.app/integration/instapaper" diff --git a/integration/instapaper/instapaper.go b/integration/instapaper/instapaper.go index a3973ff4..e333a177 100644 --- a/integration/instapaper/instapaper.go +++ b/integration/instapaper/instapaper.go @@ -17,6 +17,11 @@ type Client struct { password string } +// NewClient returns a new Instapaper client. +func NewClient(username, password string) *Client { + return &Client{username: username, password: password} +} + // AddURL sends a link to Instapaper. func (c *Client) AddURL(link, title string) error { if c.username == "" || c.password == "" { @@ -41,8 +46,3 @@ func (c *Client) AddURL(link, title string) error { return nil } - -// 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 index 2d5d38d9..db850f6c 100644 --- a/integration/integration.go +++ b/integration/integration.go @@ -16,9 +16,11 @@ import ( "miniflux.app/model" ) -// SendEntry send the entry to the activated providers. +// SendEntry sends the entry to third-party providers when the user click on "Save". func SendEntry(entry *model.Entry, integration *model.Integration) { if integration.PinboardEnabled { + logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Pinboard", entry.ID, entry.URL, integration.UserID) + client := pinboard.NewClient(integration.PinboardToken) err := client.AddBookmark( entry.URL, @@ -33,6 +35,8 @@ func SendEntry(entry *model.Entry, integration *model.Integration) { } if integration.InstapaperEnabled { + logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Instapaper", entry.ID, entry.URL, integration.UserID) + client := instapaper.NewClient(integration.InstapaperUsername, integration.InstapaperPassword) if err := client.AddURL(entry.URL, entry.Title); err != nil { logger.Error("[Integration] UserID #%d: %v", integration.UserID, err) @@ -40,6 +44,8 @@ func SendEntry(entry *model.Entry, integration *model.Integration) { } if integration.WallabagEnabled { + logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Wallabag", entry.ID, entry.URL, integration.UserID) + client := wallabag.NewClient( integration.WallabagURL, integration.WallabagClientID, @@ -54,6 +60,8 @@ func SendEntry(entry *model.Entry, integration *model.Integration) { } if integration.NunuxKeeperEnabled { + logger.Debug("[Integration] Sending Entry #%d %q for User #%d to NunuxKeeper", entry.ID, entry.URL, integration.UserID) + client := nunuxkeeper.NewClient( integration.NunuxKeeperURL, integration.NunuxKeeperAPIKey, @@ -65,6 +73,8 @@ func SendEntry(entry *model.Entry, integration *model.Integration) { } if integration.PocketEnabled { + logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Pocket", entry.ID, entry.URL, integration.UserID) + client := pocket.NewClient(config.Opts.PocketConsumerKey(integration.PocketConsumerKey), integration.PocketAccessToken) if err := client.AddURL(entry.URL, entry.Title); err != nil { logger.Error("[Integration] UserID #%d: %v", integration.UserID, err) @@ -72,11 +82,11 @@ func SendEntry(entry *model.Entry, integration *model.Integration) { } } -// PushEntry pushes new entry to the activated providers. -// This function should be wrapped in a goroutine to avoid block of program execution. +// PushEntry pushes an entry to third-party providers during feed refreshes. func PushEntry(entry *model.Entry, integration *model.Integration) { if integration.TelegramBotEnabled { - logger.Debug("[Integration] Sending Entry #%d for User #%d to telegram", entry.ID, integration.UserID) + logger.Debug("[Integration] Sending Entry %q for User #%d to Telegram", entry.URL, integration.UserID) + err := telegrambot.PushEntry(entry, integration.TelegramBotToken, integration.TelegramBotChatID) if err != nil { logger.Error("[Integration] push entry to telegram bot failed: %v", err) diff --git a/integration/nunuxkeeper/doc.go b/integration/nunuxkeeper/doc.go deleted file mode 100644 index c697c703..00000000 --- a/integration/nunuxkeeper/doc.go +++ /dev/null @@ -1,10 +0,0 @@ -// 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. - -/* - -Package nunuxkeeper provides an integration with the Nunux Keeper application. - -*/ -package nunuxkeeper // import "miniflux.app/integration/nunuxkeeper" diff --git a/integration/nunuxkeeper/nunuxkeeper.go b/integration/nunuxkeeper/nunuxkeeper.go index 87192d32..31e51d86 100644 --- a/integration/nunuxkeeper/nunuxkeeper.go +++ b/integration/nunuxkeeper/nunuxkeeper.go @@ -26,6 +26,11 @@ type Client struct { apiKey string } +// NewClient returns a new Nunux Keeepr client. +func NewClient(baseURL, apiKey string) *Client { + return &Client{baseURL: baseURL, apiKey: apiKey} +} + // AddEntry sends an entry to Nunux Keeper. func (c *Client) AddEntry(link, title, content string) error { if c.baseURL == "" || c.apiKey == "" { @@ -58,11 +63,6 @@ func (c *Client) AddEntry(link, title, content string) error { return nil } -// NewClient returns a new Nunux Keeepr client. -func NewClient(baseURL, apiKey string) *Client { - return &Client{baseURL: baseURL, apiKey: apiKey} -} - func getAPIEndpoint(baseURL, pathURL string) (string, error) { u, err := url.Parse(baseURL) if err != nil { diff --git a/integration/pinboard/doc.go b/integration/pinboard/doc.go deleted file mode 100644 index 49197d2c..00000000 --- a/integration/pinboard/doc.go +++ /dev/null @@ -1,10 +0,0 @@ -// 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. - -/* - -Package pinboard provides an integration with Pinboard. - -*/ -package pinboard // import "miniflux.app/integration/pinboard" diff --git a/integration/pinboard/pinboard.go b/integration/pinboard/pinboard.go index 4bef3cac..12bddf1b 100644 --- a/integration/pinboard/pinboard.go +++ b/integration/pinboard/pinboard.go @@ -16,6 +16,11 @@ type Client struct { authToken string } +// NewClient returns a new Pinboard client. +func NewClient(authToken string) *Client { + return &Client{authToken: authToken} +} + // AddBookmark sends a link to Pinboard. func (c *Client) AddBookmark(link, title, tags string, markAsUnread bool) error { if c.authToken == "" { @@ -46,8 +51,3 @@ func (c *Client) AddBookmark(link, title, tags string, markAsUnread bool) error return nil } - -// NewClient returns a new Pinboard client. -func NewClient(authToken string) *Client { - return &Client{authToken: authToken} -} diff --git a/integration/pocket/connector.go b/integration/pocket/connector.go index c33efac0..ab6796ab 100644 --- a/integration/pocket/connector.go +++ b/integration/pocket/connector.go @@ -18,6 +18,11 @@ type Connector struct { consumerKey string } +// NewConnector returns a new Pocket Connector. +func NewConnector(consumerKey string) *Connector { + return &Connector{consumerKey} +} + // RequestToken fetches a new request token from Pocket API. func (c *Connector) RequestToken(redirectURL string) (string, error) { type req struct { @@ -96,8 +101,3 @@ func (c *Connector) AuthorizationURL(requestToken, redirectURL string) string { redirectURL, ) } - -// NewConnector returns a new Pocket Connector. -func NewConnector(consumerKey string) *Connector { - return &Connector{consumerKey} -} diff --git a/integration/pocket/doc.go b/integration/pocket/doc.go deleted file mode 100644 index d644d6f4..00000000 --- a/integration/pocket/doc.go +++ /dev/null @@ -1,10 +0,0 @@ -// 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. - -/* - -Package pocket provides an integration with Pocket. - -*/ -package pocket // import "miniflux.app/integration/pocket" diff --git a/integration/pocket/pocket.go b/integration/pocket/pocket.go index 6f1b197c..52214e24 100644 --- a/integration/pocket/pocket.go +++ b/integration/pocket/pocket.go @@ -16,6 +16,11 @@ type Client struct { accessToken string } +// NewClient returns a new Pocket client. +func NewClient(consumerKey, accessToken string) *Client { + return &Client{consumerKey, accessToken} +} + // AddURL sends a single link to Pocket. func (c *Client) AddURL(link, title string) error { if c.consumerKey == "" || c.accessToken == "" { @@ -48,8 +53,3 @@ func (c *Client) AddURL(link, title string) error { return nil } - -// NewClient returns a new Pocket client. -func NewClient(consumerKey, accessToken string) *Client { - return &Client{consumerKey, accessToken} -} diff --git a/integration/telegrambot/doc.go b/integration/telegrambot/doc.go deleted file mode 100644 index c3605fa9..00000000 --- a/integration/telegrambot/doc.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package telegrambot provides a simple entry-to-telegram push -package telegrambot diff --git a/integration/telegrambot/telegrambot.go b/integration/telegrambot/telegrambot.go index e864e306..70377a6f 100644 --- a/integration/telegrambot/telegrambot.go +++ b/integration/telegrambot/telegrambot.go @@ -1,4 +1,8 @@ -package telegrambot +// Copyright 2021 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 telegrambot // import "miniflux.app/integration/telegrambot" import ( "bytes" @@ -14,27 +18,25 @@ import ( func PushEntry(entry *model.Entry, botToken, chatID string) error { bot, err := tgbotapi.NewBotAPI(botToken) if err != nil { - return fmt.Errorf("telegrambot: create bot failed: %w", err) + return fmt.Errorf("telegrambot: bot creation failed: %w", err) } - t, err := template.New("message").Parse("{{ .Title }}\n{{ .URL }}") + tpl, err := template.New("message").Parse("{{ .Title }}\n{{ .URL }}") if err != nil { - return fmt.Errorf("telegrambot: parse template failed: %w", err) + return fmt.Errorf("telegrambot: template parsing failed: %w", err) } var result bytes.Buffer - - err = t.Execute(&result, entry) - if err != nil { - return fmt.Errorf("telegrambot: execute template failed: %w", err) + if err := tpl.Execute(&result, entry); err != nil { + return fmt.Errorf("telegrambot: template execution failed: %w", err) } - chatId, _ := strconv.ParseInt(chatID, 10, 64) - msg := tgbotapi.NewMessage(chatId, result.String()) + chatIDInt, _ := strconv.ParseInt(chatID, 10, 64) + msg := tgbotapi.NewMessage(chatIDInt, result.String()) msg.ParseMode = tgbotapi.ModeHTML msg.DisableWebPagePreview = false if _, err := bot.Send(msg); err != nil { - return fmt.Errorf("telegrambot: send message failed: %w", err) + return fmt.Errorf("telegrambot: sending message failed: %w", err) } return nil diff --git a/integration/wallabag/doc.go b/integration/wallabag/doc.go deleted file mode 100644 index d2ada9a7..00000000 --- a/integration/wallabag/doc.go +++ /dev/null @@ -1,10 +0,0 @@ -// 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. - -/* - -Package wallabag provides an integration with the Wallabag application. - -*/ -package wallabag // import "miniflux.app/integration/wallabag" diff --git a/integration/wallabag/wallabag.go b/integration/wallabag/wallabag.go index f6f3a651..55c4ab46 100644 --- a/integration/wallabag/wallabag.go +++ b/integration/wallabag/wallabag.go @@ -22,6 +22,11 @@ type Client struct { password string } +// NewClient returns a new Wallabag client. +func NewClient(baseURL, clientID, clientSecret, username, password string) *Client { + return &Client{baseURL, clientID, clientSecret, username, password} +} + // AddEntry sends a link to Wallabag. // Pass an empty string in `content` to let Wallabag fetch the article content. func (c *Client) AddEntry(link, title, content string) error { @@ -88,11 +93,6 @@ func (c *Client) getAccessToken() (string, error) { return token.AccessToken, nil } -// NewClient returns a new Wallabag client. -func NewClient(baseURL, clientID, clientSecret, username, password string) *Client { - return &Client{baseURL, clientID, clientSecret, username, password} -} - func getAPIEndpoint(baseURL, path string) (string, error) { u, err := url.Parse(baseURL) if err != nil { diff --git a/template/templates/views/integrations.html b/template/templates/views/integrations.html index 8b9ecbb9..b89e26f1 100644 --- a/template/templates/views/integrations.html +++ b/template/templates/views/integrations.html @@ -153,7 +153,6 @@ -