bunch of API changes
This commit is contained in:
@@ -6,15 +6,6 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Registration is the response to the UserRegister API. The register API can
|
||||
// return multiple errors, which will be stored in the Errors array. Check for
|
||||
// len(Errors) == 0 to see if an error occurred
|
||||
type Registration struct {
|
||||
Success bool `json:"success"`
|
||||
Message string `json:"message,omitempty"`
|
||||
Errors []Error `json:"errors,omitempty"`
|
||||
}
|
||||
|
||||
// UserRegister registers a new user on the Pixeldrain server. username and
|
||||
// password are always required. email is optional, but without it you will not
|
||||
// be able to reset your password in case you forget it. captcha depends on
|
||||
@@ -24,18 +15,17 @@ type Registration struct {
|
||||
// The register API can return multiple errors, which will be stored in the
|
||||
// Errors array. Check for len(Errors) == 0 to see if an error occurred. If err
|
||||
// != nil it means a connection error occurred
|
||||
func (p *PixelAPI) UserRegister(username, email, password, captcha string) (resp *Registration, err error) {
|
||||
resp = &Registration{}
|
||||
var form = url.Values{}
|
||||
form.Add("username", username)
|
||||
form.Add("email", email)
|
||||
form.Add("password", password)
|
||||
form.Add("recaptcha_response", captcha)
|
||||
err = p.form("POST", p.apiEndpoint+"/user/register", form, resp, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
func (p *PixelAPI) UserRegister(username, email, password, captcha string) (err error) {
|
||||
return p.form(
|
||||
"POST", p.apiEndpoint+"/user/register",
|
||||
url.Values{
|
||||
"username": {username},
|
||||
"email": {email},
|
||||
"password": {password},
|
||||
"recaptcha_response": {captcha},
|
||||
},
|
||||
nil, true,
|
||||
)
|
||||
}
|
||||
|
||||
// Login is the success response to the `user/login` API
|
||||
@@ -48,14 +38,12 @@ type Login struct {
|
||||
// contain the returned API key. If saveKey is true the API key will also be
|
||||
// saved in the client and following requests with this client will be
|
||||
// autenticated
|
||||
func (p *PixelAPI) UserLogin(username, password string, saveKey bool) (resp *Login, err error) {
|
||||
resp = &Login{}
|
||||
func (p *PixelAPI) UserLogin(username, password string, saveKey bool) (resp Login, err error) {
|
||||
var form = url.Values{}
|
||||
form.Add("username", username)
|
||||
form.Add("password", password)
|
||||
err = p.form("POST", p.apiEndpoint+"/user/login", form, resp, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if err = p.form("POST", p.apiEndpoint+"/user/login", form, &resp, true); err != nil {
|
||||
return resp, err
|
||||
}
|
||||
if saveKey {
|
||||
p.APIKey = resp.APIKey
|
||||
@@ -71,61 +59,48 @@ type UserInfo struct {
|
||||
}
|
||||
|
||||
// UserInfo returns information about the logged in user. Requires an API key
|
||||
func (p *PixelAPI) UserInfo() (resp *UserInfo, err error) {
|
||||
resp = &UserInfo{}
|
||||
err = p.jsonRequest("GET", p.apiEndpoint+"/user", resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
func (p *PixelAPI) UserInfo() (resp UserInfo, err error) {
|
||||
return resp, p.jsonRequest("GET", p.apiEndpoint+"/user", &resp, false)
|
||||
}
|
||||
|
||||
// UserSessionDestroy destroys an API key so it can no longer be used to perform
|
||||
// actions
|
||||
func (p *PixelAPI) UserSessionDestroy(key string) (err error) {
|
||||
return p.jsonRequest("DELETE", p.apiEndpoint+"/user/session", nil)
|
||||
return p.jsonRequest("DELETE", p.apiEndpoint+"/user/session", nil, false)
|
||||
}
|
||||
|
||||
// UserFiles is a list of files uploaded by a user
|
||||
type UserFiles struct {
|
||||
Success bool `json:"success"`
|
||||
Files []FileInfo `json:"files"`
|
||||
}
|
||||
|
||||
func (p *PixelAPI) UserFiles(page, limit int) (resp *UserFiles, err error) {
|
||||
resp = &UserFiles{Files: make([]FileInfo, 0)}
|
||||
err = p.jsonRequest(
|
||||
"GET",
|
||||
fmt.Sprintf("%s/user/files?page=%d&limit=%d", p.apiEndpoint, page, limit),
|
||||
resp,
|
||||
// UserFiles gets files uploaded by a user
|
||||
func (p *PixelAPI) UserFiles(page, limit int) (resp UserFiles, err error) {
|
||||
return resp, p.jsonRequest(
|
||||
"GET", fmt.Sprintf("%s/user/files?page=%d&limit=%d", p.apiEndpoint, page, limit), &resp, false,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// UserLists is a list of lists created by a user
|
||||
type UserLists struct {
|
||||
Success bool `json:"success"`
|
||||
Lists []List `json:"lists"`
|
||||
}
|
||||
|
||||
func (p *PixelAPI) UserLists(page, limit int) (resp *UserLists, err error) {
|
||||
resp = &UserLists{Lists: make([]List, 0)}
|
||||
if err = p.jsonRequest(
|
||||
"GET",
|
||||
fmt.Sprintf("%s/user/lists?page=%d&limit=%d", p.apiEndpoint, page, limit),
|
||||
resp,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
// UserLists gets lists created by a user
|
||||
func (p *PixelAPI) UserLists(page, limit int) (resp UserLists, err error) {
|
||||
return resp, p.jsonRequest(
|
||||
"GET", fmt.Sprintf("%s/user/lists?page=%d&limit=%d", p.apiEndpoint, page, limit), &resp, false,
|
||||
)
|
||||
}
|
||||
|
||||
// UserPasswordSet changes the user's password
|
||||
func (p *PixelAPI) UserPasswordSet(oldPW, newPW string) (err error) {
|
||||
var form = url.Values{}
|
||||
form.Add("old_password", oldPW)
|
||||
form.Add("new_password", newPW)
|
||||
return p.form("PUT", p.apiEndpoint+"/user/password", form, nil, true)
|
||||
return p.form(
|
||||
"PUT", p.apiEndpoint+"/user/password",
|
||||
url.Values{"old_password": {oldPW}, "new_password": {newPW}}, nil, true,
|
||||
)
|
||||
}
|
||||
|
||||
// UserEmailReset starts the e-mail change process. An email will be sent to the
|
||||
@@ -141,9 +116,10 @@ func (p *PixelAPI) UserEmailReset(email string, delete bool) (err error) {
|
||||
|
||||
// UserEmailResetConfirm finishes process of changing a user's e-mail address
|
||||
func (p *PixelAPI) UserEmailResetConfirm(key string) (err error) {
|
||||
var form = url.Values{}
|
||||
form.Add("key", key)
|
||||
return p.form("PUT", p.apiEndpoint+"/user/email_reset_cofirm", form, nil, true)
|
||||
return p.form(
|
||||
"PUT", p.apiEndpoint+"/user/email_reset_confirm",
|
||||
url.Values{"key": {key}}, nil, true,
|
||||
)
|
||||
}
|
||||
|
||||
// UserPasswordReset starts the password reset process. An email will be sent
|
||||
|
Reference in New Issue
Block a user