From e2d02bac5a407d9de6bac94b034f1f6b7ebdddc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Mon, 9 Apr 2018 20:38:12 -0700 Subject: [PATCH] Rename RSS parser getters --- reader/rss/rss.go | 72 +++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/reader/rss/rss.go b/reader/rss/rss.go index 92335af6..5ccbb0ee 100644 --- a/reader/rss/rss.go +++ b/reader/rss/rss.go @@ -43,22 +43,6 @@ type rssCommentLink struct { Data string `xml:",chardata"` } -type rssItem struct { - GUID string `xml:"guid"` - Title string `xml:"title"` - Links []rssLink `xml:"link"` - OriginalLink string `xml:"http://rssnamespace.org/feedburner/ext/1.0 origLink"` - CommentLinks []rssCommentLink `xml:"comments"` - Description string `xml:"description"` - Content string `xml:"http://purl.org/rss/1.0/modules/content/ encoded"` - PubDate string `xml:"pubDate"` - Date string `xml:"http://purl.org/dc/elements/1.1/ date"` - Authors []rssAuthor `xml:"author"` - Creator string `xml:"http://purl.org/dc/elements/1.1/ creator"` - Enclosures []rssEnclosure `xml:"enclosure"` - OrigEnclosureLink string `xml:"http://rssnamespace.org/feedburner/ext/1.0 origEnclosureLink"` -} - type rssAuthor struct { XMLName xml.Name Data string `xml:",chardata"` @@ -72,7 +56,23 @@ type rssEnclosure struct { Length string `xml:"length,attr"` } -func (r *rssFeed) GetSiteURL() string { +type rssItem struct { + GUID string `xml:"guid"` + Title string `xml:"title"` + Links []rssLink `xml:"link"` + OriginalLink string `xml:"http://rssnamespace.org/feedburner/ext/1.0 origLink"` + CommentLinks []rssCommentLink `xml:"comments"` + Description string `xml:"description"` + EncodedContent string `xml:"http://purl.org/rss/1.0/modules/content/ encoded"` + PubDate string `xml:"pubDate"` + Date string `xml:"http://purl.org/dc/elements/1.1/ date"` + Authors []rssAuthor `xml:"author"` + Creator string `xml:"http://purl.org/dc/elements/1.1/ creator"` + EnclosureLinks []rssEnclosure `xml:"enclosure"` + OrigEnclosureLink string `xml:"http://rssnamespace.org/feedburner/ext/1.0 origEnclosureLink"` +} + +func (r *rssFeed) SiteURL() string { for _, element := range r.Links { if element.XMLName.Space == "" { return strings.TrimSpace(element.Data) @@ -82,7 +82,7 @@ func (r *rssFeed) GetSiteURL() string { return "" } -func (r *rssFeed) GetFeedURL() string { +func (r *rssFeed) FeedURL() string { for _, element := range r.Links { if element.XMLName.Space == "http://www.w3.org/2005/Atom" { return strings.TrimSpace(element.Href) @@ -94,8 +94,8 @@ func (r *rssFeed) GetFeedURL() string { func (r *rssFeed) Transform() *model.Feed { feed := new(model.Feed) - feed.SiteURL = r.GetSiteURL() - feed.FeedURL = r.GetFeedURL() + feed.SiteURL = r.SiteURL() + feed.FeedURL = r.FeedURL() feed.Title = strings.TrimSpace(r.Title) if feed.Title == "" { @@ -129,7 +129,7 @@ func (r *rssFeed) Transform() *model.Feed { return feed } -func (r *rssItem) GetDate() time.Time { +func (r *rssItem) PublishedDate() time.Time { value := r.PubDate if r.Date != "" { value = r.Date @@ -148,7 +148,7 @@ func (r *rssItem) GetDate() time.Time { return time.Now() } -func (r *rssItem) GetAuthor() string { +func (r *rssItem) Author() string { for _, element := range r.Authors { if element.Name != "" { return element.Name @@ -162,8 +162,8 @@ func (r *rssItem) GetAuthor() string { return r.Creator } -func (r *rssItem) GetHash() string { - for _, value := range []string{r.GUID, r.GetURL()} { +func (r *rssItem) Hash() string { + for _, value := range []string{r.GUID, r.URL()} { if value != "" { return crypto.Hash(value) } @@ -172,15 +172,15 @@ func (r *rssItem) GetHash() string { return "" } -func (r *rssItem) GetContent() string { - if r.Content != "" { - return r.Content +func (r *rssItem) Content() string { + if r.EncodedContent != "" { + return r.EncodedContent } return r.Description } -func (r *rssItem) GetURL() string { +func (r *rssItem) URL() string { if r.OriginalLink != "" { return r.OriginalLink } @@ -198,10 +198,10 @@ func (r *rssItem) GetURL() string { return "" } -func (r *rssItem) GetEnclosures() model.EnclosureList { +func (r *rssItem) Enclosures() model.EnclosureList { enclosures := make(model.EnclosureList, 0) - for _, enclosure := range r.Enclosures { + for _, enclosure := range r.EnclosureLinks { length, _ := strconv.ParseInt(enclosure.Length, 10, 0) enclosureURL := enclosure.URL @@ -234,14 +234,14 @@ func (r *rssItem) CommentsURL() string { func (r *rssItem) Transform() *model.Entry { entry := new(model.Entry) - entry.URL = r.GetURL() + entry.URL = r.URL() entry.CommentsURL = r.CommentsURL() - entry.Date = r.GetDate() - entry.Author = r.GetAuthor() - entry.Hash = r.GetHash() - entry.Content = r.GetContent() + entry.Date = r.PublishedDate() + entry.Author = r.Author() + entry.Hash = r.Hash() + entry.Content = r.Content() entry.Title = strings.TrimSpace(r.Title) - entry.Enclosures = r.GetEnclosures() + entry.Enclosures = r.Enclosures() return entry }