-
Notifications
You must be signed in to change notification settings - Fork 0
/
parsing.go
36 lines (29 loc) · 1011 Bytes
/
parsing.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
package newznab
import (
"encoding/xml"
"net/url"
"github.com/smquartz/errors"
)
// contains functions relating to the processing of newznab responses
// entriesFromURL extracts newznab Entries from the response body returned
// from the given URL. entriesFromURL performs a GET request against the
// given URL, and parses the response body, ultimately returning Entries.
func (c *Client) entriesFromURL(u *url.URL) (entries Entries, err error) {
rsp, err := c.getURLResponseBody(u)
if err != nil {
return nil, errors.Wrap(err, 1)
}
feed := new(rawEntries)
err = xml.Unmarshal(rsp, feed)
if err != nil {
return nil, errors.Wrapf(err, "error unmarshalling XML response into rawEntries", 1)
}
if feed.ErrorCode != 0 {
return nil, errors.Errorf("response body contained error %d: %s", feed.ErrorCode, feed.ErrorDesc)
}
entries, err = rawEntriesToEntries(c, *feed)
if err != nil {
return nil, errors.Wrapf(err, "error converting rawEntries into Entries", 1)
}
return entries, nil
}