Skip to content

Commit

Permalink
add OAuth Me() function
Browse files Browse the repository at this point in the history
  • Loading branch information
aggrolite committed May 5, 2015
1 parent d046ffa commit 8817737
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions oauth_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,26 @@ func (s OAuthSession) RevokeToken() error {

return nil
}

func (s OAuthSession) Me() (*Redditor, error) {
req := &oauthRequest{
accessToken: s.accessToken,
url: "https://oauth.reddit.com/api/v1/me",
useragent: s.useragent,
}
body, err := req.getResponse()
if err != nil {
return nil, err
}

type Response struct {
Data Redditor
}
r := &Response{}
err = json.NewDecoder(body).Decode(r)
if err != nil {
return nil, err
}

return &r.Data, nil
}

0 comments on commit 8817737

Please sign in to comment.