Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Federation calls #30

Merged
merged 16 commits into from
Oct 25, 2020
18 changes: 18 additions & 0 deletions models/federation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package models
Skarlso marked this conversation as resolved.
Show resolved Hide resolved

// Following is a single following record.
// Technically it's the same as Followers but we keep it separate
Skarlso marked this conversation as resolved.
Show resolved Hide resolved
// for easy tracking.
type Following struct {
Followers
}

// Followers is a single follower record.
type Followers struct {
ID string `json:"id"`
CreatedAt string `json:"createdAt"`
FolloweeID string `json:"followeeId"`
Followee User `json:"followee"`
FollowerID string `json:"followerId"`
Follower User `json:"follower,omitempty"`
}
6 changes: 6 additions & 0 deletions services.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/yitsushi/go-misskey/services/antennas"
"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/hashtags"
"github.com/yitsushi/go-misskey/services/meta"
"github.com/yitsushi/go-misskey/services/notifications"
Expand Down Expand Up @@ -48,3 +49,8 @@ func (c *Client) Clips() *clips.Service {
func (c *Client) Drive() *drive.Service {
return drive.NewService(c.requestHandler)
}

// Federation contains all endpoints under /federation.
func (c *Client) Federation() *federation.Service {
return federation.NewService(c.requestHandler)
}
36 changes: 36 additions & 0 deletions services/federation/followers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package federation

import (
"github.com/yitsushi/go-misskey/core"
"github.com/yitsushi/go-misskey/models"
)

// followersResponse contains a list of followers.
type followersResponse struct {
Skarlso marked this conversation as resolved.
Show resolved Hide resolved
Followers []models.Followers
}

// FollowersRequest contains request information for the followers call.
type FollowersRequest struct {
Host string `json:"host"`
SinceID string `json:"sinceId"`
UntilID string `json:"untilId"`
Limit int `json:"limit"`
}

// Validate the request.
func (r *FollowersRequest) Validate() error {
return nil
Skarlso marked this conversation as resolved.
Show resolved Hide resolved
}

// Followers lists all followers.
func (s *Service) Followers(request *FollowersRequest) ([]models.Followers, error) {
Skarlso marked this conversation as resolved.
Show resolved Hide resolved
var response followersResponse

err := s.Call(
&core.JSONRequest{Request: request, Path: "/federation/followers"},
&response,
)

return response.Followers, err
}
24 changes: 24 additions & 0 deletions services/federation/followers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package federation_test

import (
"log"
"os"

"github.com/yitsushi/go-misskey"
"github.com/yitsushi/go-misskey/services/federation"
)

func ExampleService_Followers() {
client := misskey.NewClient("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN"))

resp, err := client.Federation().Followers(&federation.FollowersRequest{
Limit: 100,
})
if err != nil {
log.Printf("[Federation/Followers] %s", err)

return
}

log.Printf("[Federation/Followers] %v listed", resp)
}
36 changes: 36 additions & 0 deletions services/federation/following.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package federation

import (
"github.com/yitsushi/go-misskey/core"
"github.com/yitsushi/go-misskey/models"
)

// followingResponse contains a list of followings.
type followingResponse struct {
Skarlso marked this conversation as resolved.
Show resolved Hide resolved
Followings []models.Following
}

// FollowingRequest contains request information for the followings call.
type FollowingRequest struct {
Host string `json:"host"`
SinceID string `json:"sinceId"`
UntilID string `json:"untilId"`
Limit int `json:"limit"`
}

// Validate the request.
func (r *FollowingRequest) Validate() error {
return nil
Skarlso marked this conversation as resolved.
Show resolved Hide resolved
}

// Following lists all followings.
func (s *Service) Following(request *FollowingRequest) ([]models.Following, error) {
Skarlso marked this conversation as resolved.
Show resolved Hide resolved
var response followingResponse

err := s.Call(
&core.JSONRequest{Request: request, Path: "/federation/following"},
&response,
)

return response.Followings, err
}
24 changes: 24 additions & 0 deletions services/federation/following_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package federation_test

import (
"log"
"os"

"github.com/yitsushi/go-misskey"
"github.com/yitsushi/go-misskey/services/federation"
)

func ExampleService_Following() {
client := misskey.NewClient("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN"))

resp, err := client.Federation().Following(&federation.FollowingRequest{
Limit: 100,
})
if err != nil {
log.Printf("[Federation/Following] %s", err)

return
}

log.Printf("[Federation/Following] %v listed", resp)
}
13 changes: 13 additions & 0 deletions services/federation/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package federation

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