-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsharecast.rb
47 lines (38 loc) · 938 Bytes
/
sharecast.rb
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
require 'rexml/document'
require 'faraday_middleware'
module Sharecast
def self.get_image(url)
raw = self.get(url)
doc = REXML::Document.new(raw)
doc.elements.each("rss/channel/itunes:image") do |item|
puts item.attributes
return item.attributes["href"]
end
rescue REXML::ParseException
return nil
end
def self.parse_opml(raw_string)
doc = REXML::Document.new(raw_string)
podcasts = []
doc.elements.each("opml/body/outline/outline") do |podcast|
attrs = podcast.attributes
url = attrs["xmlUrl"]
image = self.get_image(url)
data = {
title: attrs["text"],
url: url,
image_url: image,
}
podcasts << data
end
return podcasts
end
private
def self.get(url)
@adapter ||= Faraday.new { |b|
b.use FaradayMiddleware::FollowRedirects
b.adapter :net_http
}
@adapter.get(url).body
end
end