Skip to content

Commit

Permalink
Rename RSS parser getters
Browse files Browse the repository at this point in the history
  • Loading branch information
fguillot committed Apr 10, 2018
1 parent f760936 commit e2d02ba
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions reader/rss/rss.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,36 @@ type rssCommentLink struct {
Data string `xml:",chardata"`
}

type rssAuthor struct {
XMLName xml.Name
Data string `xml:",chardata"`
Name string `xml:"name"`
Inner string `xml:",innerxml"`
}

type rssEnclosure struct {
URL string `xml:"url,attr"`
Type string `xml:"type,attr"`
Length string `xml:"length,attr"`
}

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"`
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"`
Enclosures []rssEnclosure `xml:"enclosure"`
EnclosureLinks []rssEnclosure `xml:"enclosure"`
OrigEnclosureLink string `xml:"http://rssnamespace.org/feedburner/ext/1.0 origEnclosureLink"`
}

type rssAuthor struct {
XMLName xml.Name
Data string `xml:",chardata"`
Name string `xml:"name"`
Inner string `xml:",innerxml"`
}

type rssEnclosure struct {
URL string `xml:"url,attr"`
Type string `xml:"type,attr"`
Length string `xml:"length,attr"`
}

func (r *rssFeed) GetSiteURL() string {
func (r *rssFeed) SiteURL() string {
for _, element := range r.Links {
if element.XMLName.Space == "" {
return strings.TrimSpace(element.Data)
Expand All @@ -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)
Expand All @@ -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 == "" {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
}
Expand All @@ -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
}
Expand All @@ -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

Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit e2d02ba

Please sign in to comment.