Browse Source

users

master v0.1.3
ldf 3 years ago
parent
commit
81c9143558
  1. 480
      cmd/log/asana.log
  2. 67
      module/users/user.go

480
cmd/log/asana.log
File diff suppressed because it is too large
View File

67
module/users/user.go

@ -0,0 +1,67 @@
package users
import (
"encoding/json"
"errors"
"fmt"
"net/http"
"git.drinkme.beer/yinghe/log"
"git.drinkme.beer/yinghe/asana/util"
)
const (
URI = "/api/1.0/users/%s"
)
type User struct {
ID string `json:"gid"`
ResourceType string `json:"resource_type"`
Name string `json:"name"`
Email string `json:"email"`
Photo map[string]string `json:"photo"`
Workspaces []struct {
ID string `json:"gid"`
ResourceType string `json:"resource_type"`
Name string `json:"name"`
} `json:"workspaces"`
}
type Response struct {
Data User `json:"data"`
}
func (u User) Get(paToken string) (*User, error) {
var (
err error
resp Response
)
headers := make(map[string]string)
headers["Authorization"] = paToken
headers["Content-Type"] = util.ContentType
client := util.NewHttpClient(util.AsanaHost, fmt.Sprintf(URI, u.ID), util.HttpGetMethod, nil)
client.Headers = headers
err = client.Request()
if nil != err {
log.Errorf("failed to obtain user info: %s", err.Error())
return nil, err
}
log.Infof("response status: %d", client.HTTPStatus)
if http.StatusOK != client.HTTPStatus {
log.Errorf("unexpected response")
err = errors.New("unexpected response")
return nil, err
}
err = json.Unmarshal(client.Body, &resp)
if nil != err {
log.Errorf("illegal task result: %s", err.Error())
return nil, err
}
return &resp.Data, err
}
Loading…
Cancel
Save