Skip to content

Commit

Permalink
feat: add GetEndorsements method
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamandlou authored and mattn committed May 4, 2024
1 parent b8ed081 commit a0bda56
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ func main() {
* [x] GET /api/v1/streaming/hashtag/local?tag=:hashtag
* [x] GET /api/v1/streaming/list?list=:list_id
* [x] GET /api/v1/streaming/direct
* [x] GET /api/v1/endorsements

## Installation

Expand Down
10 changes: 10 additions & 0 deletions accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ func (c *Client) GetBlocks(ctx context.Context, pg *Pagination) ([]*Account, err
return accounts, nil
}

// GetEndorsements return accounts that the user is currently featuring on their profile.
func (c *Client) GetEndorsements(ctx context.Context, pg *Pagination) ([]*Account, error) {
var accounts []*Account
err := c.doAPI(ctx, http.MethodGet, "/api/v1/endorsements", nil, &accounts, pg)
if err != nil {
return nil, err
}
return accounts, nil
}

// Relationship holds information for relationship to the account.
type Relationship struct {
ID ID `json:"id"`
Expand Down
87 changes: 87 additions & 0 deletions accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,93 @@ func TestGetBlocks(t *testing.T) {
}
}

func TestGetEndorsements(t *testing.T) {
canErr := true
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if canErr {
canErr = false
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
fmt.Fprintln(w, `[
{
"id": "952529",
"username": "foo",
"acct": "alayna@desvox.es",
"display_name": "Alayna Desirae",
"locked": true,
"bot": false,
"created_at": "2019-10-26T23:12:06.570Z",
"note": "experiencing ________ difficulties<br>22y/o INFP in Oklahoma",
"url": "https://desvox.es/users/alayna",
"avatar": "https://files.mastodon.social/accounts/avatars/000/952/529/original/6534122046d050d5.png",
"avatar_static": "https://files.mastodon.social/accounts/avatars/000/952/529/original/6534122046d050d5.png",
"header": "https://files.mastodon.social/accounts/headers/000/952/529/original/496f1f817e042ade.png",
"header_static": "https://files.mastodon.social/accounts/headers/000/952/529/original/496f1f817e042ade.png",
"followers_count": 0,
"following_count": 0,
"statuses_count": 955,
"last_status_at": "2019-11-23T07:05:50.682Z",
"emojis": [],
"fields": []
},
{
"id": "832844",
"username": "bar",
"acct": "a9@broadcast.wolfgirl.engineering",
"display_name": "vivienne :collar: ",
"locked": true,
"bot": false,
"created_at": "2019-06-12T18:55:12.053Z",
"note": "borderline nsfw, considered a schedule I drug by nixon<br>waiting for the year of the illumos desktop",
"url": "https://broadcast.wolfgirl.engineering/users/a9",
"avatar": "https://files.mastodon.social/accounts/avatars/000/832/844/original/ae1de0b8fb63d1c6.png",
"avatar_static": "https://files.mastodon.social/accounts/avatars/000/832/844/original/ae1de0b8fb63d1c6.png",
"header": "https://files.mastodon.social/accounts/headers/000/832/844/original/5088e4a16e6d8736.png",
"header_static": "https://files.mastodon.social/accounts/headers/000/832/844/original/5088e4a16e6d8736.png",
"followers_count": 43,
"following_count": 67,
"statuses_count": 5906,
"last_status_at": "2019-11-23T05:23:47.911Z",
"emojis": [
{
"shortcode": "collar",
"url": "https://files.mastodon.social/custom_emojis/images/000/106/920/original/80953b9cd96ec4dc.png",
"static_url": "https://files.mastodon.social/custom_emojis/images/000/106/920/static/80953b9cd96ec4dc.png",
"visible_in_picker": true
}
],
"fields": []
}
]`)
}))
defer ts.Close()

client := NewClient(&Config{
Server: ts.URL,
ClientID: "foo",
ClientSecret: "bar",
AccessToken: "zoo",
})
_, err := client.GetEndorsements(context.Background(), nil)
if err == nil {
t.Fatalf("should be fail: %v", err)
}
endorsements, err := client.GetEndorsements(context.Background(), nil)
if err != nil {
t.Fatalf("should not be fail: %v", err)
}
if len(endorsements) != 2 {
t.Fatalf("result should be two: %d", len(endorsements))
}
if endorsements[0].Username != "foo" {
t.Fatalf("want %q but %q", "foo", endorsements[0].Username)
}
if endorsements[1].Username != "bar" {
t.Fatalf("want %q but %q", "bar", endorsements[1].Username)
}
}

func TestAccountFollow(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/api/v1/accounts/1234567/follow" {
Expand Down

0 comments on commit a0bda56

Please sign in to comment.