class Podrick::Podcast

Attributes

etag[R]

Public Class Methods

from_url(url, etag = nil) click to toggle source
# 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) click to toggle source
# File lib/podrick/podcast.rb, line 13
def self.from_xml xml_string, etag = nil
  new(xml_string, etag)
end
new(xml_string, etag = nil) click to toggle source
# File lib/podrick/podcast.rb, line 8
def initialize xml_string, etag = nil
  @xml = xml_string
  @etag = etag
end

Public Instance Methods

episodes() click to toggle source
# File lib/podrick/podcast.rb, line 81
def episodes
  @episodes ||= xml_doc.xpath('//item').map { |item_xml| Episode.new(item_xml) }
end
itunes() click to toggle source
# 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) click to toggle source
# File lib/podrick/podcast.rb, line 69
def xml_content_at string
  if node = xml_metadata.at_xpath(string)
    node.content
  end
end
xml_doc() click to toggle source
# File lib/podrick/podcast.rb, line 33
def xml_doc
  @xml_doc ||= Nokogiri::XML(@xml)
end
xml_metadata() click to toggle source
# File lib/podrick/podcast.rb, line 37
def xml_metadata
  @xml_metadata ||= xml_doc.xpath('/rss/channel/*[not(self::item)]')
end
xml_node_at(string) click to toggle source
# File lib/podrick/podcast.rb, line 75
def xml_node_at string
  if node = xml_metadata.at_xpath(string)
    node
  end
end