-
Notifications
You must be signed in to change notification settings - Fork 0
/
parsing_feed.go
87 lines (77 loc) · 2.12 KB
/
parsing_feed.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package rssapi
import (
"context"
"github.com/pkg/errors"
"strconv"
)
type ParsingFeedRequest struct {
URL string
Limit *int
Search *string
Sort *string
}
type ParsingFeedResponse struct {
OK bool `json:"ok"`
Result struct {
// NOTE: The type is not specified in the documentation.
// Settings []any `json:"settings"`
Info struct {
Title string `json:"title"`
Description string `json:"description"`
Homepage string `json:"homepage"`
FeedURL string `json:"feed_url"`
AdditionalDetails struct {
Language string `json:"language"`
// NOTE: The type is not specified in the documentation.
// Categories []any `json:"categories"`
// NOTE: The type is not specified in the documentation.
// Authors []any `json:"authors"`
// NOTE: The type is not specified in the documentation.
Copyright *string `json:"copyright"`
} `json:"additional_details"`
} `json:"info"`
Entries []struct {
Title string `json:"title"`
Link string `json:"link"`
Description string `json:"description"`
GUID string `json:"guid"`
Time string `json:"time"`
Timestamp int `json:"timestamp"`
} `json:"entries"`
} `json:"result"`
}
func (c *Client) ParsingFeed(
ctx context.Context,
req *ParsingFeedRequest,
) (*ParsingFeedResponse, error) {
if req == nil {
return nil, errors.New("nil request")
}
q := map[string]string{
"url": req.URL,
}
if req.Limit != nil {
q["limit"] = strconv.Itoa(*req.Limit)
}
if req.Search != nil {
q["search"] = *req.Search
}
if req.Sort != nil {
q["sort"] = *req.Sort
}
spath := "/v1/header/get"
httpReq, err := c.newGETRequest(ctx, spath, q)
if err != nil {
return nil, errors.Wrap(err, "failed to create GET request")
}
res, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, errors.Wrap(err, "failed to Do http request")
}
// TODO: Check status here...
var parsingFeedResponse ParsingFeedResponse
if err := decodeBody(res, &parsingFeedResponse); err != nil {
return nil, errors.Wrap(err, "failed to decode response body")
}
return &parsingFeedResponse, nil
}