Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F10669544
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
View Options
diff --git a/user.go b/user.go
index 5973d9c..dd4f67b 100644
--- a/user.go
+++ b/user.go
@@ -1,34 +1,62 @@
package writeas
-import "time"
+import (
+ "fmt"
+ "time"
+)
type (
// AuthUser represents a just-authenticated user. It contains information
// that'll only be returned once (now) per user session.
AuthUser struct {
AccessToken string `json:"access_token,omitempty"`
Password string `json:"password,omitempty"`
User *User `json:"user"`
}
// User represents a registered Write.as user.
User struct {
Username string `json:"username"`
Email string `json:"email"`
Created time.Time `json:"created"`
// Optional properties
Subscription *UserSubscription `json:"subscription"`
}
// UserSubscription contains information about a user's Write.as
// subscription.
UserSubscription struct {
Name string `json:"name"`
Begin time.Time `json:"begin"`
End time.Time `json:"end"`
AutoRenew bool `json:"auto_renew"`
Active bool `json:"is_active"`
Delinquent bool `json:"is_delinquent"`
}
)
+
+// GetMe retrieves the authenticated User's information.
+// See: https://developers.write.as/docs/api/#retrieve-authenticated-user
+func (c *Client) GetMe(verbose bool) (*User, error) {
+ if c.Token() == "" {
+ return nil, fmt.Errorf("Unable to get user; no access token given.")
+ }
+
+ params := ""
+ if verbose {
+ params = "?verbose=true"
+ }
+ env, err := c.get("/me"+params, nil)
+ if err != nil {
+ return nil, err
+ }
+
+ var u *User
+ var ok bool
+ if u, ok = env.Data.(*User); !ok {
+ return nil, fmt.Errorf("Wrong data returned from API.")
+ }
+
+ return u, nil
+}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Fri, May 16, 11:26 AM (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3239036
Attached To
rWGO writeas-go
Event Timeline
Log In to Comment