ldf
3 years ago
8 changed files with 223 additions and 41 deletions
-
9module/error_response.go
-
4module/story/stories.go
-
68module/task/follower.go
-
145module/task/task.go
-
20module/users/user.go
-
16text/rich_text.go
-
1util/constant.go
-
1util/http.go
@ -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,16 @@ |
|||
package text |
|||
|
|||
import "fmt" |
|||
|
|||
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) |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue