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
11 changes: 11 additions & 0 deletions models/follow.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package models

// FollowStatus defines the status of followers and followees.
type FollowStatus 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)
}
204 changes: 204 additions & 0 deletions services/federation/fixtures/followers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
[
{
"id": "84l9u36eoa",
"createdAt": "2020-03-07T14:32:32.150Z",
"followeeId": "84l9tncinl",
"followerId": "83sv4lyx22",
"followee": {
"id": "84l9tncinl",
"name": "Repo",
"username": "repo",
"host": "misskey.io",
"avatarUrl": "https://slippy.xyz/files/thumbnail-7f0f2d00-dbc2-41ee-a44b-bc8d241e2074",
"avatarBlurhash": null,
"avatarColor": null,
"isAdmin": false,
"isModerator": false,
"isBot": true,
"isCat": false,
"emojis": [],
"url": "https://misskey.io/@repo",
"createdAt": "2020-03-07T14:32:11.634Z",
"updatedAt": "2020-03-28T02:45:53.959Z",
"bannerUrl": null,
"bannerBlurhash": null,
"bannerColor": null,
"isLocked": false,
"isSilenced": false,
"isSuspended": false,
"description": "MisskeyのGitHubリポジトリのイベントを投稿します",
"location": null,
"birthday": null,
"fields": [],
"followersCount": 1,
"followingCount": 0,
"notesCount": 382,
"pinnedNoteIds": [],
"pinnedNotes": [],
"pinnedPageId": null,
"pinnedPage": null,
"twoFactorEnabled": false,
"usePasswordLessLogin": false,
"securityKeys": false
}
},
{
"id": "83yz9lemdx",
"createdAt": "2020-02-21T00:05:43.966Z",
"followeeId": "83yz8h0uad",
"followerId": "83sv4lyx22",
"followee": {
"id": "83yz8h0uad",
"name": "しゅいろ",
"username": "syuilo",
"host": "misskey.io",
"avatarUrl": "https://slippy.xyz/files/thumbnail-c782f620-3343-4b53-8597-8f3be68b5baf",
"avatarBlurhash": "yCGI1PWB00xtE0jZ8{00a{yERkx^WB^+?wof={of00kB%MD%WBRkV[?HkCIp%Lt7E1ofxvRQ%2o~RjniRkoc%2IV0Kof-;t7oLIokV",
"avatarColor": null,
"isAdmin": false,
"isModerator": false,
"isBot": false,
"isCat": false,
"emojis": [],
"url": "https://misskey.io/@syuilo",
"createdAt": "2020-02-21T00:04:51.630Z",
"updatedAt": "2020-10-25T14:36:32.624Z",
"bannerUrl": "https://s3.arkjp.net/misskey/pdg1/15b4c833-7955-4673-8e2d-75f11e2b1b1f.jpg",
"bannerBlurhash": null,
"bannerColor": null,
"isLocked": false,
"isSilenced": false,
"isSuspended": false,
"description": "Project lead of Misskey.\n\nMisskeyの作者/開発者です。\n\nhttps://github.com/syuilo/misskey\n\n#misskey #藍ちゃファンクラブ #わーーーーーーーーーーーーーーー 旦那→@AureoleArk@misskey.io 推し→@ai@misskey.io",
"location": "Japan",
"birthday": "1997-12-06",
"fields": [
{
"name": "欲しいものリスト",
"value": "https://www.amazon.jp/hz/wishlist/ls/4JG4P6XKX9KD?ref_=wl_share"
}
],
"followersCount": 1,
"followingCount": 0,
"notesCount": 11371,
"pinnedNoteIds": [
"8cy8yw6g3f",
"7wivpdbsc5",
"7wehobubbx"
],
"pinnedNotes": [
{
"id": "8cy8yw6g3f",
"createdAt": "2020-10-04T05:46:55.720Z",
"userId": "83yz8h0uad",
"user": {
"id": "83yz8h0uad",
"name": "しゅいろ",
"username": "syuilo",
"host": "misskey.io",
"avatarUrl": "https://slippy.xyz/files/thumbnail-c782f620-3343-4b53-8597-8f3be68b5baf",
"avatarBlurhash": "yCGI1PWB00xtE0jZ8{00a{yERkx^WB^+?wof={of00kB%MD%WBRkV[?HkCIp%Lt7E1ofxvRQ%2o~RjniRkoc%2IV0Kof-;t7oLIokV",
"avatarColor": null,
"emojis": []
},
"text": "MisskeyはFDD(Feeling Driven Development、雰囲気駆動開発)を採用しており、どなたでも雰囲気で開発に参加することができます",
"cw": null,
"visibility": "public",
"renoteCount": 0,
"repliesCount": 0,
"reactions": {},
"emojis": [],
"fileIds": [],
"files": [],
"replyId": null,
"renoteId": null,
"uri": "https://misskey.io/notes/8cy8yw6guj"
},
{
"id": "7wivpdbsc5",
"createdAt": "2019-08-17T09:03:46.360Z",
"userId": "83yz8h0uad",
"user": {
"id": "83yz8h0uad",
"name": "しゅいろ",
"username": "syuilo",
"host": "misskey.io",
"avatarUrl": "https://slippy.xyz/files/thumbnail-c782f620-3343-4b53-8597-8f3be68b5baf",
"avatarBlurhash": "yCGI1PWB00xtE0jZ8{00a{yERkx^WB^+?wof={of00kB%MD%WBRkV[?HkCIp%Lt7E1ofxvRQ%2o~RjniRkoc%2IV0Kof-;t7oLIokV",
"avatarColor": null,
"emojis": []
},
"text": "分散型マイクロブログサービス、Misskeyを開発しています。\nよろしければ支援お願いします🙏\nhttp://patreon.com/syuilo/",
"cw": null,
"visibility": "public",
"renoteCount": 11,
"repliesCount": 0,
"reactions": {},
"emojis": [],
"fileIds": [],
"files": [],
"replyId": null,
"renoteId": null,
"uri": "https://misskey.io/notes/7wivpdbsot"
},
{
"id": "7wehobubbx",
"createdAt": "2019-08-14T07:19:58.451Z",
"userId": "83yz8h0uad",
"user": {
"id": "83yz8h0uad",
"name": "しゅいろ",
"username": "syuilo",
"host": "misskey.io",
"avatarUrl": "https://slippy.xyz/files/thumbnail-c782f620-3343-4b53-8597-8f3be68b5baf",
"avatarBlurhash": "yCGI1PWB00xtE0jZ8{00a{yERkx^WB^+?wof={of00kB%MD%WBRkV[?HkCIp%Lt7E1ofxvRQ%2o~RjniRkoc%2IV0Kof-;t7oLIokV",
"avatarColor": null,
"emojis": []
},
"text": ".",
"cw": null,
"visibility": "public",
"renoteCount": 8,
"repliesCount": 0,
"reactions": {},
"emojis": [],
"fileIds": [
"83yz8io6bs"
],
"files": [
{
"id": "83yz8io6bs",
"createdAt": "2020-02-21T00:04:53.766Z",
"name": "webpublic-cdfc5f93-42a2-40b7-932f-1e567a601725.png",
"type": "image/png",
"md5": "5fb275f731d76db68284a575410efc53",
"size": 0,
"isSensitive": false,
"blurhash": null,
"properties": {
"width": 890,
"height": 796,
"avgColor": "rgb(121,120,119)"
},
"url": "https://s3.arkjp.net/misskey/webpublic-cdfc5f93-42a2-40b7-932f-1e567a601725.png",
"thumbnailUrl": "https://s3.arkjp.net/misskey/webpublic-cdfc5f93-42a2-40b7-932f-1e567a601725.png",
"comment": null,
"folderId": null,
"folder": null,
"userId": null,
"user": null
}
],
"replyId": null,
"renoteId": null,
"uri": "https://misskey.io/notes/7wehobub52"
}
],
"pinnedPageId": null,
"pinnedPage": null,
"twoFactorEnabled": false,
"usePasswordLessLogin": false,
"securityKeys": false
}
}
]
83 changes: 83 additions & 0 deletions services/federation/fixtures/following.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
[
{
"id": "864ws9xsoz",
"createdAt": "2020-04-15T13:02:18.448Z",
"followeeId": "83sv4lyx22",
"followerId": "84wi1id9ev",
"followee": {
"id": "83sv4lyx22",
"name": ":ffxivmsq_comp: Efertone",
"username": "efertone",
"host": null,
"avatarUrl": "https://slippy.xyz/files/thumbnail-26260544-87af-4d04-b284-f15eb05157a3",
"avatarBlurhash": null,
"avatarColor": null,
"isAdmin": true,
"isModerator": true,
"isBot": false,
"isCat": false,
"emojis": [
{
"name": "ffxivmsq_comp",
"host": null,
"url": "https://slippy.xyz/files/fe13318a-43c8-482f-bdd5-a9cefc8518bb",
"aliases": []
},
{
"name": "heart_bi",
"host": null,
"url": "https://slippy.xyz/files/aefe2f46-6003-46de-a0a5-83c4e0029e51",
"aliases": []
},
{
"name": "heart_trans",
"host": null,
"url": "https://slippy.xyz/files/ee8e7d54-1121-46ad-83c3-b6cbeff6b52b",
"aliases": [
""
]
}
],
"url": null,
"createdAt": "2020-02-16T17:23:15.897Z",
"updatedAt": "2020-10-25T10:54:57.967Z",
"bannerUrl": "https://slippy.xyz/files/webpublic-8e4dd9d5-81f3-4485-89c6-36348010c9a0",
"bannerBlurhash": null,
"bannerColor": null,
"isLocked": false,
"isSilenced": false,
"isSuspended": false,
"description": "I'm trans bi girl and usually I'm #engineering the #cloud. And #gaming (mostly #ffxiv) ;)\nBut really, mostly CloudEngineering, #Security Audit, #Automation, #python, #golang and in the last few weeks #haskell (it's fun). Don't judge me, but everything can be done in #vim quicker than any other ways.\n\n:heart_trans: :heart_bi:",
"location": "Hungary",
"birthday": null,
"fields": [
{
"name": "Name",
"value": "Efertone / Efer / Effy"
},
{
"name": "Blog",
"value": "https://efertone.me"
},
{
"name": "Pronouns",
"value": "She / Her"
},
{
"name": "FFXIV Server",
"value": "Lich"
}
],
"followersCount": 46,
"followingCount": 51,
"notesCount": 1137,
"pinnedNoteIds": [],
"pinnedNotes": [],
"pinnedPageId": null,
"pinnedPage": null,
"twoFactorEnabled": true,
"usePasswordLessLogin": true,
"securityKeys": true
}
}
]
47 changes: 47 additions & 0 deletions services/federation/followers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package federation

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

// FollowersRequest contains request information to obtain followers.
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 {
if r.Host == "" {
return core.RequestValidationError{
Request: r,
Message: core.UndefinedRequiredField,
Field: "Host",
}
}

if r.Limit < 1 || r.Limit > 100 {
return core.RequestValidationError{
Request: r,
Message: core.NewRangeError(1, 100),
Field: "Limit",
}
}

return nil
Skarlso marked this conversation as resolved.
Show resolved Hide resolved
}

// Followers lists all followers.
func (s *Service) Followers(request FollowersRequest) ([]models.FollowStatus, error) {
var response []models.FollowStatus

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

return response, err
}
Loading