mirror of
https://bitbucket.org/skobkin/point-tools-go.git
synced 2024-11-21 20:36:04 +00:00
SendPostWithComments() method implemented. Some refactoring done.
This commit is contained in:
parent
9ba6534965
commit
bb97206d98
48
client.go
48
client.go
|
@ -11,10 +11,16 @@ import (
|
|||
"net/url"
|
||||
)
|
||||
|
||||
const (
|
||||
STATUS_SUCCESS string = "success"
|
||||
STATUS_FAILURE string = "fail"
|
||||
)
|
||||
|
||||
// Package errors
|
||||
var (
|
||||
ErrHttpRequest = errors.New("point-api: HTTP request error")
|
||||
ErrJsonDeserialization = errors.New("point-api: JSON deserialization error")
|
||||
ErrJsonSerialization = errors.New("point-api: JSON serialization error")
|
||||
)
|
||||
|
||||
type PointToolsClient struct {
|
||||
|
@ -37,7 +43,18 @@ func GetPageJSON(page point.Page) (string, error) {
|
|||
|
||||
if err != nil {
|
||||
log.Println("point.Page serialize error:", err)
|
||||
return "", err
|
||||
return "", ErrJsonSerialization
|
||||
}
|
||||
|
||||
return string(b[:]), nil
|
||||
}
|
||||
|
||||
func GetPostWithCommentsJSON(post point.PostShowResponse) (string, error) {
|
||||
b, err := json.Marshal(post)
|
||||
|
||||
if err != nil {
|
||||
log.Println("point.Page serialize error:", err)
|
||||
return "", ErrJsonSerialization
|
||||
}
|
||||
|
||||
return string(b[:]), nil
|
||||
|
@ -71,3 +88,32 @@ func (c *PointToolsClient) SendAllPage(page point.Page) (SendAllPageResponse, er
|
|||
|
||||
return response, nil
|
||||
}
|
||||
|
||||
// SendPostWithComments sends post with comments to Point Tools crawler API gate for processing
|
||||
func (c *PointToolsClient) SendPostWithComments(post point.PostShowResponse) (SendPostWithCommentsResponse, error) {
|
||||
var response SendPostWithCommentsResponse
|
||||
|
||||
jsonStr, err := GetPostWithCommentsJSON(post)
|
||||
|
||||
if err != nil {
|
||||
return response, err
|
||||
}
|
||||
|
||||
data := url.Values{}
|
||||
data.Set("token", c.token)
|
||||
data.Add("json", jsonStr)
|
||||
|
||||
body, reqErr := c.client.MakePostRequest(c.apiUrl+"all/page", data, nil)
|
||||
|
||||
if reqErr != nil {
|
||||
return response, ErrHttpRequest
|
||||
}
|
||||
|
||||
jsonErr := json.Unmarshal(body, &response)
|
||||
|
||||
if jsonErr != nil {
|
||||
return response, ErrJsonDeserialization
|
||||
}
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
package point_tools
|
||||
|
||||
const (
|
||||
STATUS_SUCCESS string = "success"
|
||||
STATUS_FAILURE string = "fail"
|
||||
)
|
||||
|
||||
type SendAllPageResponse struct {
|
||||
Status string `json:"status"`
|
||||
Data SendAllPageResponseData `json:"data"`
|
||||
|
|
12
send_post_with_comments_response.go
Normal file
12
send_post_with_comments_response.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package point_tools
|
||||
|
||||
type SendPostWithCommentsResponse struct {
|
||||
Status string `json:"status"`
|
||||
Data SendPostWithCommentsResponseData `json:"data"`
|
||||
Error ApiError `json:"error"`
|
||||
}
|
||||
|
||||
type SendPostWithCommentsResponseData struct {
|
||||
Continue bool `json:"continue"`
|
||||
Next string `json:"next"`
|
||||
}
|
Loading…
Reference in a new issue