Class: Skriptorium::RSS::Source
Instance Attribute Summary
Attributes inherited from BaseSource
#config, #limit
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BaseSource
#apply_filter, #fetch_latest
Constructor Details
#initialize(config) ⇒ Source
Returns a new instance of Source.
7
8
9
10
|
# File 'lib/skriptorium/rss/source.rb', line 7
def initialize(config)
super
@url = config['url']
end
|
Class Method Details
.to_article(item) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/skriptorium/rss/source.rb', line 26
def self.to_article(item)
content = if item.respond_to?(:content_encoded) && item.content_encoded
item.content_encoded
elsif item.respond_to?(:description) && item.description
item.description
else
''
end
Article.new(
id: item.guid&.content || item.link,
title: item.title,
content: content,
tags: [],
canonical_url: item.link,
published_at: Article.parse_date(item.pubDate || item.dc_date),
cover_image: nil,
slug: nil,
markdown: false,
html: true
)
end
|
Instance Method Details
#fetch ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/skriptorium/rss/source.rb', line 12
def fetch
client = Faraday.new
response = client.get(@url)
raise "RSS fetch error: #{response.status} - #{response.body}" unless response.success?
feed = ::RSS::Parser.parse(response.body)
Enumerator.new do |y|
feed.items.each do |item|
y << self.class.to_article(item)
end
end
end
|