Class: Feed
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Feed
- Includes:
- HTTParty
- Defined in:
- app/models/feed.rb
Overview
Schema Information
Table name: feeds
id :integer(4) not null, primary key
uri :string(2083)
display_uri :string(2083)
title :string(1000)
short_title :string(100)
description :text
tag_filter :string(1000)
top_tags :text
priority :integer(4) default(10)
status :integer(4) default(1)
last_requested_at :datetime default(Wed Jan 01 00:00:00 UTC 1969)
last_harvested_at :datetime default(Wed Jan 01 00:00:00 UTC 1969)
harvest_interval :integer(4) default(86400)
failed_requests :integer(4) default(0)
error_message :text
service_id :integer(4) default(0)
login :string(255)
password :string(255)
created_at :datetime
updated_at :datetime
entries_changed_at :datetime
harvested_from_display_uri :string(2083)
harvested_from_title :string(1000)
harvested_from_short_title :string(100)
entries_count :integer(4)
default_language_id :integer(4) default(0)
default_grain_size :string(255) default("unknown")
contributor_id :integer(4)
etag :string(255)
Class Method Summary collapse
-
.discover_feeds(uri) ⇒ Object
Looks for feeds from a given url.
-
.find_or_create(uri, title, username, password, service_id, contributor_id, display_uri = nil) ⇒ Object
Finds or creates a feed based on the url.
-
.from_feedzirra(feed) ⇒ Object
Turns a feed from feedzirra into a muck feed.
-
.gather_information(uri) ⇒ Object
Gathers all available feed uris from the given uri and parses them into feed objects.
Instance Method Summary collapse
-
#banned? ⇒ Boolean
named_scope :ready_to_harvest, lambda { |*args| { :conditions => [ “feeds.last_harvested_at < ?”, args.first || 1.day.ago.end_of_day ] } }.
-
#delete_if_unused(user) ⇒ Object
This will delete a feed if there are no references to it.
-
#feed_url ⇒ Object
provided to make feed quack like a feedzirra feed.
-
#global? ⇒ Boolean
feeds that are not attached to anything become global to the site.
- #harvest ⇒ Object
-
#harvest_interval_hours ⇒ Object
harvest_interval is stored in seconds default is 86400 which is one day.
-
#harvest_interval_hours=(interval) ⇒ Object
Converts hours into seconds for harvest_interval.
-
#in_use? ⇒ Boolean
Checks to see if there is a reference to the feed in any of the relation tables.
- #inform_admin ⇒ Object
-
#last_modified ⇒ Object
provided to make feed quack like a feedzirra feed.
- #pending? ⇒ Boolean
-
#url ⇒ Object
provided to make feed quack like a feedzirra feed.
Class Method Details
.discover_feeds(uri) ⇒ Object
Looks for feeds from a given url
161 162 163 |
# File 'app/models/feed.rb', line 161 def self.discover_feeds(uri) Feedbag.find(uri) end |
.find_or_create(uri, title, username, password, service_id, contributor_id, display_uri = nil) ⇒ Object
Finds or creates a feed based on the url. Any give feed uri should only exist once in the system
166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'app/models/feed.rb', line 166 def self.find_or_create(uri, title, username, password, service_id, contributor_id, display_uri = nil) Feed.find_by_uri(uri) || Feed.create(:uri => uri, :harvest_interval => '01:00:00', :last_harvested_at => Time.at(0), :title => title, :login => username, :password => password, :service_id => service_id, :contributor_id => contributor_id, :display_uri => display_uri) end |
.from_feedzirra(feed) ⇒ Object
Turns a feed from feedzirra into a muck feed
153 154 155 156 157 158 |
# File 'app/models/feed.rb', line 153 def self.from_feedzirra(feed) Feed.new(:short_title => feed.title, :title => feed.title, :display_uri => feed.url, :uri => feed.feed_url) end |
.gather_information(uri) ⇒ Object
Gathers all available feed uris from the given uri and parses them into feed objects
143 144 145 146 147 148 149 150 |
# File 'app/models/feed.rb', line 143 def self.gather_information(uri) feeds = [] @available_feeds = discover_feeds(uri) @available_feeds.each do |feed| feeds << from_feedzirra(Feedzirra::Feed.fetch_and_parse(feed.url)) end feeds end |
Instance Method Details
#banned? ⇒ Boolean
named_scope :ready_to_harvest, lambda { |*args| { :conditions => [ “feeds.last_harvested_at < ?”, args.first || 1.day.ago.end_of_day ] } }
65 66 67 |
# File 'app/models/feed.rb', line 65 def banned? self.status == MuckRaker::Status::BANNED end |
#delete_if_unused(user) ⇒ Object
This will delete a feed if there are no references to it
133 134 135 136 137 138 139 |
# File 'app/models/feed.rb', line 133 def delete_if_unused(user) if user.id == contributor_id && !in_use? self.destroy else false end end |
#feed_url ⇒ Object
provided to make feed quack like a feedzirra feed
107 108 109 |
# File 'app/models/feed.rb', line 107 def feed_url uri end |
#global? ⇒ Boolean
feeds that are not attached to anything become global to the site
117 118 119 |
# File 'app/models/feed.rb', line 117 def global? self.feed_parents.empty? && self.identity_feeds.empty? && self.aggregations.empty? end |
#harvest ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'app/models/feed.rb', line 90 def harvest # check to see if the feed has changed feed = Feedzirra::Feed.fetch_and_parse(self.uri) feed.entries # updated_feed = Feedzirra::Feed.update(self) # if updated_feed.updated? # updated_feed.new_entries # get new entries # updated_feed.sanitize_entries! # clean up # end end |
#harvest_interval_hours ⇒ Object
harvest_interval is stored in seconds default is 86400 which is one day
81 82 83 |
# File 'app/models/feed.rb', line 81 def harvest_interval_hours self.harvest_interval/3600 end |
#harvest_interval_hours=(interval) ⇒ Object
Converts hours into seconds for harvest_interval
86 87 88 |
# File 'app/models/feed.rb', line 86 def harvest_interval_hours=(interval) self.harvest_interval = interval * 3600 end |
#in_use? ⇒ Boolean
Checks to see if there is a reference to the feed in any of the relation tables.
122 123 124 125 126 127 128 129 130 |
# File 'app/models/feed.rb', line 122 def in_use? feed = FeedParent.find_by_feed_id(self.id) return true if feed feed = IdentityFeed.find_by_feed_id(self.id) return true if feed feed = AggregationFeed.find_by_feed_id(self.id) return true if feed false end |
#inform_admin ⇒ Object
73 74 75 76 77 |
# File 'app/models/feed.rb', line 73 def inform_admin if GlobalConfig.inform_admin_of_global_feed && global? RakerMailer.deliver_notification_feed_added(self) # Global feed. Email the admin to let them know a feed has been added end end |
#last_modified ⇒ Object
provided to make feed quack like a feedzirra feed
112 113 114 |
# File 'app/models/feed.rb', line 112 def last_modified entries_changed_at end |
#pending? ⇒ Boolean
69 70 71 |
# File 'app/models/feed.rb', line 69 def pending? self.status == MuckRaker::Status::PENDING end |
#url ⇒ Object
provided to make feed quack like a feedzirra feed
102 103 104 |
# File 'app/models/feed.rb', line 102 def url display_uri end |