Minor improvements in integration package

This commit is contained in:
Frédéric Guillot 2021-09-07 20:28:41 -07:00 committed by fguillot
parent 34dd358eb0
commit 49119eff00
16 changed files with 57 additions and 108 deletions

View File

@ -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"

View File

@ -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"

View File

@ -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}
}

View File

@ -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)

View File

@ -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"

View File

@ -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 {

View File

@ -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"

View File

@ -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}
}

View File

@ -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}
}

View File

@ -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"

View File

@ -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}
}

View File

@ -1,2 +0,0 @@
// Package telegrambot provides a simple entry-to-telegram push
package telegrambot

View File

@ -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<a href=\"{{ .URL }}\">{{ .URL }}</a>")
tpl, err := template.New("message").Parse("{{ .Title }}\n<a href=\"{{ .URL }}\">{{ .URL }}</a>")
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

View File

@ -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"

View File

@ -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 {

View File

@ -153,7 +153,6 @@
</div>
</div>
</form>
<h3>{{ t "page.integration.bookmarklet" }}</h3>