Class: Ingest::Feed
- Inherits:
-
Object
- Object
- Ingest::Feed
- Defined in:
- lib/ingest/feed.rb
Instance Attribute Summary collapse
-
#copyright ⇒ Object
Returns the value of attribute copyright.
-
#description ⇒ Object
Returns the value of attribute description.
-
#etag ⇒ Object
Returns the value of attribute etag.
-
#items ⇒ Object
Returns the value of attribute items.
-
#itunes_author ⇒ Object
Returns the value of attribute itunes_author.
-
#itunes_block ⇒ Object
Returns the value of attribute itunes_block.
-
#itunes_categories ⇒ Object
Returns the value of attribute itunes_categories.
-
#itunes_email ⇒ Object
Returns the value of attribute itunes_email.
-
#itunes_explicit ⇒ Object
Returns the value of attribute itunes_explicit.
-
#itunes_image ⇒ Object
Returns the value of attribute itunes_image.
-
#itunes_keywords ⇒ Object
Returns the value of attribute itunes_keywords.
-
#itunes_name ⇒ Object
Returns the value of attribute itunes_name.
-
#itunes_new_feed_url ⇒ Object
Returns the value of attribute itunes_new_feed_url.
-
#itunes_subtitle ⇒ Object
Returns the value of attribute itunes_subtitle.
-
#itunes_summary ⇒ Object
Returns the value of attribute itunes_summary.
-
#language ⇒ Object
Returns the value of attribute language.
-
#last_modified ⇒ Object
Returns the value of attribute last_modified.
-
#link ⇒ Object
Returns the value of attribute link.
-
#managing_editor ⇒ Object
Returns the value of attribute managing_editor.
-
#published_at ⇒ Object
Returns the value of attribute published_at.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
-
.fetch_and_parse(url) ⇒ Object
Fetches and parses an iTunes RSS feed based on the given URL.
Instance Attribute Details
#copyright ⇒ Object
Returns the value of attribute copyright.
3 4 5 |
# File 'lib/ingest/feed.rb', line 3 def copyright @copyright end |
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/ingest/feed.rb', line 3 def description @description end |
#etag ⇒ Object
Returns the value of attribute etag.
3 4 5 |
# File 'lib/ingest/feed.rb', line 3 def etag @etag end |
#items ⇒ Object
Returns the value of attribute items.
3 4 5 |
# File 'lib/ingest/feed.rb', line 3 def items @items end |
#itunes_author ⇒ Object
Returns the value of attribute itunes_author.
3 4 5 |
# File 'lib/ingest/feed.rb', line 3 def end |
#itunes_block ⇒ Object
Returns the value of attribute itunes_block.
3 4 5 |
# File 'lib/ingest/feed.rb', line 3 def itunes_block @itunes_block end |
#itunes_categories ⇒ Object
Returns the value of attribute itunes_categories.
3 4 5 |
# File 'lib/ingest/feed.rb', line 3 def itunes_categories @itunes_categories end |
#itunes_email ⇒ Object
Returns the value of attribute itunes_email.
3 4 5 |
# File 'lib/ingest/feed.rb', line 3 def itunes_email @itunes_email end |
#itunes_explicit ⇒ Object
Returns the value of attribute itunes_explicit.
3 4 5 |
# File 'lib/ingest/feed.rb', line 3 def itunes_explicit @itunes_explicit end |
#itunes_image ⇒ Object
Returns the value of attribute itunes_image.
3 4 5 |
# File 'lib/ingest/feed.rb', line 3 def itunes_image @itunes_image end |
#itunes_keywords ⇒ Object
Returns the value of attribute itunes_keywords.
3 4 5 |
# File 'lib/ingest/feed.rb', line 3 def itunes_keywords @itunes_keywords end |
#itunes_name ⇒ Object
Returns the value of attribute itunes_name.
3 4 5 |
# File 'lib/ingest/feed.rb', line 3 def itunes_name @itunes_name end |
#itunes_new_feed_url ⇒ Object
Returns the value of attribute itunes_new_feed_url.
3 4 5 |
# File 'lib/ingest/feed.rb', line 3 def itunes_new_feed_url @itunes_new_feed_url end |
#itunes_subtitle ⇒ Object
Returns the value of attribute itunes_subtitle.
3 4 5 |
# File 'lib/ingest/feed.rb', line 3 def itunes_subtitle @itunes_subtitle end |
#itunes_summary ⇒ Object
Returns the value of attribute itunes_summary.
3 4 5 |
# File 'lib/ingest/feed.rb', line 3 def itunes_summary @itunes_summary end |
#language ⇒ Object
Returns the value of attribute language.
3 4 5 |
# File 'lib/ingest/feed.rb', line 3 def language @language end |
#last_modified ⇒ Object
Returns the value of attribute last_modified.
3 4 5 |
# File 'lib/ingest/feed.rb', line 3 def last_modified @last_modified end |
#link ⇒ Object
Returns the value of attribute link.
3 4 5 |
# File 'lib/ingest/feed.rb', line 3 def link @link end |
#managing_editor ⇒ Object
Returns the value of attribute managing_editor.
3 4 5 |
# File 'lib/ingest/feed.rb', line 3 def managing_editor @managing_editor end |
#published_at ⇒ Object
Returns the value of attribute published_at.
3 4 5 |
# File 'lib/ingest/feed.rb', line 3 def published_at @published_at end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/ingest/feed.rb', line 3 def title @title end |
Class Method Details
.fetch_and_parse(url) ⇒ Object
Fetches and parses an iTunes RSS feed based on the given URL. Returns a Feed
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/ingest/feed.rb', line 12 def self.fetch_and_parse(url) # Setup the content and etag variables content, etag = '' # Open the given URL and read the content and etag open(url, allow_redirections: :safe) do |source| content = source.read etag = source.['etag'] end # Parse the feed data rss = RSS::Parser.parse(content, false, false) # Create a new Feed feed = Ingest::Feed.new # Assign values from the parsed RSS feed.description = rss.channel.description feed.etag = etag feed. = rss.channel. feed.itunes_block = rss.channel.itunes_block feed.itunes_explicit = rss.channel.itunes_explicit feed.itunes_image = rss.channel.itunes_image.href if rss.channel.itunes_keywords.present? feed.itunes_keywords = rss.channel.itunes_keywords.join(',') end feed.itunes_new_feed_url = rss.channel.itunes_new_feed_url if rss.channel.itunes_owner.present? feed.itunes_name = rss.channel.itunes_owner.itunes_name feed.itunes_email = rss.channel.itunes_owner.itunes_email end feed.itunes_subtitle = rss.channel.itunes_subtitle feed.itunes_summary = rss.channel.itunes_summary feed.language = rss.channel.language feed.link = rss.channel.link feed.managing_editor = rss.channel.managingEditor feed.published_at = rss.channel.pubDate feed.title = rss.channel.title # iTunes categories are special snowflakes feed.itunes_categories = {} rss.channel.itunes_categories.each do |category| # Set the sub-category to be nil sub_category = nil unless category.itunes_category.nil? # Set a sub_category sub_category = category.itunes_category.text end # Add a new element to the hash and assign its sub-category feed.itunes_categories[category.text] = sub_category end # Setup the Feed's items array feed.items = [] # Loop through the parsed RSS feed's items rss.items.each do |item| # Create a new FeedItem for each item from the RSS feed feed_item = Ingest::FeedItem.new # Assign values based on the RSS feed item feed_item. = item. feed_item.content = item.content_encoded feed_item.description = item.description if item.enclosure.present? feed_item.enclosure_length = item.enclosure.length feed_item.enclosure_type = item.enclosure.type feed_item.enclosure_url = item.enclosure.url end if item.guid.present? feed_item.guid = item.guid.content else feed_item.guid = "" end feed_item. = item. feed_item.itunes_block = item.itunes_block feed_item.itunes_explicit = item.itunes_explicit feed_item.itunes_subtitle = item.itunes_subtitle feed_item.itunes_summary = item.itunes_summary feed_item.link = item.link feed_item.published_at = item.pubDate feed_item.title = item.title if item.itunes_duration.present? feed_item.itunes_duration = item.itunes_duration.content.to_s end if item.itunes_keywords.present? feed_item.itunes_keywords = item.itunes_keywords.join(',') end # Put the FeedItem into the Feed's items array feed.items << feed_item end # Return the Feed return feed end |