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
6 changes: 6 additions & 0 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ type User struct {
AvatarBlurhash core.String `json:"avatarBlurhash"`
AvatarColor core.String `json:"avatarColor"`
Emojis []Emoji `json:"emojis"`
IsCat bool `json:"iscat"`
IsBot bool `json:"isbot"`
IsAdmin bool `json:"isadmin"`
IsModerator bool `json:"ismoderator"`
IsLocked bool `json:"islocked"`
Birthday string `json:"birthday"`
yitsushi marked this conversation as resolved.
Show resolved Hide resolved
}
6 changes: 6 additions & 0 deletions services.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package misskey
import (
"github.com/yitsushi/go-misskey/core"
"github.com/yitsushi/go-misskey/services/antennas"
"github.com/yitsushi/go-misskey/services/federation"
"github.com/yitsushi/go-misskey/services/meta"
)

Expand All @@ -25,3 +26,8 @@ func (c *Client) Meta() *meta.Service {
func (c *Client) Antennas() *antennas.Service {
return antennas.NewService(c.requestHandler)
}

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

import "github.com/yitsushi/go-misskey/core"

// ShowRequest is the request used by the show command.
// Contains a single URI.
type ShowRequest struct {
URI string `json:"uri"`
}

// ShowResponse is an empty response for the Show command.
Skarlso marked this conversation as resolved.
Show resolved Hide resolved
type ShowResponse struct {
}

// Show shows the ActivityPub object specified by the URI.
func (s *Service) Show(request ShowRequest) error {
Skarlso marked this conversation as resolved.
Show resolved Hide resolved
var response ShowResponse
err := s.Call(
&core.BaseRequest{Request: request, Path: "/ap/show"},
&response,
)

return err
}
51 changes: 51 additions & 0 deletions services/federation/follow_calls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package federation

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

// FollowRequest is the request used by the followers and following commands.
type FollowRequest struct {
Skarlso marked this conversation as resolved.
Show resolved Hide resolved
Host string `json:"host"`
SinceID string `json:"sinceId"`
UntilID string `json:"untilId"`
Limit int `json:"limit"`
}

// Follow is a single follower or following record.
yitsushi marked this conversation as resolved.
Show resolved Hide resolved
type Follow struct {
ID string `json:"id"`
CreatedAt string `json:"createdAt"`
FolloweeID string `json:"followeeId"`
Followee models.User `json:"followee"`
FollowerID string `json:"followerId"`
Follower models.User `json:"follower"`
Skarlso marked this conversation as resolved.
Show resolved Hide resolved
}

// FollowResponse contains a list of followers or followings.
type FollowResponse struct {
Follows []Follow
}
Skarlso marked this conversation as resolved.
Show resolved Hide resolved

// Followers lists all followers.
func (s *Service) Followers(request FollowRequest) (FollowResponse, error) {
var response FollowResponse
Skarlso marked this conversation as resolved.
Show resolved Hide resolved
err := s.Call(
&core.BaseRequest{Request: request, Path: "/federation/followers"},
&response,
)

return response, err
}

// Following lists all followings.
func (s *Service) Following(request FollowRequest) (FollowResponse, error) {
var response FollowResponse
Skarlso marked this conversation as resolved.
Show resolved Hide resolved
err := s.Call(
&core.BaseRequest{Request: request, Path: "/federation/following"},
&response,
)

return response, err
}
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}
}