diff --git a/services/notes/children.go b/services/notes/children.go new file mode 100644 index 0000000..6f298a7 --- /dev/null +++ b/services/notes/children.go @@ -0,0 +1,47 @@ +package notes + +import ( + "github.com/yitsushi/go-misskey/core" + "github.com/yitsushi/go-misskey/models" +) + +// ChildrenRequest represents an Children request. +type ChildrenRequest struct { + NoteID string `json:"noteId"` + Limit uint `json:"limit"` + SinceID string `json:"sinceId,omitempty"` + UntilID string `json:"untilId,omitempty"` +} + +// Validate the request. +func (r ChildrenRequest) Validate() error { + if r.NoteID == "" { + return core.RequestValidationError{ + Request: r, + Message: core.UndefinedRequiredField, + Field: "NoteID", + } + } + + if r.Limit < 1 || r.Limit > 100 { + return core.RequestValidationError{ + Request: r, + Message: core.NewRangeError(1, 100), + Field: "Limit", + } + } + + return nil +} + +// Children endpoint. +func (s *Service) Children(request ChildrenRequest) ([]models.Note, error) { + var response []models.Note + + err := s.Call( + &core.JSONRequest{Request: &request, Path: "/notes/children"}, + &response, + ) + + return response, err +} diff --git a/services/notes/children_test.go b/services/notes/children_test.go new file mode 100644 index 0000000..cb18f52 --- /dev/null +++ b/services/notes/children_test.go @@ -0,0 +1,69 @@ +package notes_test + +import ( + "log" + "net/http" + "os" + "testing" + + "github.com/sirupsen/logrus" + "github.com/stretchr/testify/assert" + "github.com/yitsushi/go-misskey" + "github.com/yitsushi/go-misskey/core" + "github.com/yitsushi/go-misskey/services/notes" + "github.com/yitsushi/go-misskey/test" +) + +func TestService_Children(t *testing.T) { + client := test.MakeMockClient(test.SimpleMockOptions{ + Endpoint: "/api/notes/children", + RequestData: ¬es.ChildrenRequest{}, + ResponseFile: "children.json", + StatusCode: http.StatusOK, + }) + + noteList, err := client.Notes().Children(notes.ChildrenRequest{ + NoteID: "noteid", + Limit: 1, + }) + if !assert.NoError(t, err) { + return + } + + assert.Len(t, noteList, 1) +} + +func TestChildrenRequest_Validate(t *testing.T) { + test.ValidateRequests( + t, + []core.BaseRequest{ + notes.ChildrenRequest{}, + notes.ChildrenRequest{NoteID: ""}, + notes.ChildrenRequest{NoteID: "noteid"}, + notes.ChildrenRequest{Limit: 10}, + notes.ChildrenRequest{NoteID: "noteid", Limit: 200}, + }, + []core.BaseRequest{ + notes.ChildrenRequest{NoteID: "noteid", Limit: 10}, + }, + ) +} + +func ExampleService_Children() { + client := misskey.NewClient("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN")) + client.LogLevel(logrus.DebugLevel) + + noteList, err := client.Notes().Children(notes.ChildrenRequest{ + NoteID: "noteid", + Limit: 10, + }) + if err != nil { + log.Printf("[Notes] Error happened: %s", err) + + return + } + + for _, note := range noteList { + log.Printf(" - %s", note.Text) + } +} diff --git a/services/notes/fixtures/children.json b/services/notes/fixtures/children.json new file mode 100644 index 0000000..76ace81 --- /dev/null +++ b/services/notes/fixtures/children.json @@ -0,0 +1,74 @@ +[ + { + "id": "8e90eyjcy1", + "createdAt": "2020-11-05T23:12:39.000Z", + "userId": "846um7m67z", + "user": { + "id": "846um7m67z", + "name": "Demoonic Dork Succubus", + "username": "maxine", + "host": "social.mootech.eu", + "avatarUrl": "https://slippy.xyz/files/thumbnail-2b74eb20-7bf5-45c9-9a59-358efa0922d2", + "avatarBlurhash": "yBIEk8.GEHDI0405iyD$91Mm?W----Ir00$+07Ed?F?qx.$-tMM{~Ux@MhRR4roy=|M~?pw#wO04%J%vIVjd9aRU8}NL.0D,sCofRj", + "avatarColor": null, + "instance": { + "name": "Mootech", + "softwareName": "mastodon", + "softwareVersion": "3.2.1+mootech4", + "iconUrl": "https://social.mootech.eu/android-chrome-192x192.png", + "faviconUrl": "https://social.mootech.eu/favicon.ico", + "themeColor": "#282c37" + }, + "emojis": [] + }, + "text": "Seriously though. Fascists always use the same tactic and it works every time on privileged people.\n\nPresent a (supposedly) very dangerous enemy/situation, that most people ignore/can't see. Then pose those who belief you as smart, cunning, etc. for also believing that (made up) story.\n\nThrow in a few \"facts\" and bam, people follow.\n\nI fell for it myself, then starred listening to other marginalized folks and admit that I know shit.\n\nThat helped a ton", + "cw": "general pol, fascist tactics", + "visibility": "public", + "renoteCount": 1, + "repliesCount": 0, + "reactions": {}, + "emojis": [], + "fileIds": [], + "files": [], + "replyId": "8e907l3sy0", + "renoteId": null, + "uri": "https://social.mootech.eu/users/maxine/statuses/105160242556438262", + "url": "https://social.mootech.eu/@maxine/105160242556438262", + "reply": { + "id": "8e907l3sy0", + "createdAt": "2020-11-05T23:06:55.000Z", + "userId": "846um7m67z", + "user": { + "id": "846um7m67z", + "name": "Demoonic Dork Succubus", + "username": "maxine", + "host": "social.mootech.eu", + "avatarUrl": "https://slippy.xyz/files/thumbnail-2b74eb20-7bf5-45c9-9a59-358efa0922d2", + "avatarBlurhash": "yBIEk8.GEHDI0405iyD$91Mm?W----Ir00$+07Ed?F?qx.$-tMM{~Ux@MhRR4roy=|M~?pw#wO04%J%vIVjd9aRU8}NL.0D,sCofRj", + "avatarColor": null, + "instance": { + "name": "Mootech", + "softwareName": "mastodon", + "softwareVersion": "3.2.1+mootech4", + "iconUrl": "https://social.mootech.eu/android-chrome-192x192.png", + "faviconUrl": "https://social.mootech.eu/favicon.ico", + "themeColor": "#282c37" + }, + "emojis": [] + }, + "text": "fascists: The world is ending, because a super powerful enemy is there, but you can defeat it, you're the smart one. Join us. Listen only to us the troth tellers!\n\nCommunists: Now here's the deal. You listen to marginalized folks, really listen, and protect them. In return we let you play games with us and share cookies. Good? Good.", + "cw": "general pol", + "visibility": "public", + "renoteCount": 0, + "repliesCount": 1, + "reactions": {}, + "emojis": [], + "fileIds": [], + "files": [], + "replyId": null, + "renoteId": null, + "uri": "https://social.mootech.eu/users/maxine/statuses/105160220030964687", + "url": "https://social.mootech.eu/@maxine/105160220030964687" + } + } +] \ No newline at end of file diff --git a/services/notes/fixtures/search-by-tag.json b/services/notes/fixtures/search-by-tag.json new file mode 100644 index 0000000..09d03db --- /dev/null +++ b/services/notes/fixtures/search-by-tag.json @@ -0,0 +1,467 @@ +[ + { + "id": "8aohsdxyqa", + "createdAt": "2020-08-08T00:36:42.262Z", + "userId": "83yz8h0uad", + "user": { + "id": "83yz8h0uad", + "name": "しゅいろ:loading:", + "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, + "instance": { + "name": "Misskey", + "softwareName": "misskey", + "softwareVersion": "12.53.0", + "iconUrl": "https://misskey.io/assets/icons/192.png", + "faviconUrl": "https://misskey.io/favicon.ico", + "themeColor": "#86b300" + }, + "emojis": [ + { + "name": "loading", + "host": "misskey.io", + "url": "https://s3.arkjp.net/misskey/9a941052-364e-48b5-ab27-d44817cc8ca0.png", + "aliases": [] + } + ] + }, + "text": "#test 2", + "cw": null, + "visibility": "public", + "renoteCount": 0, + "repliesCount": 0, + "reactions": {}, + "tags": [ + "test" + ], + "emojis": [], + "fileIds": [], + "files": [], + "replyId": null, + "renoteId": null, + "uri": "https://misskey.io/notes/8aohsdxyh5" + }, + { + "id": "8aohqsvopz", + "createdAt": "2020-08-08T00:35:28.308Z", + "userId": "83yz8h0uad", + "user": { + "id": "83yz8h0uad", + "name": "しゅいろ:loading:", + "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, + "instance": { + "name": "Misskey", + "softwareName": "misskey", + "softwareVersion": "12.53.0", + "iconUrl": "https://misskey.io/assets/icons/192.png", + "faviconUrl": "https://misskey.io/favicon.ico", + "themeColor": "#86b300" + }, + "emojis": [ + { + "name": "loading", + "host": "misskey.io", + "url": "https://s3.arkjp.net/misskey/9a941052-364e-48b5-ab27-d44817cc8ca0.png", + "aliases": [] + } + ] + }, + "text": "#test", + "cw": null, + "visibility": "public", + "renoteCount": 0, + "repliesCount": 0, + "reactions": {}, + "tags": [ + "test" + ], + "emojis": [], + "fileIds": [], + "files": [], + "replyId": null, + "renoteId": null, + "uri": "https://misskey.io/notes/8aohqsvosd" + }, + { + "id": "89h0ufigfv", + "createdAt": "2020-07-08T14:28:18.568Z", + "userId": "88v9vu5nbu", + "user": { + "id": "88v9vu5nbu", + "name": null, + "username": "kiki_test", + "host": null, + "avatarUrl": "https://slippy.xyz/avatar/88v9vu5nbu", + "avatarBlurhash": null, + "avatarColor": null, + "isBot": true, + "emojis": [] + }, + "text": "**Test Title again**\n\nanother content\n\nhttps://efertone.me/\n\n#test", + "cw": null, + "visibility": "public", + "renoteCount": 0, + "repliesCount": 0, + "reactions": {}, + "tags": [ + "test" + ], + "emojis": [], + "fileIds": [ + "89h0g9o3da" + ], + "files": [ + { + "id": "89h0g9o3da", + "createdAt": "2020-07-08T14:17:17.811Z", + "name": "b7c305c5-a467-4af3-bb4c-024d7f7ae7ef", + "type": "image/png", + "md5": "649bd8d40f5ec6fd4d3b3a3c016d0db3", + "size": 202876, + "isSensitive": false, + "blurhash": null, + "properties": { + "width": 600, + "height": 600, + "avgColor": "rgb(173,149,169)" + }, + "url": "https://slippy.xyz/files/webpublic-dfbc27a0-9a26-48b9-a1d1-cdee46d84404", + "thumbnailUrl": "https://slippy.xyz/files/thumbnail-63604293-c866-47b0-921b-6c6168c9f614", + "comment": null, + "folderId": null, + "folder": null, + "userId": null, + "user": null + } + ], + "replyId": null, + "renoteId": null + }, + { + "id": "899zm73zcz", + "createdAt": "2020-07-03T16:19:31.583Z", + "userId": "88v9vu5nbu", + "user": { + "id": "88v9vu5nbu", + "name": null, + "username": "kiki_test", + "host": null, + "avatarUrl": "https://slippy.xyz/avatar/88v9vu5nbu", + "avatarBlurhash": null, + "avatarColor": null, + "isBot": true, + "emojis": [] + }, + "text": "**Test Title again**\n\nanother content\n\nhttps://efertone.me/\n\n#test", + "cw": null, + "visibility": "public", + "renoteCount": 0, + "repliesCount": 0, + "reactions": {}, + "tags": [ + "test" + ], + "emojis": [], + "fileIds": [], + "files": [], + "replyId": null, + "renoteId": null + }, + { + "id": "88jyo6xm9c", + "createdAt": "2020-06-15T11:11:04.474Z", + "userId": "84c9aor4hj", + "user": { + "id": "84c9aor4hj", + "name": "takimura@めいめい鯖​:@mei23:", + "username": "cv_k", + "host": "misskey.m544.net", + "avatarUrl": "https://misskey-drive.m544.net/files/a7fdfaea-3211-458d-ae34-9f886b84d28c/url-circle.png", + "avatarBlurhash": null, + "avatarColor": null, + "instance": { + "name": "めいすきー", + "softwareName": "misskey", + "softwareVersion": "10.102.344-m544", + "iconUrl": "https://misskey-drive2.m544.net/m544/owv7c0xeho8x0xq8kgnn2iie.png", + "faviconUrl": "https://misskey-drive2.m544.net/m544/owv7c0xeho8x0xq8kgnn2iie.png", + "themeColor": "#5A0608" + }, + "emojis": [] + }, + "text": "https://twitter.com/TwitterJP\nhttps://mobile.twitter.com/TwitterJP #test", + "cw": null, + "visibility": "public", + "renoteCount": 0, + "repliesCount": 0, + "reactions": {}, + "tags": [ + "test" + ], + "emojis": [], + "fileIds": [], + "files": [], + "replyId": null, + "renoteId": null, + "uri": "https://misskey.m544.net/notes/7172b7acf31aec43085bc682" + }, + { + "id": "883hf5u8si", + "createdAt": "2020-06-03T22:23:50.864Z", + "userId": "849cd0p02a", + "user": { + "id": "849cd0p02a", + "name": "takimura@​:misskey:​.io​:smiling_ai:​:aified:​", + "username": "cv_k", + "host": "misskey.io", + "avatarUrl": "https://s3.arkjp.net/misskey/webpublic-01301451-8e18-4bc1-96da-abedd36e3219.png", + "avatarBlurhash": null, + "avatarColor": null, + "isCat": true, + "instance": { + "name": "Misskey", + "softwareName": "misskey", + "softwareVersion": "12.53.0", + "iconUrl": "https://misskey.io/assets/icons/192.png", + "faviconUrl": "https://misskey.io/favicon.ico", + "themeColor": "#86b300" + }, + "emojis": [ + { + "name": "aified", + "host": "misskey.io", + "url": "https://emoji.arkjp.net/misskey/aified.svg", + "aliases": [] + }, + { + "name": "misskey", + "host": "misskey.io", + "url": "https://emoji.arkjp.net/misskey/misskey.svg", + "aliases": [] + }, + { + "name": "smiling_ai", + "host": "misskey.io", + "url": "https://emoji.arkjp.net/misskey/smiling_ai.png", + "aliases": [] + } + ] + }, + "text": "#test ", + "cw": null, + "visibility": "public", + "renoteCount": 0, + "repliesCount": 0, + "reactions": {}, + "tags": [ + "test" + ], + "emojis": [], + "fileIds": [], + "files": [], + "replyId": null, + "renoteId": null, + "uri": "https://misskey.io/notes/883hf5u81i" + }, + { + "id": "880u7ojkz7", + "createdAt": "2020-06-02T01:58:38.336Z", + "userId": "84c9aor4hj", + "user": { + "id": "84c9aor4hj", + "name": "takimura@めいめい鯖​:@mei23:", + "username": "cv_k", + "host": "misskey.m544.net", + "avatarUrl": "https://misskey-drive.m544.net/files/a7fdfaea-3211-458d-ae34-9f886b84d28c/url-circle.png", + "avatarBlurhash": null, + "avatarColor": null, + "instance": { + "name": "めいすきー", + "softwareName": "misskey", + "softwareVersion": "10.102.344-m544", + "iconUrl": "https://misskey-drive2.m544.net/m544/owv7c0xeho8x0xq8kgnn2iie.png", + "faviconUrl": "https://misskey-drive2.m544.net/m544/owv7c0xeho8x0xq8kgnn2iie.png", + "themeColor": "#5A0608" + }, + "emojis": [] + }, + "text": "#test https://twitter.com/cv_k/status/1267603306316066816 ※めいすきー対応済", + "cw": null, + "visibility": "public", + "renoteCount": 0, + "repliesCount": 0, + "reactions": {}, + "tags": [ + "test" + ], + "emojis": [], + "fileIds": [], + "files": [], + "replyId": null, + "renoteId": null, + "uri": "https://misskey.m544.net/notes/717272c082008a34c26e5a13" + }, + { + "id": "87m575ns3y", + "createdAt": "2020-05-22T19:09:37.000Z", + "userId": "84dpht6uqf", + "user": { + "id": "84dpht6uqf", + "name": "のえる", + "username": "noellabo", + "host": "fedibird.com", + "avatarUrl": "https://slippy.xyz/files/thumbnail-ae4abff4-4af8-4bc4-b100-ecc3899fe504", + "avatarBlurhash": "yiOD2w%M_4Rk?vjbx]FyV@-;WCR6t7ni$*RknixtIoofI:_MkCR+t6VsRjRP$*V@M{ofS1kCkCxuozRjR*aes:t7xuniRjR*RjR*t7", + "avatarColor": null, + "instance": { + "name": "Fedibird", + "softwareName": "mastodon", + "softwareVersion": "3.2.0", + "iconUrl": "https://fedibird.com/android-chrome-192x192.png", + "faviconUrl": "https://fedibird.com/favicon.ico", + "themeColor": "#282c37" + }, + "emojis": [ + { + "name": "liberapay", + "host": "fedibird.com", + "url": "https://s3.fedibird.com/custom_emojis/images/000/025/634/original/5b8620742973f844.png", + "aliases": [] + }, + { + "name": "mastodon", + "host": "fedibird.com", + "url": "https://s3.fedibird.com/custom_emojis/images/000/008/396/original/1317b6f8efcf8318.png", + "aliases": [] + } + ] + }, + "text": "#test てすとですよ3", + "cw": null, + "visibility": "public", + "renoteCount": 0, + "repliesCount": 0, + "reactions": {}, + "tags": [ + "test" + ], + "emojis": [], + "fileIds": [], + "files": [], + "replyId": null, + "renoteId": null, + "uri": "https://fedibird.com/users/noellabo/statuses/104213681135151248", + "url": "https://fedibird.com/@noellabo/104213681135151248" + }, + { + "id": "87m56q883s", + "createdAt": "2020-05-22T19:09:17.000Z", + "userId": "84dpht6uqf", + "user": { + "id": "84dpht6uqf", + "name": "のえる", + "username": "noellabo", + "host": "fedibird.com", + "avatarUrl": "https://slippy.xyz/files/thumbnail-ae4abff4-4af8-4bc4-b100-ecc3899fe504", + "avatarBlurhash": "yiOD2w%M_4Rk?vjbx]FyV@-;WCR6t7ni$*RknixtIoofI:_MkCR+t6VsRjRP$*V@M{ofS1kCkCxuozRjR*aes:t7xuniRjR*RjR*t7", + "avatarColor": null, + "instance": { + "name": "Fedibird", + "softwareName": "mastodon", + "softwareVersion": "3.2.0", + "iconUrl": "https://fedibird.com/android-chrome-192x192.png", + "faviconUrl": "https://fedibird.com/favicon.ico", + "themeColor": "#282c37" + }, + "emojis": [ + { + "name": "liberapay", + "host": "fedibird.com", + "url": "https://s3.fedibird.com/custom_emojis/images/000/025/634/original/5b8620742973f844.png", + "aliases": [] + }, + { + "name": "mastodon", + "host": "fedibird.com", + "url": "https://s3.fedibird.com/custom_emojis/images/000/008/396/original/1317b6f8efcf8318.png", + "aliases": [] + } + ] + }, + "text": "#test てすとですよ2", + "cw": null, + "visibility": "public", + "renoteCount": 0, + "repliesCount": 0, + "reactions": {}, + "tags": [ + "test" + ], + "emojis": [], + "fileIds": [], + "files": [], + "replyId": null, + "renoteId": null, + "uri": "https://fedibird.com/users/noellabo/statuses/104213679804960887", + "url": "https://fedibird.com/@noellabo/104213679804960887" + }, + { + "id": "87m562b43l", + "createdAt": "2020-05-22T19:08:46.000Z", + "userId": "84dpht6uqf", + "user": { + "id": "84dpht6uqf", + "name": "のえる", + "username": "noellabo", + "host": "fedibird.com", + "avatarUrl": "https://slippy.xyz/files/thumbnail-ae4abff4-4af8-4bc4-b100-ecc3899fe504", + "avatarBlurhash": "yiOD2w%M_4Rk?vjbx]FyV@-;WCR6t7ni$*RknixtIoofI:_MkCR+t6VsRjRP$*V@M{ofS1kCkCxuozRjR*aes:t7xuniRjR*RjR*t7", + "avatarColor": null, + "instance": { + "name": "Fedibird", + "softwareName": "mastodon", + "softwareVersion": "3.2.0", + "iconUrl": "https://fedibird.com/android-chrome-192x192.png", + "faviconUrl": "https://fedibird.com/favicon.ico", + "themeColor": "#282c37" + }, + "emojis": [ + { + "name": "liberapay", + "host": "fedibird.com", + "url": "https://s3.fedibird.com/custom_emojis/images/000/025/634/original/5b8620742973f844.png", + "aliases": [] + }, + { + "name": "mastodon", + "host": "fedibird.com", + "url": "https://s3.fedibird.com/custom_emojis/images/000/008/396/original/1317b6f8efcf8318.png", + "aliases": [] + } + ] + }, + "text": "#test てすとですよ", + "cw": null, + "visibility": "public", + "renoteCount": 0, + "repliesCount": 0, + "reactions": {}, + "tags": [ + "test" + ], + "emojis": [], + "fileIds": [], + "files": [], + "replyId": null, + "renoteId": null, + "uri": "https://fedibird.com/users/noellabo/statuses/104213677783837992", + "url": "https://fedibird.com/@noellabo/104213677783837992" + } +] \ No newline at end of file diff --git a/services/notes/search.go b/services/notes/search.go index fd05422..35310cf 100644 --- a/services/notes/search.go +++ b/services/notes/search.go @@ -9,10 +9,10 @@ import ( type SearchRequest struct { Query string `json:"query"` Limit uint `json:"limit"` - SinceID string `json:"sinceId"` - UntilID string `json:"untilId"` - Host core.String `json:"host"` - UserID core.String `json:"userId"` + SinceID string `json:"sinceId,omitempty"` + UntilID string `json:"untilId,omitempty"` + Host core.String `json:"host,omitempty"` + UserID core.String `json:"userId,omitempty"` } // Validate the request. diff --git a/services/notes/search_by_tag.go b/services/notes/search_by_tag.go new file mode 100644 index 0000000..019fc9e --- /dev/null +++ b/services/notes/search_by_tag.go @@ -0,0 +1,54 @@ +package notes + +import ( + "github.com/yitsushi/go-misskey/core" + "github.com/yitsushi/go-misskey/models" +) + +// SearchByTagRequest represents an SearchByTag request. +type SearchByTagRequest struct { + Tag string `json:"tag,omitempty"` + Query [][]string `json:"query,omitempty"` + Limit uint `json:"limit"` + Reply bool `json:"reply,omitempty"` + Renote bool `json:"renote,omitempty"` + OnlyWithFiles bool `json:"withFiles,omitempty"` + OnlyPolls bool `json:"poll,omitempty"` + SinceID string `json:"sinceId,omitempty"` + UntilID string `json:"untilId,omitempty"` + Host core.String `json:"host,omitempty"` + UserID core.String `json:"userId,omitempty"` +} + +// Validate the request. +func (r SearchByTagRequest) Validate() error { + if r.Tag == "" && len(r.Query) == 0 { + return core.RequestValidationError{ + Request: r, + Message: core.UndefinedRequiredField, + Field: "Tag || Query", + } + } + + if r.Limit < 1 || r.Limit > 100 { + return core.RequestValidationError{ + Request: r, + Message: core.NewRangeError(1, 100), + Field: "Limit", + } + } + + return nil +} + +// SearchByTag endpoint. +func (s *Service) SearchByTag(request SearchByTagRequest) ([]models.Note, error) { + var response []models.Note + + err := s.Call( + &core.JSONRequest{Request: &request, Path: "/notes/search-by-tag"}, + &response, + ) + + return response, err +} diff --git a/services/notes/search_by_tag_test.go b/services/notes/search_by_tag_test.go new file mode 100644 index 0000000..5eed259 --- /dev/null +++ b/services/notes/search_by_tag_test.go @@ -0,0 +1,68 @@ +package notes_test + +import ( + "log" + "net/http" + "os" + "testing" + + "github.com/sirupsen/logrus" + "github.com/stretchr/testify/assert" + "github.com/yitsushi/go-misskey" + "github.com/yitsushi/go-misskey/core" + "github.com/yitsushi/go-misskey/services/notes" + "github.com/yitsushi/go-misskey/test" +) + +func TestService_SearchByTag(t *testing.T) { + client := test.MakeMockClient(test.SimpleMockOptions{ + Endpoint: "/api/notes/search-by-tag", + RequestData: ¬es.SearchByTagRequest{}, + ResponseFile: "search.json", + StatusCode: http.StatusOK, + }) + + noteList, err := client.Notes().SearchByTag(notes.SearchByTagRequest{ + Tag: "test", + Limit: 2, + }) + if !assert.NoError(t, err) { + return + } + + assert.Len(t, noteList, 2) +} + +func TestSearchByTagRequest_Validate(t *testing.T) { + test.ValidateRequests( + t, + []core.BaseRequest{ + notes.SearchByTagRequest{}, + notes.SearchByTagRequest{Tag: ""}, + notes.SearchByTagRequest{Query: [][]string{}}, + notes.SearchByTagRequest{Limit: 10}, + }, + []core.BaseRequest{ + notes.SearchByTagRequest{Tag: "test", Limit: 20}, + }, + ) +} + +func ExampleService_SearchByTag() { + client := misskey.NewClient("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN")) + client.LogLevel(logrus.DebugLevel) + + noteList, err := client.Notes().SearchByTag(notes.SearchByTagRequest{ + Tag: "test", + Limit: 10, + }) + if err != nil { + log.Printf("[Notes] Error happened: %s", err) + + return + } + + for _, note := range noteList { + log.Printf(" - %s", note.Text) + } +}