-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Retrieve the user assigned to the token (#100)
* implement Users/Me * fix warning * add Request type. * change exampleService_Me * fix lint errors.
- Loading branch information
Showing
3 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
{ | ||
"id": "9dr5dkiiby", | ||
"name": "test", | ||
"username": "test", | ||
"host": null, | ||
"avatarUrl": "", | ||
"avatarBlurhash": "edRC-.t7_4t7s;%Lj[NHfPoK%hj[RiayM{%NayRPayozt6ayWBj[ay", | ||
"isBot": false, | ||
"isCat": true, | ||
"emojis": {}, | ||
"onlineStatus": "online", | ||
"badgeRoles": [], | ||
"url": null, | ||
"uri": null, | ||
"movedTo": null, | ||
"alsoKnownAs": null, | ||
"createdAt": "2023-04-19T11:01:05.178Z", | ||
"updatedAt": "2023-09-14T06:20:41.417Z", | ||
"lastFetchedAt": null, | ||
"bannerUrl": null, | ||
"bannerBlurhash": null, | ||
"isLocked": false, | ||
"isSilenced": false, | ||
"isSuspended": false, | ||
"description": "", | ||
"location": "", | ||
"birthday": "", | ||
"lang": "ja", | ||
"fields": [], | ||
"followersCount": 0, | ||
"followingCount": 0, | ||
"notesCount": 0, | ||
"pinnedNoteIds": [], | ||
"pinnedNotes": [], | ||
"pinnedPageId": null, | ||
"pinnedPage": null, | ||
"publicReactions": true, | ||
"ffVisibility": "public", | ||
"twoFactorEnabled": false, | ||
"usePasswordLessLogin": false, | ||
"securityKeys": false, | ||
"roles": [], | ||
"memo": null, | ||
"avatarId": "9ivuypq810", | ||
"bannerId": null, | ||
"isModerator": false, | ||
"isAdmin": false, | ||
"injectFeaturedNote": true, | ||
"receiveAnnouncementEmail": true, | ||
"alwaysMarkNsfw": false, | ||
"autoSensitive": false, | ||
"carefulBot": false, | ||
"autoAcceptFollowed": true, | ||
"noCrawle": false, | ||
"preventAiLearning": true, | ||
"isExplorable": true, | ||
"isDeleted": false, | ||
"hideOnlineStatus": false, | ||
"hasUnreadSpecifiedNotes": false, | ||
"hasUnreadMentions": true, | ||
"hasUnreadAnnouncement": false, | ||
"hasUnreadAntenna": false, | ||
"hasUnreadChannel": false, | ||
"hasUnreadNotification": false, | ||
"hasPendingReceivedFollowRequest": false, | ||
"mutedWords": [], | ||
"mutedInstances": [], | ||
"mutingNotificationTypes": [], | ||
"emailNotificationTypes": [], | ||
"achievements": [], | ||
"loggedInDays": 80, | ||
"policies": { | ||
"gtlAvailable": true, | ||
"ltlAvailable": true, | ||
"canPublicNote": true, | ||
"canInvite": false, | ||
"inviteLimit": 0, | ||
"inviteLimitCycle": 10080, | ||
"inviteExpirationTime": 0, | ||
"canManageCustomEmojis": false, | ||
"canSearchNotes": true, | ||
"canHideAds": false, | ||
"driveCapacityMb": 10000, | ||
"alwaysMarkNsfw": false, | ||
"pinLimit": 5, | ||
"antennaLimit": 5, | ||
"wordMuteLimit": 200, | ||
"webhookLimit": 3, | ||
"clipLimit": 10, | ||
"noteEachClipsLimit": 200, | ||
"userListLimit": 10, | ||
"userEachUserListsLimit": 50, | ||
"rateLimitFactor": 1 | ||
}, | ||
"email": "[email protected]", | ||
"emailVerified": true, | ||
"securityKeysList": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package users | ||
|
||
import ( | ||
"github.com/yitsushi/go-misskey/core" | ||
"github.com/yitsushi/go-misskey/models" | ||
) | ||
|
||
// MeRequest represents a request to retrieve a user who has been issued a token. | ||
type MeRequest struct{} | ||
|
||
// Validate the request. | ||
func (r MeRequest) Validate() error { | ||
return nil | ||
} | ||
|
||
// Me gets the user issued the token. | ||
func (s *Service) Me() (models.User, error) { | ||
var user models.User | ||
err := s.Call( | ||
&core.JSONRequest{ | ||
Path: "/i", | ||
Request: &MeRequest{}, | ||
}, | ||
&user, | ||
) | ||
|
||
return user, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package users_test | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/yitsushi/go-misskey" | ||
"github.com/yitsushi/go-misskey/services/users" | ||
"github.com/yitsushi/go-misskey/test" | ||
) | ||
|
||
func TestService_Me(t *testing.T) { | ||
client := test.MakeMockClient(test.SimpleMockOptions{ | ||
Endpoint: "/api/i", | ||
ResponseFile: "i.json", | ||
StatusCode: http.StatusOK, | ||
RequestData: &users.MeRequest{}, | ||
}) | ||
|
||
user, err := client.Users().Me() | ||
if !assert.NoError(t, err) { | ||
return | ||
} | ||
|
||
assert.Equal(t, user.ID, "9dr5dkiiby") | ||
} | ||
|
||
func ExampleService_Me() { | ||
client, _ := misskey.NewClientWithOptions(misskey.WithSimpleConfig("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN"))) | ||
|
||
user, err := client.Users().Me() | ||
if err != nil { | ||
log.Printf("[Users/Me] %s", err) | ||
|
||
return | ||
} | ||
|
||
log.Printf("[Users/Me] %s %s", user.Username, user.Name) | ||
} |