Sha256: d5bcd0a01b7b5fb58d67f1a528fb62aadec5557d592737edf725a42d1742f70b
Contents?: true
Size: 1000 Bytes
Versions: 2
Compression:
Stored size: 1000 Bytes
Contents
module Imasquerade class Extractor public def Extractor.parse_itunes_uri(uri='') id = Extractor.extract_itunes_id(uri) return Extractor.fetch_and_parse_feed_from_apple(id) end private def Extractor.extract_itunes_id(url="") uri = URI.parse(url) uri_path = uri.path.match("id[0-9]+") unless uri.path.nil? uri_query = uri.query.match("id=[0-9]+") unless uri.query.nil? id = uri_path.to_s.delete!("id") || uri_query.to_s.delete!("id=") return id end def Extractor.fetch_and_parse_feed_from_apple(id) uri = "http://itunes.apple.com/podcast/id#{id}" response = Curl::Easy.perform(uri) do |curl| curl.headers["User-Agent"] = 'iTunes/10.1.1' end reader = Nokogiri::XML(response.body_str) array_of_feeds = reader.xpath('//xmlns:key[text()="feedURL"]/following-sibling::xmlns:string[1]/text()') return array_of_feeds[0].to_s end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
imasquerade-0.1.1 | lib/imasquerade/extractor.rb |
imasquerade-0.1.0 | lib/imasquerade/extractor.rb |