Add endorsement commands (GetEndorsements, {Pin,Unpin}Account)
authorMikael Berthe <mikael@lilotux.net>
Wed, 05 Sep 2018 22:55:20 +0200
changeset 235 263da7f71f03
parent 234 e37050f8a4bf
child 236 5b87cc73ed97
Add endorsement commands (GetEndorsements, {Pin,Unpin}Account)
account.go
endorsements.go
--- a/account.go	Wed Sep 05 13:11:54 2018 +0200
+++ b/account.go	Wed Sep 05 22:55:20 2018 +0200
@@ -55,7 +55,7 @@
 	strID := strconv.FormatInt(id, 10)
 
 	switch op {
-	case "follow", "unfollow", "block", "unblock", "mute", "unmute":
+	case "follow", "unfollow", "block", "unblock", "mute", "unmute", "pin", "unpin":
 		endPoint = "accounts/" + strID + "/" + op
 	default:
 		return nil, ErrInvalidParameter
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/endorsements.go	Wed Sep 05 22:55:20 2018 +0200
@@ -0,0 +1,46 @@
+/*
+Copyright 2018 Mikael Berthe
+
+Licensed under the MIT license.  Please see the LICENSE file is this directory.
+*/
+
+package madon
+
+import (
+	"github.com/sendgrid/rest"
+)
+
+// GetEndorsements returns the list of user's endorsements
+func (mc *Client) GetEndorsements(lopt *LimitParams) ([]Account, error) {
+	endPoint := "endorsements"
+	method := rest.Get
+	var accountList []Account
+	if err := mc.apiCall(endPoint, method, nil, lopt, nil, &accountList); err != nil {
+		return nil, err
+	}
+	return accountList, nil
+}
+
+// PinAccount adds the account to the endorsement list
+func (mc *Client) PinAccount(accountID int64) (*Relationship, error) {
+	rel, err := mc.updateRelationship("pin", accountID, nil)
+	if err != nil {
+		return nil, err
+	}
+	if rel == nil {
+		return nil, ErrEntityNotFound
+	}
+	return rel, nil
+}
+
+// UnpinAccount removes the account from the endorsement list
+func (mc *Client) UnpinAccount(accountID int64) (*Relationship, error) {
+	rel, err := mc.updateRelationship("unpin", accountID, nil)
+	if err != nil {
+		return nil, err
+	}
+	if rel == nil {
+		return nil, ErrEntityNotFound
+	}
+	return rel, nil
+}