From c6122d07d2494ca115bcedd0efc9c91e827ee92b Mon Sep 17 00:00:00 2001 From: Balazs Nadasdi Date: Sat, 19 Mar 2022 21:56:36 +0100 Subject: [PATCH] feat: Implement Following endpoints (#84) Closes #10 --- README.md | 2 +- services.go | 6 ++ services/following/create.go | 38 ++++++++++++ services/following/create_test.go | 56 +++++++++++++++++ services/following/delete.go | 38 ++++++++++++ services/following/delete_test.go | 56 +++++++++++++++++ services/following/fixtures/user.json | 12 ++++ services/following/invalidate.go | 38 ++++++++++++ services/following/invalidate_test.go | 56 +++++++++++++++++ services/following/requests/accept.go | 35 +++++++++++ services/following/requests/accept_test.go | 54 ++++++++++++++++ services/following/requests/cancel.go | 38 ++++++++++++ services/following/requests/cancel_test.go | 56 +++++++++++++++++ services/following/requests/fixtures/empty | 0 .../following/requests/fixtures/list.json | 43 +++++++++++++ .../following/requests/fixtures/user.json | 12 ++++ services/following/requests/list.go | 33 ++++++++++ services/following/requests/list_test.go | 61 +++++++++++++++++++ services/following/requests/reject.go | 35 +++++++++++ services/following/requests/reject_test.go | 54 ++++++++++++++++ services/following/requests/service.go | 13 ++++ services/following/service.go | 21 +++++++ 22 files changed, 756 insertions(+), 1 deletion(-) create mode 100644 services/following/create.go create mode 100644 services/following/create_test.go create mode 100644 services/following/delete.go create mode 100644 services/following/delete_test.go create mode 100644 services/following/fixtures/user.json create mode 100644 services/following/invalidate.go create mode 100644 services/following/invalidate_test.go create mode 100644 services/following/requests/accept.go create mode 100644 services/following/requests/accept_test.go create mode 100644 services/following/requests/cancel.go create mode 100644 services/following/requests/cancel_test.go create mode 100644 services/following/requests/fixtures/empty create mode 100644 services/following/requests/fixtures/list.json create mode 100644 services/following/requests/fixtures/user.json create mode 100644 services/following/requests/list.go create mode 100644 services/following/requests/list_test.go create mode 100644 services/following/requests/reject.go create mode 100644 services/following/requests/reject_test.go create mode 100644 services/following/requests/service.go create mode 100644 services/following/service.go diff --git a/README.md b/README.md index 8bd76b9..b9423d3 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Check the `docs` directory for more information. | :x: | [charts](https://misskey.io/api-doc#tag/charts) | [#7](https://github.com/yitsushi/go-misskey/issues/7) || | :white_check_mark: | [clips](https://misskey.io/api-doc#tag/clips) | [#8](https://github.com/yitsushi/go-misskey/issues/8) || | :white_check_mark: | [drive](https://misskey.io/api-doc#tag/drive) | [#9](https://github.com/yitsushi/go-misskey/issues/9) || -| :x: | [following](https://misskey.io/api-doc#tag/following) | [#10](https://github.com/yitsushi/go-misskey/issues/10) || +| :white_check_mark: | [following](https://misskey.io/api-doc#tag/following) | [#10](https://github.com/yitsushi/go-misskey/issues/10) || | :x: | [games](https://misskey.io/api-doc#tag/games) | [#11](https://github.com/yitsushi/go-misskey/issues/11) || | :white_check_mark: | [hashtags](https://misskey.io/api-doc#tag/hashtags) | [#12](https://github.com/yitsushi/go-misskey/issues/12) || | :x: | [messaging](https://misskey.io/api-doc#tag/messaging) | [#13](https://github.com/yitsushi/go-misskey/issues/13) || diff --git a/services.go b/services.go index 0c04424..925bd65 100644 --- a/services.go +++ b/services.go @@ -7,6 +7,7 @@ import ( "github.com/yitsushi/go-misskey/services/clips" "github.com/yitsushi/go-misskey/services/drive" "github.com/yitsushi/go-misskey/services/federation" + "github.com/yitsushi/go-misskey/services/following" "github.com/yitsushi/go-misskey/services/hashtags" "github.com/yitsushi/go-misskey/services/meta" "github.com/yitsushi/go-misskey/services/notes" @@ -72,3 +73,8 @@ func (c *Client) Promo() *promo.Service { func (c *Client) Admin() *admin.Service { return admin.NewService(c.requestHandler) } + +// Following contains all endpoints under /following. +func (c *Client) Following() *following.Service { + return following.NewService(c.requestHandler) +} diff --git a/services/following/create.go b/services/following/create.go new file mode 100644 index 0000000..b11c8cb --- /dev/null +++ b/services/following/create.go @@ -0,0 +1,38 @@ +package following + +import ( + "github.com/yitsushi/go-misskey/core" + "github.com/yitsushi/go-misskey/models" +) + +// CreateRequest is the request structure to create a following. +type CreateRequest struct { + UserID string `json:"userId"` +} + +// Validate request. +func (r CreateRequest) Validate() error { + if r.UserID == "" { + return core.RequestValidationError{ + Request: r, + Message: core.UndefinedRequiredField, + Field: "UserID", + } + } + + return nil +} + +// Create following endpoint. +func (s *Service) Create(userID string) (models.User, error) { + var response models.User + + request := &CreateRequest{UserID: userID} + + err := s.Call( + &core.JSONRequest{Request: request, Path: "/following/create"}, + &response, + ) + + return response, err +} diff --git a/services/following/create_test.go b/services/following/create_test.go new file mode 100644 index 0000000..bd48465 --- /dev/null +++ b/services/following/create_test.go @@ -0,0 +1,56 @@ +package following_test + +import ( + "log" + "net/http" + "os" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/yitsushi/go-misskey" + "github.com/yitsushi/go-misskey/core" + "github.com/yitsushi/go-misskey/services/following" + "github.com/yitsushi/go-misskey/test" +) + +func TestService_Create(t *testing.T) { + client := test.MakeMockClient(test.SimpleMockOptions{ + Endpoint: "/api/following/create", + RequestData: &following.CreateRequest{}, + ResponseFile: "user.json", + StatusCode: http.StatusOK, + }) + + user, err := client.Following().Create("88v9vu5nbu") + if !assert.NoError(t, err) { + return + } + + assert.Equal(t, "88v9vu5nbu", user.ID) +} + +func TestCreateRequest_Validate(t *testing.T) { + test.ValidateRequests( + t, + []core.BaseRequest{ + following.CreateRequest{}, + following.CreateRequest{UserID: ""}, + }, + []core.BaseRequest{ + following.CreateRequest{UserID: "88v9vu5nbu"}, + }, + ) +} + +func ExampleService_Create() { + client := misskey.NewClient("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN")) + + user, err := client.Following().Create("88v9vu5nbu") + if err != nil { + log.Printf("[Following/Create] %s", err) + + return + } + + log.Printf("[Following/Create] %s", user.Username) +} diff --git a/services/following/delete.go b/services/following/delete.go new file mode 100644 index 0000000..0b1c166 --- /dev/null +++ b/services/following/delete.go @@ -0,0 +1,38 @@ +package following + +import ( + "github.com/yitsushi/go-misskey/core" + "github.com/yitsushi/go-misskey/models" +) + +// DeleteRequest is the request structure to delete a following. +type DeleteRequest struct { + UserID string `json:"userId"` +} + +// Validate request. +func (r DeleteRequest) Validate() error { + if r.UserID == "" { + return core.RequestValidationError{ + Request: r, + Message: core.UndefinedRequiredField, + Field: "UserID", + } + } + + return nil +} + +// Delete following endpoint. +func (s *Service) Delete(userID string) (models.User, error) { + var response models.User + + request := &DeleteRequest{UserID: userID} + + err := s.Call( + &core.JSONRequest{Request: request, Path: "/following/delete"}, + &response, + ) + + return response, err +} diff --git a/services/following/delete_test.go b/services/following/delete_test.go new file mode 100644 index 0000000..e149b45 --- /dev/null +++ b/services/following/delete_test.go @@ -0,0 +1,56 @@ +package following_test + +import ( + "log" + "net/http" + "os" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/yitsushi/go-misskey" + "github.com/yitsushi/go-misskey/core" + "github.com/yitsushi/go-misskey/services/following" + "github.com/yitsushi/go-misskey/test" +) + +func TestService_Delete(t *testing.T) { + client := test.MakeMockClient(test.SimpleMockOptions{ + Endpoint: "/api/following/delete", + RequestData: &following.DeleteRequest{}, + ResponseFile: "user.json", + StatusCode: http.StatusOK, + }) + + user, err := client.Following().Delete("88v9vu5nbu") + if !assert.NoError(t, err) { + return + } + + assert.Equal(t, "88v9vu5nbu", user.ID) +} + +func TestDeleteRequest_Validate(t *testing.T) { + test.ValidateRequests( + t, + []core.BaseRequest{ + following.DeleteRequest{}, + following.DeleteRequest{UserID: ""}, + }, + []core.BaseRequest{ + following.DeleteRequest{UserID: "88v9vu5nbu"}, + }, + ) +} + +func ExampleService_Delete() { + client := misskey.NewClient("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN")) + + user, err := client.Following().Delete("88v9vu5nbu") + if err != nil { + log.Printf("[Following/Delete] %s", err) + + return + } + + log.Printf("[Following/Delete] %s", user.Username) +} diff --git a/services/following/fixtures/user.json b/services/following/fixtures/user.json new file mode 100644 index 0000000..905496f --- /dev/null +++ b/services/following/fixtures/user.json @@ -0,0 +1,12 @@ +{ + "id": "88v9vu5nbu", + "name": null, + "username": "kiki_test", + "host": null, + "avatarUrl": "https://slippy.xyz/identicon/88v9vu5nbu", + "avatarBlurhash": null, + "avatarColor": null, + "isBot": true, + "emojis": [], + "onlineStatus": "unknown" +} diff --git a/services/following/invalidate.go b/services/following/invalidate.go new file mode 100644 index 0000000..57a3848 --- /dev/null +++ b/services/following/invalidate.go @@ -0,0 +1,38 @@ +package following + +import ( + "github.com/yitsushi/go-misskey/core" + "github.com/yitsushi/go-misskey/models" +) + +// InvalidateRequest is the request structure to invalidate a following. +type InvalidateRequest struct { + UserID string `json:"userId"` +} + +// Validate request. +func (r InvalidateRequest) Validate() error { + if r.UserID == "" { + return core.RequestValidationError{ + Request: r, + Message: core.UndefinedRequiredField, + Field: "UserID", + } + } + + return nil +} + +// Invalidate following endpoint. +func (s *Service) Invalidate(userID string) (models.User, error) { + var response models.User + + request := &InvalidateRequest{UserID: userID} + + err := s.Call( + &core.JSONRequest{Request: request, Path: "/following/invalidate"}, + &response, + ) + + return response, err +} diff --git a/services/following/invalidate_test.go b/services/following/invalidate_test.go new file mode 100644 index 0000000..bfc1c97 --- /dev/null +++ b/services/following/invalidate_test.go @@ -0,0 +1,56 @@ +package following_test + +import ( + "log" + "net/http" + "os" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/yitsushi/go-misskey" + "github.com/yitsushi/go-misskey/core" + "github.com/yitsushi/go-misskey/services/following" + "github.com/yitsushi/go-misskey/test" +) + +func TestService_Invalidate(t *testing.T) { + client := test.MakeMockClient(test.SimpleMockOptions{ + Endpoint: "/api/following/invalidate", + RequestData: &following.InvalidateRequest{}, + ResponseFile: "user.json", + StatusCode: http.StatusOK, + }) + + user, err := client.Following().Invalidate("88v9vu5nbu") + if !assert.NoError(t, err) { + return + } + + assert.Equal(t, "88v9vu5nbu", user.ID) +} + +func TestInvalidateRequest_Validate(t *testing.T) { + test.ValidateRequests( + t, + []core.BaseRequest{ + following.InvalidateRequest{}, + following.InvalidateRequest{UserID: ""}, + }, + []core.BaseRequest{ + following.InvalidateRequest{UserID: "88v9vu5nbu"}, + }, + ) +} + +func ExampleService_Invalidate() { + client := misskey.NewClient("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN")) + + user, err := client.Following().Invalidate("88v9vu5nbu") + if err != nil { + log.Printf("[Following/Invalidate] %s", err) + + return + } + + log.Printf("[Following/Invalidate] %s", user.Username) +} diff --git a/services/following/requests/accept.go b/services/following/requests/accept.go new file mode 100644 index 0000000..e09e478 --- /dev/null +++ b/services/following/requests/accept.go @@ -0,0 +1,35 @@ +package requests + +import ( + "github.com/yitsushi/go-misskey/core" +) + +// AcceptRequest is the request structure to accept a following request. +type AcceptRequest struct { + UserID string `json:"userId"` +} + +// Validate request. +func (r AcceptRequest) Validate() error { + if r.UserID == "" { + return core.RequestValidationError{ + Request: r, + Message: core.UndefinedRequiredField, + Field: "UserID", + } + } + + return nil +} + +// Accept following endpoint. +func (s *Service) Accept(userID string) error { + request := &AcceptRequest{UserID: userID} + + err := s.Call( + &core.JSONRequest{Request: request, Path: "/following/requests/accept"}, + &core.EmptyResponse{}, + ) + + return err +} diff --git a/services/following/requests/accept_test.go b/services/following/requests/accept_test.go new file mode 100644 index 0000000..432fb45 --- /dev/null +++ b/services/following/requests/accept_test.go @@ -0,0 +1,54 @@ +package requests_test + +import ( + "log" + "net/http" + "os" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/yitsushi/go-misskey" + "github.com/yitsushi/go-misskey/core" + "github.com/yitsushi/go-misskey/services/following/requests" + "github.com/yitsushi/go-misskey/test" +) + +func TestService_Accept(t *testing.T) { + client := test.MakeMockClient(test.SimpleMockOptions{ + Endpoint: "/api/following/requests/accept", + RequestData: &requests.AcceptRequest{}, + ResponseFile: "empty", + StatusCode: http.StatusNoContent, + }) + + err := client.Following().Requests().Accept("88v9vu5nbu") + if !assert.NoError(t, err) { + return + } +} + +func TestAcceptRequest_Validate(t *testing.T) { + test.ValidateRequests( + t, + []core.BaseRequest{ + requests.AcceptRequest{}, + requests.AcceptRequest{UserID: ""}, + }, + []core.BaseRequest{ + requests.AcceptRequest{UserID: "88v9vu5nbu"}, + }, + ) +} + +func ExampleService_Accept() { + client := misskey.NewClient("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN")) + + err := client.Following().Requests().Accept("88v9vu5nbu") + if err != nil { + log.Printf("[Following/Requests/Accept] %s", err) + + return + } + + log.Println("[Following/Requests/Accept] Accepted") +} diff --git a/services/following/requests/cancel.go b/services/following/requests/cancel.go new file mode 100644 index 0000000..5d1693d --- /dev/null +++ b/services/following/requests/cancel.go @@ -0,0 +1,38 @@ +package requests + +import ( + "github.com/yitsushi/go-misskey/core" + "github.com/yitsushi/go-misskey/models" +) + +// CancelRequest is the request structure to cancel a following request. +type CancelRequest struct { + UserID string `json:"userId"` +} + +// Validate request. +func (r CancelRequest) Validate() error { + if r.UserID == "" { + return core.RequestValidationError{ + Request: r, + Message: core.UndefinedRequiredField, + Field: "UserID", + } + } + + return nil +} + +// Cancel following endpoint. +func (s *Service) Cancel(userID string) (models.User, error) { + var response models.User + + request := &CancelRequest{UserID: userID} + + err := s.Call( + &core.JSONRequest{Request: request, Path: "/following/requests/cancel"}, + &response, + ) + + return response, err +} diff --git a/services/following/requests/cancel_test.go b/services/following/requests/cancel_test.go new file mode 100644 index 0000000..c11fe49 --- /dev/null +++ b/services/following/requests/cancel_test.go @@ -0,0 +1,56 @@ +package requests_test + +import ( + "log" + "net/http" + "os" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/yitsushi/go-misskey" + "github.com/yitsushi/go-misskey/core" + "github.com/yitsushi/go-misskey/services/following/requests" + "github.com/yitsushi/go-misskey/test" +) + +func TestService_Cancel(t *testing.T) { + client := test.MakeMockClient(test.SimpleMockOptions{ + Endpoint: "/api/following/requests/cancel", + RequestData: &requests.CancelRequest{}, + ResponseFile: "user.json", + StatusCode: http.StatusOK, + }) + + user, err := client.Following().Requests().Cancel("88v9vu5nbu") + if !assert.NoError(t, err) { + return + } + + assert.Equal(t, "88v9vu5nbu", user.ID) +} + +func TestCancelRequest_Validate(t *testing.T) { + test.ValidateRequests( + t, + []core.BaseRequest{ + requests.CancelRequest{}, + requests.CancelRequest{UserID: ""}, + }, + []core.BaseRequest{ + requests.CancelRequest{UserID: "88v9vu5nbu"}, + }, + ) +} + +func ExampleService_Cancel() { + client := misskey.NewClient("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN")) + + user, err := client.Following().Requests().Cancel("88v9vu5nbu") + if err != nil { + log.Printf("[Following/Requests/Cancel] %s", err) + + return + } + + log.Printf("[Following/Requests/Cancel] Canceled: %s", user.ID) +} diff --git a/services/following/requests/fixtures/empty b/services/following/requests/fixtures/empty new file mode 100644 index 0000000..e69de29 diff --git a/services/following/requests/fixtures/list.json b/services/following/requests/fixtures/list.json new file mode 100644 index 0000000..9c4257f --- /dev/null +++ b/services/following/requests/fixtures/list.json @@ -0,0 +1,43 @@ +[ + { + "followee": { + "avatarBlurhash": null, + "avatarColor": null, + "avatarUrl": "https://slippy.xyz/identicon/88v9vu5nbu", + "emojis": [], + "host": null, + "id": "88v9vu5nbu", + "isBot": true, + "name": null, + "onlineStatus": "unknown", + "username": "kiki_test" + }, + "follower": { + "avatarBlurhash": null, + "avatarColor": null, + "avatarUrl": "https://slippy.xyz/files/thumbnail-26260544-87af-4d04-b284-f15eb05157a3", + "emojis": [ + { + "name": "ffxivmsq_comp", + "url": "https://slippy.xyz/files/fe13318a-43c8-482f-bdd5-a9cefc8518bb" + }, + { + "name": "heart_trans", + "url": "https://slippy.xyz/files/ee8e7d54-1121-46ad-83c3-b6cbeff6b52b" + }, + { + "name": "heart_bi", + "url": "https://slippy.xyz/files/aefe2f46-6003-46de-a0a5-83c4e0029e51" + } + ], + "host": null, + "id": "83sv4lyx22", + "isAdmin": true, + "isModerator": true, + "name": ":ffxivmsq_comp: Efertone 🏳️‍⚧️", + "onlineStatus": "online", + "username": "efertone" + }, + "id": "8y1u07q7yt" + } +] diff --git a/services/following/requests/fixtures/user.json b/services/following/requests/fixtures/user.json new file mode 100644 index 0000000..905496f --- /dev/null +++ b/services/following/requests/fixtures/user.json @@ -0,0 +1,12 @@ +{ + "id": "88v9vu5nbu", + "name": null, + "username": "kiki_test", + "host": null, + "avatarUrl": "https://slippy.xyz/identicon/88v9vu5nbu", + "avatarBlurhash": null, + "avatarColor": null, + "isBot": true, + "emojis": [], + "onlineStatus": "unknown" +} diff --git a/services/following/requests/list.go b/services/following/requests/list.go new file mode 100644 index 0000000..55c7c4f --- /dev/null +++ b/services/following/requests/list.go @@ -0,0 +1,33 @@ +package requests + +import ( + "github.com/yitsushi/go-misskey/core" + "github.com/yitsushi/go-misskey/models" +) + +// ListRequest is the request structure to list following requests. +type ListRequest struct{} + +// Validate request. +func (r ListRequest) Validate() error { + return nil +} + +// ListResponse is the response from the list following requests endpoint. +type ListResponse struct { + ID string `json:"id"` + Follower models.User `json:"follower"` + Followee models.User `json:"followee"` +} + +// List following requests endpoint. +func (s *Service) List() ([]ListResponse, error) { + response := []ListResponse{} + + err := s.Call( + &core.JSONRequest{Request: &ListRequest{}, Path: "/following/requests/list"}, + &response, + ) + + return response, err +} diff --git a/services/following/requests/list_test.go b/services/following/requests/list_test.go new file mode 100644 index 0000000..4c803af --- /dev/null +++ b/services/following/requests/list_test.go @@ -0,0 +1,61 @@ +package requests_test + +import ( + "log" + "net/http" + "os" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/yitsushi/go-misskey" + "github.com/yitsushi/go-misskey/core" + "github.com/yitsushi/go-misskey/services/following/requests" + "github.com/yitsushi/go-misskey/test" +) + +func TestService_List(t *testing.T) { + client := test.MakeMockClient(test.SimpleMockOptions{ + Endpoint: "/api/following/requests/list", + RequestData: &requests.ListRequest{}, + ResponseFile: "list.json", + StatusCode: http.StatusOK, + }) + + list, err := client.Following().Requests().List() + if !assert.NoError(t, err) { + return + } + + assert.Len(t, list, 1) + assert.Equal(t, "efertone", list[0].Follower.Username) + assert.Equal(t, "kiki_test", list[0].Followee.Username) +} + +func TestListRequest_Validate(t *testing.T) { + test.ValidateRequests( + t, + []core.BaseRequest{}, + []core.BaseRequest{ + requests.ListRequest{}, + }, + ) +} + +func ExampleService_List() { + client := misskey.NewClient("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN")) + + list, err := client.Following().Requests().List() + if err != nil { + log.Printf("[Following/Requests/List] %s", err) + + return + } + + for _, item := range list { + log.Printf( + "[Following/Requests/List] %s -> %s", + item.Follower.Username, + item.Followee.Username, + ) + } +} diff --git a/services/following/requests/reject.go b/services/following/requests/reject.go new file mode 100644 index 0000000..153cc78 --- /dev/null +++ b/services/following/requests/reject.go @@ -0,0 +1,35 @@ +package requests + +import ( + "github.com/yitsushi/go-misskey/core" +) + +// RejectRequest is the request structure to reject a following request. +type RejectRequest struct { + UserID string `json:"userId"` +} + +// Validate request. +func (r RejectRequest) Validate() error { + if r.UserID == "" { + return core.RequestValidationError{ + Request: r, + Message: core.UndefinedRequiredField, + Field: "UserID", + } + } + + return nil +} + +// Reject following request endpoint. +func (s *Service) Reject(userID string) error { + request := &RejectRequest{UserID: userID} + + err := s.Call( + &core.JSONRequest{Request: request, Path: "/following/requests/reject"}, + &core.EmptyResponse{}, + ) + + return err +} diff --git a/services/following/requests/reject_test.go b/services/following/requests/reject_test.go new file mode 100644 index 0000000..604ef14 --- /dev/null +++ b/services/following/requests/reject_test.go @@ -0,0 +1,54 @@ +package requests_test + +import ( + "log" + "net/http" + "os" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/yitsushi/go-misskey" + "github.com/yitsushi/go-misskey/core" + "github.com/yitsushi/go-misskey/services/following/requests" + "github.com/yitsushi/go-misskey/test" +) + +func TestService_Reject(t *testing.T) { + client := test.MakeMockClient(test.SimpleMockOptions{ + Endpoint: "/api/following/requests/reject", + RequestData: &requests.RejectRequest{}, + ResponseFile: "empty", + StatusCode: http.StatusNoContent, + }) + + err := client.Following().Requests().Reject("88v9vu5nbu") + if !assert.NoError(t, err) { + return + } +} + +func TestRejectRequest_Validate(t *testing.T) { + test.ValidateRequests( + t, + []core.BaseRequest{ + requests.RejectRequest{}, + requests.RejectRequest{UserID: ""}, + }, + []core.BaseRequest{ + requests.RejectRequest{UserID: "88v9vu5nbu"}, + }, + ) +} + +func ExampleService_Reject() { + client := misskey.NewClient("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN")) + + err := client.Following().Requests().Reject("88v9vu5nbu") + if err != nil { + log.Printf("[Following/Requests/Reject] %s", err) + + return + } + + log.Println("[Following/Requests/Reject] Rejected") +} diff --git a/services/following/requests/service.go b/services/following/requests/service.go new file mode 100644 index 0000000..67277a7 --- /dev/null +++ b/services/following/requests/service.go @@ -0,0 +1,13 @@ +package requests + +import "github.com/yitsushi/go-misskey/core" + +// Service is the base for all the endpoints on this service. +type Service struct { + Call core.RequestHandlerFunc +} + +// NewService creates a new Service instance. +func NewService(requestHandler core.RequestHandlerFunc) *Service { + return &Service{Call: requestHandler} +} diff --git a/services/following/service.go b/services/following/service.go new file mode 100644 index 0000000..5ab8077 --- /dev/null +++ b/services/following/service.go @@ -0,0 +1,21 @@ +package following + +import ( + "github.com/yitsushi/go-misskey/core" + "github.com/yitsushi/go-misskey/services/following/requests" +) + +// Service is the base for all the endpoints on this service. +type Service struct { + Call core.RequestHandlerFunc +} + +// NewService creates a new Service instance. +func NewService(requestHandler core.RequestHandlerFunc) *Service { + return &Service{Call: requestHandler} +} + +// Requests endpoint on followings. +func (s *Service) Requests() *requests.Service { + return requests.NewService(s.Call) +}