muck-services 3.2.2 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.2.2
1
+ 3.3.0
@@ -37,7 +37,7 @@ class Muck::IdentityFeedsController < ApplicationController
37
37
  else
38
38
  uri = nil
39
39
  end
40
-
40
+
41
41
  if uri
42
42
  @feed = Feed.new(:uri => uri, :login => params[:username])
43
43
  feeds = Service.create_tag_feeds_for_service(@service, uri, params[:username], params[:password], current_user.id)
@@ -38,8 +38,8 @@ class Feed < ActiveRecord::Base
38
38
  include HTTParty
39
39
  format :xml
40
40
 
41
- validates_presence_of :uri
42
- validates_uniqueness_of :uri
41
+ validates_presence_of :uri, :unless => :is_website?
42
+ validates_uniqueness_of :uri, :scope => [:contributor_id]
43
43
 
44
44
  has_many :feed_parents
45
45
  has_many :identity_feeds
@@ -59,6 +59,11 @@ class Feed < ActiveRecord::Base
59
59
  attr_protected :status, :last_requested_at, :last_harvested_at, :harvest_interval, :failed_requests,
60
60
  :created_at, :updated_at, :entries_changed_at, :entries_count, :contributor_id
61
61
 
62
+ # let uri be blank if display_uri is not blank. In that case the 'feed' is really a site rather than a feed.
63
+ def is_website?
64
+ self.uri.blank? && !self.display_uri.blank?
65
+ end
66
+
62
67
  def banned?
63
68
  self.status == MuckServices::Status::BANNED
64
69
  end
@@ -148,11 +153,11 @@ class Feed < ActiveRecord::Base
148
153
 
149
154
  # Gathers all available feed uris from the given uri and parses them into
150
155
  # feed objects
151
- def self.feeds_from_uri(uri, user = nil)
156
+ def self.feeds_from_uri(uri, contributor = nil)
152
157
  feeds = []
153
158
  @available_feeds = discover_feeds(uri)
154
159
  @available_feeds.each do |feed|
155
- feeds << create_from_feedzirra(fetch_feed(feed.url), user) unless feed.blank?
160
+ feeds << create_from_feedzirra(fetch_feed(feed.url), contributor) unless feed.blank?
156
161
  end
157
162
  feeds
158
163
  end
@@ -173,9 +178,9 @@ class Feed < ActiveRecord::Base
173
178
  end
174
179
 
175
180
  # Creates a feed from feedzirra into a muck feed
176
- def self.create_from_feedzirra(feed, user)
181
+ def self.create_from_feedzirra(feed, contributor)
177
182
  return if feed.blank?
178
- Feed.find_or_create(feed.feed_url, feed.title, '', '', Service.find_service_by_uri(feed.url), user, feed.url)
183
+ Feed.find_or_create(feed.feed_url, feed.title, '', '', Service.find_service_by_uri(feed.url), contributor, feed.url)
179
184
  end
180
185
 
181
186
  # Looks for feeds from a given url
@@ -188,8 +193,31 @@ class Feed < ActiveRecord::Base
188
193
  end
189
194
  end
190
195
 
196
+ # Attempts to build feeds from the provided uri. If that fails the uri is added as a website (a feed without a uri but with a display_uri)
197
+ def self.make_feeds_or_website(uri, contributor, service_name = nil)
198
+ return [] if uri.blank?
199
+ feeds = Feed.feeds_from_uri(uri, contributor)
200
+ if feeds.blank?
201
+ # Couldn't find a feed. Create it as a website
202
+ service = Service.find_by_name(service_name)
203
+ service ||= Service.find_service_by_uri(uri)
204
+ feeds = [Feed.find_or_create_as_website(uri, '', service, contributor)]
205
+ end
206
+ feeds
207
+ end
208
+
191
209
  # Finds or creates a feed based on the url. Any give feed uri should only exist once in the system
192
- def self.find_or_create(uri, title, username, password, service_id, contributor_id, display_uri = nil)
210
+ def self.find_or_create(uri, title, username, password, service, contributor, display_uri = nil)
211
+ if service.is_a?(Service)
212
+ service_id = service.id
213
+ else
214
+ service_id = service
215
+ end
216
+ if contributor.is_a?(User)
217
+ contributor_id = contributor.id
218
+ else
219
+ contributor_id = contributor
220
+ end
193
221
  Feed.find_by_uri(uri) ||
194
222
  Feed.create(:uri => uri,
195
223
  :harvest_interval => '01:00:00',
@@ -202,6 +230,11 @@ class Feed < ActiveRecord::Base
202
230
  :display_uri => display_uri)
203
231
  end
204
232
 
233
+ # Finds or creates a feed based on the url. Any give feed uri should only exist once in the system
234
+ def self.find_or_create_as_website(display_uri, title, service, contributor)
235
+ Feed.find_or_create(nil, title, nil, nil, service, contributor, display_uri)
236
+ end
237
+
205
238
  # Create feeds for the given uris
206
239
  # user: User that will be set as the feed contributor
207
240
  # uris: An array of uris for which to create feeds
@@ -209,7 +242,7 @@ class Feed < ActiveRecord::Base
209
242
  def self.create_tag_feeds(user = nil, uris = nil, service = nil)
210
243
  return [] if uris.blank?
211
244
  service ||= Service.default_service
212
- uris.collect { |uri| Feed.find_or_create(uri, '', '', '', service.id, user, uri) }
245
+ uris.collect { |uri| Feed.find_or_create(uri, '', '', '', service, user, uri) }
213
246
  end
214
247
 
215
248
  # Combines entries in a collection of feeds together and sorts the entries by date
@@ -428,7 +428,7 @@ class Service < ActiveRecord::Base
428
428
  def self.create_tag_feeds(terms, user = nil, selected_service_ids = nil, refresh_services = false)
429
429
  services = get_tag_services(selected_service_ids, refresh_services)
430
430
  split_terms(terms).collect { |tag|
431
- services.collect { |service| Feed.find_or_create(service.generate_tag_uri(tag), tag, '', '', service.id, user, service.human_uri(tag)) }
431
+ services.collect { |service| Feed.find_or_create(service.generate_tag_uri(tag), tag, '', '', service, user, service.human_uri(tag)) }
432
432
  }.flatten!
433
433
  end
434
434
 
@@ -2,7 +2,7 @@
2
2
  <% if limited -%>
3
3
  <%= activity.item.body %>
4
4
  <% else -%>
5
- <%= t('muck.services.entry_commment_contents', :resource => link_to(activity.item.commentable.title, visit_path(activity.item.commentable, :show_comments => true))) -%>
5
+ <%= t('muck.services.entry_commment_contents', :resource => link_to(activity.item.commentable.try(:title), visit_path(activity.item.commentable, :show_comments => true))) -%>
6
6
  <p class="entry-comment-contents"><%= activity.item.body %></p>
7
7
  <% end -%>
8
8
  <% end -%>
@@ -10,6 +10,7 @@ module MuckServices
10
10
  extend ActiveSupport::Concern
11
11
 
12
12
  included do
13
+ has_many :contributed_feeds, :class_name => 'Feed'
13
14
  has_many :identity_feeds, :as => :ownable
14
15
  has_many :own_feeds, :through => :identity_feeds, :source => :feed, :order => 'created_at desc'
15
16
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{muck-services}
8
- s.version = "3.2.2"
8
+ s.version = "3.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Joel Duffin", "Justin Ball"]
12
- s.date = %q{2011-02-12}
12
+ s.date = %q{2011-03-02}
13
13
  s.description = %q{This gem contains the rails specific code for dealing with feeds, aggregations and recommendations. It is meant to work with the muck-raker gem.}
14
14
  s.email = %q{justin@tatemae.com}
15
15
  s.extra_rdoc_files = [
@@ -261,11 +261,10 @@ Gem::Specification.new do |s|
261
261
  ]
262
262
  s.homepage = %q{http://github.com/tatemae/muck_services}
263
263
  s.require_paths = ["lib"]
264
- s.rubygems_version = %q{1.3.7}
264
+ s.rubygems_version = %q{1.5.2}
265
265
  s.summary = %q{Feeds, aggregations and services for muck}
266
266
 
267
267
  if s.respond_to? :specification_version then
268
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
269
268
  s.specification_version = 3
270
269
 
271
270
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
metadata CHANGED
@@ -2,12 +2,12 @@
2
2
  name: muck-services
3
3
  version: !ruby/object:Gem::Version
4
4
  hash: 11
5
- prerelease: false
5
+ prerelease:
6
6
  segments:
7
7
  - 3
8
- - 2
9
- - 2
10
- version: 3.2.2
8
+ - 3
9
+ - 0
10
+ version: 3.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joel Duffin
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-02-12 00:00:00 -07:00
19
+ date: 2011-03-02 00:00:00 -07:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -496,7 +496,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
496
496
  requirements: []
497
497
 
498
498
  rubyforge_project:
499
- rubygems_version: 1.3.7
499
+ rubygems_version: 1.5.2
500
500
  signing_key:
501
501
  specification_version: 3
502
502
  summary: Feeds, aggregations and services for muck