6 Commits
Author | SHA1 | Message | Date |
---|---|---|---|
frank | fea6efb20c |
expand Asana attach method for aes256 decryption
|
2 years ago |
ldf | 863d7a899c |
comment content fixed
|
3 years ago |
ldf | b68cf87c6b |
asana html text
|
3 years ago |
ldf | 93bc316578 |
rich text
|
3 years ago |
ldf | 81c9143558 |
users
|
3 years ago |
ldf | 9fe7706466 |
omit empty.
|
3 years ago |
10 changed files with 321 additions and 528 deletions
-
480cmd/log/asana.log
-
14module/attach/attachments.go
-
9module/error_response.go
-
54module/story/stories.go
-
68module/task/follower.go
-
98module/task/task.go
-
67module/users/user.go
-
46text/rich_text.go
-
1util/constant.go
-
12util/http.go
480
cmd/log/asana.log
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,9 @@ |
|||||
|
package module |
||||
|
|
||||
|
type Error struct { |
||||
|
Code string `json:"error"` |
||||
|
Message string `json:"message"` |
||||
|
Help string `json:"help"` |
||||
|
} |
||||
|
|
||||
|
type Errors []Error |
@ -0,0 +1,68 @@ |
|||||
|
package task |
||||
|
|
||||
|
import ( |
||||
|
"encoding/json" |
||||
|
"fmt" |
||||
|
"net/http" |
||||
|
|
||||
|
"git.drinkme.beer/yinghe/log" |
||||
|
|
||||
|
"git.drinkme.beer/yinghe/asana/util" |
||||
|
) |
||||
|
|
||||
|
const ( |
||||
|
AddFollowersURI = "/api/1.0/tasks/%s/addFollowers" |
||||
|
) |
||||
|
|
||||
|
type Follower struct { |
||||
|
Followers []string `json:"followers,omitempty"` |
||||
|
} |
||||
|
|
||||
|
type FollowersRequest struct { |
||||
|
Data Follower `json:"data"` |
||||
|
} |
||||
|
|
||||
|
func (f Follower) Add(token, taskID string) error { |
||||
|
var ( |
||||
|
req FollowersRequest |
||||
|
) |
||||
|
if "" == token || "" == taskID { |
||||
|
log.Errorf("illegal request") |
||||
|
return fmt.Errorf("illegal request") |
||||
|
} |
||||
|
if nil == f.Followers { |
||||
|
log.Errorf("invalid request, followers") |
||||
|
return fmt.Errorf("none followers") |
||||
|
} |
||||
|
|
||||
|
req.Data = f |
||||
|
buf, err := json.Marshal(&req) |
||||
|
if nil != err { |
||||
|
log.Errorf("invalid arguments: %s", err.Error()) |
||||
|
return err |
||||
|
} |
||||
|
log.Infof("request ==> %s", string(buf)) |
||||
|
|
||||
|
headers := make(map[string]string) |
||||
|
headers["Authorization"] = token |
||||
|
headers["Content-Type"] = util.ContentType |
||||
|
|
||||
|
client := util.NewHttpClient(util.AsanaHost, |
||||
|
fmt.Sprintf(AddFollowersURI, taskID), |
||||
|
util.HttpPostMethod, buf) |
||||
|
client.Headers = headers |
||||
|
|
||||
|
err = client.Request() |
||||
|
if nil != err { |
||||
|
log.Errorf("failed to create new Asana task: %s", err.Error()) |
||||
|
return err |
||||
|
} |
||||
|
log.Infof("response status: %d", client.HTTPStatus) |
||||
|
if http.StatusOK != client.HTTPStatus { |
||||
|
log.Errorf("unexpected response") |
||||
|
err = fmt.Errorf("unexpected response") |
||||
|
return err |
||||
|
} else { |
||||
|
return nil |
||||
|
} |
||||
|
} |
@ -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,omitempty"` |
||||
|
ResourceType string `json:"resource_type,omitempty"` |
||||
|
Name string `json:"name,omitempty"` |
||||
|
Email string `json:"email,omitempty"` |
||||
|
|
||||
|
Photo map[string]string `json:"photo,omitempty"` |
||||
|
Workspaces []struct { |
||||
|
ID string `json:"gid,omitempty"` |
||||
|
ResourceType string `json:"resource_type,omitempty"` |
||||
|
Name string `json:"name,omitempty"` |
||||
|
} `json:"workspaces,omitempty"` |
||||
|
} |
||||
|
|
||||
|
type Response struct { |
||||
|
Data User `json:"data,omitempty"` |
||||
|
} |
||||
|
|
||||
|
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 |
||||
|
} |
@ -0,0 +1,46 @@ |
|||||
|
package text |
||||
|
|
||||
|
import ( |
||||
|
"fmt" |
||||
|
"html" |
||||
|
"regexp" |
||||
|
"strings" |
||||
|
) |
||||
|
|
||||
|
const ( |
||||
|
DataMention = `<a data-asana-gid="%s"/>` |
||||
|
) |
||||
|
|
||||
|
// `<body>
|
||||
|
// testing
|
||||
|
// <a data-asana-gid="1199521781039350"/>
|
||||
|
// <a data-asana-gid="1200773217477032"/>
|
||||
|
// </body>`
|
||||
|
func Mention(gid string) string { |
||||
|
return fmt.Sprintf(DataMention, gid) |
||||
|
} |
||||
|
|
||||
|
func DeleteHtmlTags(src string) string { |
||||
|
var ( |
||||
|
line int |
||||
|
v, des string |
||||
|
) |
||||
|
if "" == src || 0 == len(src) { |
||||
|
return "" |
||||
|
} |
||||
|
reg := regexp.MustCompile(`<.+?>`) |
||||
|
str := reg.ReplaceAllString(src, " ") |
||||
|
s := strings.Split(str, "\n") |
||||
|
for _, v = range s { |
||||
|
if 0 == len(strings.TrimSpace(v)) { |
||||
|
continue |
||||
|
} |
||||
|
des = des + fmt.Sprintf("\n%s", v) |
||||
|
line++ |
||||
|
} |
||||
|
if 0 == line { |
||||
|
return "" |
||||
|
} |
||||
|
|
||||
|
return html.UnescapeString(des)[1:] |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue