|
@ -67,7 +67,7 @@ func (r Request) Update(taskID string) error { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
if http.StatusOK != c.HTTPStatus { |
|
|
if http.StatusOK != c.HTTPStatus { |
|
|
log.Infof("response: %s", string(c.Body)) |
|
|
|
|
|
|
|
|
c.Print() |
|
|
log.Errorf("unexpected response") |
|
|
log.Errorf("unexpected response") |
|
|
err = errors.New("unexpected response") |
|
|
err = errors.New("unexpected response") |
|
|
return err |
|
|
return err |
|
@ -86,7 +86,7 @@ func (r Request) Create() (resp *Response, err error) { |
|
|
|
|
|
|
|
|
log.Infof("response status: %d", client.HTTPStatus) |
|
|
log.Infof("response status: %d", client.HTTPStatus) |
|
|
if http.StatusCreated != client.HTTPStatus { |
|
|
if http.StatusCreated != client.HTTPStatus { |
|
|
log.Infof("response: %s", string(client.Body)) |
|
|
|
|
|
|
|
|
client.Print() |
|
|
log.Errorf("unexpected response") |
|
|
log.Errorf("unexpected response") |
|
|
err = errors.New("unexpected response") |
|
|
err = errors.New("unexpected response") |
|
|
return |
|
|
return |
|
@ -94,7 +94,7 @@ func (r Request) Create() (resp *Response, err error) { |
|
|
|
|
|
|
|
|
err = json.Unmarshal(client.Body, &respData) |
|
|
err = json.Unmarshal(client.Body, &respData) |
|
|
if nil != err { |
|
|
if nil != err { |
|
|
log.Infof("response: %s", string(client.Body)) |
|
|
|
|
|
|
|
|
client.Print() |
|
|
log.Errorf("illegal task result: %s", err.Error()) |
|
|
log.Errorf("illegal task result: %s", err.Error()) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
@ -105,64 +105,11 @@ func (r Request) Create() (resp *Response, err error) { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//func (r Request) Create() (resp *Response, err error) {
|
|
|
|
|
|
// var (
|
|
|
|
|
|
// reqData Data
|
|
|
|
|
|
// respData struct {
|
|
|
|
|
|
// Response Response `json:"data"`
|
|
|
|
|
|
// }
|
|
|
|
|
|
// )
|
|
|
|
|
|
//
|
|
|
|
|
|
// resp = new(Response)
|
|
|
|
|
|
//
|
|
|
|
|
|
// headers := make(map[string]string)
|
|
|
|
|
|
// headers["Authorization"] = r.paToken
|
|
|
|
|
|
// headers["Content-Type"] = util.ContentType
|
|
|
|
|
|
//
|
|
|
|
|
|
// if "" == r.ResourceSubtype {
|
|
|
|
|
|
// r.ResourceSubtype = ResourceSubtype
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// reqData.Request = r
|
|
|
|
|
|
//
|
|
|
|
|
|
// buf, err := json.Marshal(&reqData)
|
|
|
|
|
|
// if nil != err {
|
|
|
|
|
|
// log.Errorf("failed to generate task request: %s", err.Error())
|
|
|
|
|
|
// return
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// log.Infof("request: %s", string(buf))
|
|
|
|
|
|
//
|
|
|
|
|
|
// client := util.NewHttpClient(util.AsanaHost, URI, util.HttpPostMethod, buf)
|
|
|
|
|
|
// client.Headers = headers
|
|
|
|
|
|
//
|
|
|
|
|
|
// err = client.Request()
|
|
|
|
|
|
// if nil != err {
|
|
|
|
|
|
// log.Errorf("failed to create new Asana task: %s", err.Error())
|
|
|
|
|
|
// return
|
|
|
|
|
|
// }
|
|
|
|
|
|
// log.Infof("response status: %d", client.HTTPStatus)
|
|
|
|
|
|
// if http.StatusCreated != client.HTTPStatus {
|
|
|
|
|
|
// log.Errorf("unexpected response")
|
|
|
|
|
|
// err = errors.New("unexpected response")
|
|
|
|
|
|
// return
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// err = json.Unmarshal(client.Body, &respData)
|
|
|
|
|
|
// if nil != err {
|
|
|
|
|
|
// log.Errorf("illegal task result: %s", err.Error())
|
|
|
|
|
|
// return
|
|
|
|
|
|
// }
|
|
|
|
|
|
// resp = &respData.Response
|
|
|
|
|
|
// log.Infof("[%s]new task ID:%s", r.TicketID, resp.ID)
|
|
|
|
|
|
// return
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
func (r Request) call(uri, httpMethod string) (*util.Client, error) { |
|
|
func (r Request) call(uri, httpMethod string) (*util.Client, error) { |
|
|
|
|
|
|
|
|
var ( |
|
|
var ( |
|
|
err error |
|
|
err error |
|
|
reqData Data |
|
|
reqData Data |
|
|
|
|
|
client = new(util.Client) |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
headers := make(map[string]string) |
|
|
headers := make(map[string]string) |
|
@ -178,18 +125,18 @@ func (r Request) call(uri, httpMethod string) (*util.Client, error) { |
|
|
buf, err := json.Marshal(&reqData) |
|
|
buf, err := json.Marshal(&reqData) |
|
|
if nil != err { |
|
|
if nil != err { |
|
|
log.Errorf("failed to generate task request: %s", err.Error()) |
|
|
log.Errorf("failed to generate task request: %s", err.Error()) |
|
|
return nil, err |
|
|
|
|
|
|
|
|
return client, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
log.Infof("request: %s", string(buf)) |
|
|
log.Infof("request: %s", string(buf)) |
|
|
|
|
|
|
|
|
client := util.NewHttpClient(util.AsanaHost, uri, httpMethod, buf) |
|
|
|
|
|
|
|
|
client = util.NewHttpClient(util.AsanaHost, uri, httpMethod, buf) |
|
|
client.Headers = headers |
|
|
client.Headers = headers |
|
|
|
|
|
|
|
|
err = client.Request() |
|
|
err = client.Request() |
|
|
if nil != err { |
|
|
if nil != err { |
|
|
log.Errorf("failed to create new Asana task: %s", err.Error()) |
|
|
log.Errorf("failed to create new Asana task: %s", err.Error()) |
|
|
return nil, err |
|
|
|
|
|
|
|
|
return client, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return client, nil |
|
|
return client, nil |
|
|