Class: Podrick::Podcast
- Inherits:
-
Object
- Object
- Podrick::Podcast
- Defined in:
- lib/podrick/podcast.rb
Instance Attribute Summary collapse
-
#etag ⇒ Object
readonly
Returns the value of attribute etag.
Class Method Summary collapse
Instance Method Summary collapse
- #episodes ⇒ Object
-
#initialize(xml_string, etag = nil) ⇒ Podcast
constructor
A new instance of Podcast.
- #itunes ⇒ Object
- #xml_content_at(string) ⇒ Object
- #xml_doc ⇒ Object
- #xml_metadata ⇒ Object
- #xml_node_at(string) ⇒ Object
Constructor Details
#initialize(xml_string, etag = nil) ⇒ Podcast
Returns a new instance of Podcast.
8 9 10 11 |
# File 'lib/podrick/podcast.rb', line 8 def initialize xml_string, etag = nil @xml = xml_string @etag = etag end |
Instance Attribute Details
#etag ⇒ Object (readonly)
Returns the value of attribute etag.
6 7 8 |
# File 'lib/podrick/podcast.rb', line 6 def etag @etag end |
Class Method Details
.from_url(url, etag = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/podrick/podcast.rb', line 17 def self.from_url url, etag = nil headers = {} if etag headers['If-None-Match'] = etag end response = Faraday.get(url, {}, headers) if response.status == 304 nil else new(response.body, response.headers['ETag']) end end |
.from_xml(xml_string, etag = nil) ⇒ Object
13 14 15 |
# File 'lib/podrick/podcast.rb', line 13 def self.from_xml xml_string, etag = nil new(xml_string, etag) end |
Instance Method Details
#episodes ⇒ Object
81 82 83 |
# File 'lib/podrick/podcast.rb', line 81 def episodes @episodes ||= xml_doc.xpath('//item').map { |item_xml| Episode.new(item_xml) } end |
#itunes ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/podrick/podcast.rb', line 49 def itunes @itunes ||= begin image = Struct.new(:href) owner = Struct.new(:name, :email) itunes = Struct.new(:subtitle, :author, :summary, :keywords, :explicit, :category, :subcategories, :image, :owner) itunes.new( xml_content_at("//itunes:subtitle"), xml_content_at("//itunes:author"), xml_content_at("//itunes:summary"), xml_content_at("//itunes:keywords"), xml_content_at("//itunes:explicit"), xml_node_at("//itunes:category")["text"], xml_doc.xpath("//itunes:category//itunes:category").map { |category| category["text"] }, image.new(xml_node_at("//itunes:image")["href"]), owner.new(xml_content_at("//itunes:owner//itunes:name"), xml_content_at("//itunes:owner//itunes:email")) ) end end |
#xml_content_at(string) ⇒ Object
69 70 71 72 73 |
# File 'lib/podrick/podcast.rb', line 69 def xml_content_at string if node = .at_xpath(string) node.content end end |
#xml_doc ⇒ Object
33 34 35 |
# File 'lib/podrick/podcast.rb', line 33 def xml_doc @xml_doc ||= Nokogiri::XML(@xml) end |
#xml_metadata ⇒ Object
37 38 39 |
# File 'lib/podrick/podcast.rb', line 37 def @xml_metadata ||= xml_doc.xpath('/rss/channel/*[not(self::item)]') end |
#xml_node_at(string) ⇒ Object
75 76 77 78 79 |
# File 'lib/podrick/podcast.rb', line 75 def xml_node_at string if node = .at_xpath(string) node end end |