[server] Delete the subscriber on listmonk when needed
This commit is contained in:
parent
5904e3dd2c
commit
c32badc82c
1 changed files with 5 additions and 12 deletions
|
@ -3,6 +3,7 @@ package controller
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ente-io/museum/pkg/external/listmonk"
|
"github.com/ente-io/museum/pkg/external/listmonk"
|
||||||
|
@ -221,25 +222,17 @@ func (c *MailingListsController) listmonkSubscribe(email string) error {
|
||||||
|
|
||||||
// Unsubscribes an email address to a particular listmonk campaign mailing list
|
// Unsubscribes an email address to a particular listmonk campaign mailing list
|
||||||
func (c *MailingListsController) listmonkUnsubscribe(email string) error {
|
func (c *MailingListsController) listmonkUnsubscribe(email string) error {
|
||||||
// Listmonk dosen't provide an endpoint for unsubscribing users
|
// Listmonk doesn't provide an endpoint for unsubscribing users
|
||||||
// from a particular list directly via their email
|
// from a particular list directly via their email
|
||||||
//
|
//
|
||||||
// Thus, fetching subscriberID through email address,
|
// Thus, fetching subscriberID through email address,
|
||||||
// and then calling endpoint to modify subscription in a list
|
// and then calling the endpoint to delete that user
|
||||||
id, err := listmonk.GetSubscriberID(c.listmonkCredentials.BaseURL+"/api/subscribers",
|
id, err := listmonk.GetSubscriberID(c.listmonkCredentials.BaseURL+"/api/subscribers",
|
||||||
c.listmonkCredentials.Username, c.listmonkCredentials.Password, email)
|
c.listmonkCredentials.Username, c.listmonkCredentials.Password, email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
stacktrace.Propagate(err, "")
|
stacktrace.Propagate(err, "")
|
||||||
}
|
}
|
||||||
// API endpoint expects an array of subscriber id as parameter
|
|
||||||
subscriberID := []int{id}
|
|
||||||
|
|
||||||
data := map[string]interface{}{
|
return listmonk.SendRequest("DELETE", c.listmonkCredentials.BaseURL+"/api/subscribers/"+strconv.Itoa(id),
|
||||||
"ids": subscriberID,
|
map[string]interface{}{}, c.listmonkCredentials.Username, c.listmonkCredentials.Password)
|
||||||
"action": "remove",
|
|
||||||
"target_list_ids": c.listmonkListIDs,
|
|
||||||
}
|
|
||||||
|
|
||||||
return listmonk.SendRequest("PUT", c.listmonkCredentials.BaseURL+"/api/subscribers/lists", data,
|
|
||||||
c.listmonkCredentials.Username, c.listmonkCredentials.Password)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue