diff --git a/client.go b/client.go index d3653de..80a289e 100644 --- a/client.go +++ b/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 +} diff --git a/send_all_page_response.go b/send_all_page_response.go index 2824121..02ab430 100644 --- a/send_all_page_response.go +++ b/send_all_page_response.go @@ -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"` diff --git a/send_post_with_comments_response.go b/send_post_with_comments_response.go new file mode 100644 index 0000000..068b534 --- /dev/null +++ b/send_post_with_comments_response.go @@ -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"` +}