Merge pull request #2 from 178inaba/account

Add GetAccount
This commit is contained in:
mattn 2017-04-14 11:48:55 +09:00 committed by GitHub
commit 3646db025f

View File

@ -124,6 +124,24 @@ func RegisterApp(appConfig *AppConfig) (*Application, error) {
return app, nil return app, nil
} }
type Account struct {
ID int64 `json:"id"`
Username string `json:"username"`
Acct string `json:"acct"`
DisplayName string `json:"display_name"`
Locked bool `json:"locked"`
CreatedAt time.Time `json:"created_at"`
FollowersCount int64 `json:"followers_count"`
FollowingCount int64 `json:"following_count"`
StatusesCount int64 `json:"statuses_count"`
Note string `json:"note"`
URL string `json:"url"`
Avatar string `json:"avatar"`
AvatarStatic string `json:"avatar_static"`
Header string `json:"header"`
HeaderStatic string `json:"header_static"`
}
type Visibility int64 type Visibility int64
type Toot struct { type Toot struct {
@ -136,42 +154,52 @@ type Toot struct {
} }
type Status struct { type Status struct {
ID int64 `json:"id"` ID int64 `json:"id"`
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
InReplyToID interface{} `json:"in_reply_to_id"` InReplyToID interface{} `json:"in_reply_to_id"`
InReplyToAccountID interface{} `json:"in_reply_to_account_id"` InReplyToAccountID interface{} `json:"in_reply_to_account_id"`
Sensitive bool `json:"sensitive"` Sensitive bool `json:"sensitive"`
SpoilerText string `json:"spoiler_text"` SpoilerText string `json:"spoiler_text"`
Visibility string `json:"visibility"` Visibility string `json:"visibility"`
Application interface{} `json:"application"` Application interface{} `json:"application"`
Account struct { Account Account `json:"account"`
ID int64 `json:"id"` MediaAttachments []interface{} `json:"media_attachments"`
Username string `json:"username"` Mentions []interface{} `json:"mentions"`
Acct string `json:"acct"` Tags []interface{} `json:"tags"`
DisplayName string `json:"display_name"` URI string `json:"uri"`
Locked bool `json:"locked"` Content string `json:"content"`
CreatedAt time.Time `json:"created_at"` URL string `json:"url"`
FollowersCount int64 `json:"followers_count"` ReblogsCount int64 `json:"reblogs_count"`
FollowingCount int64 `json:"following_count"` FavouritesCount int64 `json:"favourites_count"`
StatusesCount int64 `json:"statuses_count"` Reblog interface{} `json:"reblog"`
Note string `json:"note"` Favourited interface{} `json:"favourited"`
URL string `json:"url"` Reblogged interface{} `json:"reblogged"`
Avatar string `json:"avatar"` }
AvatarStatic string `json:"avatar_static"`
Header string `json:"header"` func (c *client) GetAccount(id int) (*Account, error) {
HeaderStatic string `json:"header_static"` url, err := url.Parse(c.config.Server)
} `json:"account"` if err != nil {
MediaAttachments []interface{} `json:"media_attachments"` return nil, err
Mentions []interface{} `json:"mentions"` }
Tags []interface{} `json:"tags"` url.Path = path.Join(url.Path, fmt.Sprintf("/api/v1/accounts/%d", id))
URI string `json:"uri"`
Content string `json:"content"` req, err := http.NewRequest("GET", url.String(), nil)
URL string `json:"url"` if err != nil {
ReblogsCount int64 `json:"reblogs_count"` return nil, err
FavouritesCount int64 `json:"favourites_count"` }
Reblog interface{} `json:"reblog"` req.Header.Set("Authorization", "Bearer "+c.config.AccessToken)
Favourited interface{} `json:"favourited"` resp, err := c.Do(req)
Reblogged interface{} `json:"reblogged"` if err != nil {
return nil, err
}
defer resp.Body.Close()
account := &Account{}
err = json.NewDecoder(resp.Body).Decode(account)
if err != nil {
return nil, err
}
return account, nil
} }
func (c *client) GetTimelineHome() ([]*Status, error) { func (c *client) GetTimelineHome() ([]*Status, error) {