muck-raker 0.1.40 → 0.1.41
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/controllers/muck/aggregations_controller.rb +1 -1
- data/app/controllers/muck/entries_controller.rb +2 -0
- data/app/controllers/muck/identity_feeds_controller.rb +1 -1
- data/app/controllers/muck/topics_controller.rb +2 -2
- data/app/models/aggregation.rb +15 -13
- data/app/models/entry.rb +1 -0
- data/app/models/feed.rb +1 -1
- data/app/models/service.rb +190 -69
- data/app/views/entries/_result_status.html.erb +1 -1
- data/app/views/entries/browse_by_tags.html.erb +1 -0
- data/lib/muck_raker/exceptions.rb +5 -0
- data/lib/muck_raker/languages.rb +4 -0
- data/lib/muck_raker.rb +2 -0
- data/locales/en.yml +1 -0
- data/muck-raker.gemspec +3 -2
- data/test/rails_root/test/factories.rb +1 -0
- data/test/rails_root/test/functional/topics_controller_test.rb +1 -1
- data/test/rails_root/test/test_helper.rb +9 -0
- data/test/rails_root/test/unit/aggregation_test.rb +9 -8
- data/test/rails_root/test/unit/entry_test.rb +12 -0
- data/test/rails_root/test/unit/service_test.rb +59 -24
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.41
|
@@ -60,7 +60,7 @@ class Muck::AggregationsController < ApplicationController
|
|
60
60
|
terms = params[:terms]
|
61
61
|
terms = terms.join(' ') if terms.is_a?(Array)
|
62
62
|
|
63
|
-
#@feeds = Service.
|
63
|
+
#@feeds = Service.build_tag_feeds(terms, current_user, params[:service_ids])
|
64
64
|
|
65
65
|
@photo_feeds = Service.build_photo_feeds(terms, current_user)
|
66
66
|
@video_feeds = Service.build_video_feeds(terms, current_user)
|
@@ -86,6 +86,8 @@ class Muck::EntriesController < ApplicationController
|
|
86
86
|
@paginated_results = @results.paginate(:page => @page, :per_page => @per_page, :total_entries => @hit_count)
|
87
87
|
log_query(current_user.nil? ? request.remote_addr : current_user.id, Language.locale_id, @tag_filter.nil? ? 'search' : 'browse', @search, @grain_size, @hit_count)
|
88
88
|
end
|
89
|
+
rescue MuckRaker::Exceptions::LanguageNotSupported => ex
|
90
|
+
flash[:error] = ex
|
89
91
|
end
|
90
92
|
|
91
93
|
def query_logger
|
@@ -29,7 +29,7 @@ class Muck::IdentityFeedsController < ApplicationController
|
|
29
29
|
def create
|
30
30
|
@service = Service.find(params[:service_id])
|
31
31
|
@feed = Feed.new(:uri => params[:uri], :login => params[:username])
|
32
|
-
feeds = Service.
|
32
|
+
feeds = Service.create_tag_feeds_for_service(@service, params[:uri], params[:username], params[:password], current_user.id)
|
33
33
|
if feeds.blank?
|
34
34
|
success = false
|
35
35
|
if params[:username]
|
@@ -3,7 +3,7 @@ class Muck::TopicsController < ApplicationController
|
|
3
3
|
|
4
4
|
before_filter :adjust_format_for_iphone
|
5
5
|
before_filter :check_terms, :except => [:new]
|
6
|
-
before_filter :
|
6
|
+
before_filter :build_tag_feeds, :only => [:show, :rss_discovery]
|
7
7
|
|
8
8
|
def show
|
9
9
|
respond_to do |format|
|
@@ -71,7 +71,7 @@ class Muck::TopicsController < ApplicationController
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
def
|
74
|
+
def build_tag_feeds
|
75
75
|
@terms = CGI.unescape(params[:id])
|
76
76
|
@page_title = @title = @terms.titleize
|
77
77
|
|
data/app/models/aggregation.rb
CHANGED
@@ -29,12 +29,14 @@ class Aggregation < ActiveRecord::Base
|
|
29
29
|
# Builds and then adds feeds for a given terms
|
30
30
|
# user: User to be associated with each feed. Default is nil which makes each feed global.
|
31
31
|
# service_ids: An array of service ids. Nil will generate a feed for every available service.
|
32
|
-
|
33
|
-
|
32
|
+
# refresh_services: By default all tag services are cached. Setting this value to true
|
33
|
+
# will result in the values being repopulated from the database
|
34
|
+
def add_feeds(user = nil, service_ids = nil, refresh_services = false)
|
35
|
+
safe_add_feeds(Service.create_tag_feeds(self.terms, user, service_ids, refresh_services))
|
34
36
|
end
|
35
37
|
|
36
38
|
def add_feeds_by_uri(user = nil, uris = nil)
|
37
|
-
safe_add_feeds(Feed.
|
39
|
+
safe_add_feeds(Feed.create_tag_feeds(user, uris))
|
38
40
|
end
|
39
41
|
|
40
42
|
# Only add feeds that aren't already part of the aggregation
|
@@ -50,28 +52,28 @@ class Aggregation < ActiveRecord::Base
|
|
50
52
|
end
|
51
53
|
|
52
54
|
# Get only photo feeds
|
53
|
-
def photo_feeds
|
54
|
-
all_feeds.find_all{ |feed| feed.service.photo? }
|
55
|
+
def photo_feeds(refresh_services = false)
|
56
|
+
all_feeds.find_all{ |feed| feed.service.photo?(refresh_services) rescue nil }
|
55
57
|
end
|
56
58
|
|
57
59
|
# Get only video feeds
|
58
|
-
def video_feeds
|
59
|
-
all_feeds.find_all{ |feed| feed.service.video? }
|
60
|
+
def video_feeds(refresh_services = false)
|
61
|
+
all_feeds.find_all{ |feed| feed.service.video?(refresh_services) rescue nil }
|
60
62
|
end
|
61
63
|
|
62
64
|
# Get only bookmark feeds
|
63
|
-
def bookmark_feeds
|
64
|
-
all_feeds.find_all{ |feed| feed.service.bookmark? }
|
65
|
+
def bookmark_feeds(refresh_services = false)
|
66
|
+
all_feeds.find_all{ |feed| feed.service.bookmark?(refresh_services) rescue nil }
|
65
67
|
end
|
66
68
|
|
67
69
|
# Get only music feeds
|
68
|
-
def music_feeds
|
69
|
-
all_feeds.find_all{ |feed| feed.service.music? }
|
70
|
+
def music_feeds(refresh_services = false)
|
71
|
+
all_feeds.find_all{ |feed| feed.service.music?(refresh_services) rescue nil}
|
70
72
|
end
|
71
73
|
|
72
74
|
# Get only general feeds (exclude all specific feeds such as photos, videos, etc)
|
73
|
-
def general_feeds
|
74
|
-
all_feeds.find_all{ |feed| feed.service.general? }
|
75
|
+
def general_feeds(refresh_services = false)
|
76
|
+
all_feeds.find_all{ |feed| feed.service.general?(refresh_services) rescue nil }
|
75
77
|
end
|
76
78
|
|
77
79
|
def all_feeds
|
data/app/models/entry.rb
CHANGED
@@ -60,6 +60,7 @@ class Entry < ActiveRecord::Base
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def self.search(search_terms, grain_size = nil, language = "en", limit = 10, offset = 0, operator = :or)
|
63
|
+
raise MuckRaker::Exceptions::LanguageNotSupported, I18n.t('muck.raker.language_not_supported') unless Recommender::Languages.supported_languages.include?(language)
|
63
64
|
query = (!grain_size.nil? && grain_size != 'all') ? (search_terms + ") AND (grain_size:#{grain_size}") : search_terms
|
64
65
|
return find_by_solr(query, :limit => limit, :offset => offset, :scores => true, :select => "entries.id, entries.title, entries.permalink, entries.direct_link, entries.published_at, entries.description, entries.feed_id, feeds.short_title AS collection", :joins => "INNER JOIN feeds ON feeds.id = entries.feed_id", :core => language, :operator => operator)
|
65
66
|
end
|
data/app/models/feed.rb
CHANGED
@@ -198,7 +198,7 @@ class Feed < ActiveRecord::Base
|
|
198
198
|
# user: User that will be set as the feed contributor
|
199
199
|
# uris: An array of uris for which to create feeds
|
200
200
|
# service: A default service to be associated with all the feeds.
|
201
|
-
def self.
|
201
|
+
def self.create_tag_feeds(user = nil, uris = nil, service = nil)
|
202
202
|
return [] if uris.blank?
|
203
203
|
service ||= Service.default_service
|
204
204
|
uris.collect { |uri| Feed.find_or_create(uri, '', '', '', service.id, user, uri) }
|
data/app/models/service.rb
CHANGED
@@ -26,28 +26,39 @@ class Service < ActiveRecord::Base
|
|
26
26
|
named_scope :tag_services, :conditions => ['use_for = ?', 'tags']
|
27
27
|
named_scope :photo_services, :conditions => ["service_categories.id = services.service_category_id AND service_categories.name = 'Photos'"], :include => ['service_category']
|
28
28
|
|
29
|
-
# Indicates whether
|
30
|
-
|
31
|
-
|
29
|
+
# Indicates whether service is primarily a photo service ie from flick, picasa, etc
|
30
|
+
#
|
31
|
+
# refresh_services: Optional parameter indicating whether or not to reload values from the database before checking service type
|
32
|
+
def photo?(refresh_services = false)
|
33
|
+
Service.get_photo_services(refresh_services).include?(self)
|
32
34
|
end
|
33
35
|
|
34
|
-
# Indicates whether
|
35
|
-
|
36
|
-
|
36
|
+
# Indicates whether service is primarily a video service ie from youtube, etc
|
37
|
+
#
|
38
|
+
# refresh_services: Optional parameter indicating whether or not to reload values from the database before checking service type
|
39
|
+
def video?(refresh_services = false)
|
40
|
+
Service.get_video_services(refresh_services).include?(self)
|
37
41
|
end
|
38
42
|
|
39
|
-
# Indicates whether
|
40
|
-
|
41
|
-
|
43
|
+
# Indicates whether service is primarily a bookmark service ie delicious, etc
|
44
|
+
#
|
45
|
+
# refresh_services: Optional parameter indicating whether or not to reload values from the database before checking service type
|
46
|
+
def bookmark?(refresh_services = false)
|
47
|
+
Service.get_bookmark_services(refresh_services).include?(self)
|
42
48
|
end
|
43
49
|
|
44
|
-
# Indicates whether
|
45
|
-
|
46
|
-
|
50
|
+
# Indicates whether service is primarily music
|
51
|
+
#
|
52
|
+
# refresh_services: Optional parameter indicating whether or not to reload values from the database before checking service type
|
53
|
+
def music?(refresh_services = false)
|
54
|
+
Service.get_music_services(refresh_services).include?(self)
|
47
55
|
end
|
48
56
|
|
49
|
-
|
50
|
-
|
57
|
+
# Indicates whether service is general (ie not video, photo, music or bookmark)
|
58
|
+
#
|
59
|
+
# refresh_services: Optional parameter indicating whether or not to reload values from the database before checking service type
|
60
|
+
def general?(refresh_services = false)
|
61
|
+
Service.get_general_services(refresh_services).include?(self)
|
51
62
|
end
|
52
63
|
|
53
64
|
def human_uri(tag)
|
@@ -100,95 +111,179 @@ class Service < ActiveRecord::Base
|
|
100
111
|
# Generates uris for 'tag' using all services where 'use_for' is 'tags'
|
101
112
|
def self.generate_tag_uris(terms, selected_service_ids = nil)
|
102
113
|
split_terms(terms).collect { |tag|
|
103
|
-
|
114
|
+
get_tag_services(selected_service_ids).collect { |service| service.generate_tag_uri(tag) }
|
104
115
|
}.flatten!
|
105
116
|
end
|
106
117
|
|
107
118
|
# creates a feed for a service with a username and optional password
|
108
|
-
def self.
|
119
|
+
def self.create_tag_feeds_for_service(service, uri, username, password, contributor)
|
109
120
|
uris = service.generate_uris(username, password, uri)
|
110
121
|
uris.collect{ |u| Feed.find_or_create(u.url, u.title, username, password, service.id, contributor) } if uris
|
111
122
|
end
|
112
123
|
|
113
|
-
def self.build_photo_feeds(terms, user, service_ids = nil)
|
124
|
+
def self.build_photo_feeds(terms, user, service_ids = nil, refresh_services = false)
|
114
125
|
if service_ids.nil?
|
115
|
-
service_ids =
|
126
|
+
service_ids = get_photo_tag_services(refresh_services).map(&:id)
|
116
127
|
else
|
117
|
-
service_ids = make_int_array(service_ids) &
|
128
|
+
service_ids = make_int_array(service_ids) & get_photo_tag_services(refresh_services).map(&:id)
|
118
129
|
end
|
119
|
-
|
130
|
+
build_tag_feeds(terms, user, service_ids, refresh_services)
|
120
131
|
end
|
121
132
|
|
122
|
-
def self.build_video_feeds(terms, user, service_ids = nil)
|
133
|
+
def self.build_video_feeds(terms, user, service_ids = nil, refresh_services = false)
|
123
134
|
if service_ids.nil?
|
124
|
-
service_ids =
|
135
|
+
service_ids = get_video_tag_services(refresh_services).map(&:id)
|
125
136
|
else
|
126
|
-
service_ids = make_int_array(service_ids) &
|
137
|
+
service_ids = make_int_array(service_ids) & get_video_tag_services(refresh_services).map(&:id)
|
127
138
|
end
|
128
|
-
|
139
|
+
build_tag_feeds(terms, user, service_ids, refresh_services)
|
129
140
|
end
|
130
141
|
|
131
|
-
def self.build_bookmark_feeds(terms, user, service_ids = nil)
|
142
|
+
def self.build_bookmark_feeds(terms, user, service_ids = nil, refresh_services = false)
|
132
143
|
if service_ids.nil?
|
133
|
-
service_ids =
|
144
|
+
service_ids = get_bookmark_tag_services(refresh_services).map(&:id)
|
134
145
|
else
|
135
|
-
service_ids = make_int_array(service_ids) &
|
146
|
+
service_ids = make_int_array(service_ids) & get_bookmark_tag_services(refresh_services).map(&:id)
|
136
147
|
end
|
137
|
-
|
148
|
+
build_tag_feeds(terms, user, service_ids, refresh_services)
|
138
149
|
end
|
139
150
|
|
140
|
-
def self.build_music_feeds(terms, user, service_ids = nil)
|
151
|
+
def self.build_music_feeds(terms, user, service_ids = nil, refresh_services = false)
|
141
152
|
if service_ids.nil?
|
142
|
-
service_ids =
|
153
|
+
service_ids = get_music_tag_services(refresh_services).map(&:id)
|
143
154
|
else
|
144
|
-
service_ids = make_int_array(service_ids) &
|
155
|
+
service_ids = make_int_array(service_ids) & get_music_tag_services(refresh_services).map(&:id)
|
145
156
|
end
|
146
|
-
|
157
|
+
build_tag_feeds(terms, user, service_ids, refresh_services)
|
147
158
|
end
|
148
159
|
|
149
|
-
def self.build_general_feeds(terms, user, service_ids = nil)
|
160
|
+
def self.build_general_feeds(terms, user, service_ids = nil, refresh_services = false)
|
150
161
|
if service_ids.nil?
|
151
|
-
service_ids =
|
162
|
+
service_ids = get_general_tag_services(refresh_services).map(&:id)
|
152
163
|
else
|
153
|
-
service_ids = make_int_array(service_ids) &
|
164
|
+
service_ids = make_int_array(service_ids) & get_general_tag_services(refresh_services).map(&:id)
|
154
165
|
end
|
155
|
-
|
166
|
+
build_tag_feeds(terms, user, service_ids, refresh_services)
|
156
167
|
end
|
157
|
-
|
158
|
-
|
159
|
-
|
168
|
+
|
169
|
+
# Get all photo services
|
170
|
+
#
|
171
|
+
# refresh_services: By default all tag services are cached. Setting this value to true
|
172
|
+
# will result in the values being repopulated from the database
|
173
|
+
def self.get_photo_services(refresh_services = false)
|
174
|
+
@photo_services = nil if refresh_services
|
175
|
+
@photo_services ||= get_services(refresh_services).find_all{|service| service.service_category.name == 'Photos' }
|
160
176
|
end
|
161
177
|
|
162
|
-
|
163
|
-
|
178
|
+
# Get all video services
|
179
|
+
#
|
180
|
+
# refresh_services: By default all tag services are cached. Setting this value to true
|
181
|
+
# will result in the values being repopulated from the database
|
182
|
+
def self.get_video_services(refresh_services = false)
|
183
|
+
@video_services = nil if refresh_services
|
184
|
+
@video_services ||= get_services(refresh_services).find_all{|service| service.service_category.name == 'Videos' }
|
164
185
|
end
|
165
186
|
|
166
|
-
|
167
|
-
|
187
|
+
# Get all bookmark services
|
188
|
+
#
|
189
|
+
# refresh_services: By default all tag services are cached. Setting this value to true
|
190
|
+
# will result in the values being repopulated from the database
|
191
|
+
def self.get_bookmark_services(refresh_services = false)
|
192
|
+
@bookmark_services = nil if refresh_services
|
193
|
+
@bookmark_services ||= get_services(refresh_services).find_all{|service| service.service_category.name == 'Bookmarks' }
|
194
|
+
end
|
195
|
+
|
196
|
+
# Get all music services
|
197
|
+
#
|
198
|
+
# refresh_services: By default all tag services are cached. Setting this value to true
|
199
|
+
# will result in the values being repopulated from the database
|
200
|
+
def self.get_music_services(refresh_services = false)
|
201
|
+
@music_services = nil if refresh_services
|
202
|
+
@music_services ||= get_services(refresh_services).find_all{|service| service.service_category.name == 'Music' }
|
203
|
+
end
|
204
|
+
|
205
|
+
# Get all general services. These are all services except photo, video, bookmark and music.
|
206
|
+
#
|
207
|
+
# refresh_services: By default all tag services are cached. Setting this value to true
|
208
|
+
# will result in the values being repopulated from the database
|
209
|
+
def self.get_general_services(refresh_services = false)
|
210
|
+
@general_services = nil if refresh_services
|
211
|
+
@general_services ||= get_services(refresh_services).find_all{|service| !['Photos', 'Videos', 'Bookmarks', 'Music'].include?(service.service_category.name) }
|
212
|
+
end
|
213
|
+
|
214
|
+
# Get all photo services that are used to generate tag feeds
|
215
|
+
#
|
216
|
+
# refresh_services: By default all tag services are cached. Setting this value to true
|
217
|
+
# will result in the values being repopulated from the database
|
218
|
+
def self.get_photo_tag_services(refresh_services = false)
|
219
|
+
@photo_services = nil if refresh_services
|
220
|
+
@photo_services ||= get_tag_services(nil, refresh_services).find_all{|service| service.service_category.name == 'Photos' }
|
221
|
+
end
|
222
|
+
|
223
|
+
# Get all video services that are used to generate tag feeds
|
224
|
+
#
|
225
|
+
# refresh_services: By default all tag services are cached. Setting this value to true
|
226
|
+
# will result in the values being repopulated from the database
|
227
|
+
def self.get_video_tag_services(refresh_services = false)
|
228
|
+
@video_services = nil if refresh_services
|
229
|
+
@video_services ||= get_tag_services(nil, refresh_services).find_all{|service| service.service_category.name == 'Videos' }
|
168
230
|
end
|
169
231
|
|
170
|
-
|
171
|
-
|
232
|
+
# Get all bookmark services that are used to generate tag feeds
|
233
|
+
#
|
234
|
+
# refresh_services: By default all tag services are cached. Setting this value to true
|
235
|
+
# will result in the values being repopulated from the database
|
236
|
+
def self.get_bookmark_tag_services(refresh_services = false)
|
237
|
+
@bookmark_services = nil if refresh_services
|
238
|
+
@bookmark_services ||= get_tag_services(nil, refresh_services).find_all{|service| service.service_category.name == 'Bookmarks' }
|
172
239
|
end
|
173
240
|
|
174
|
-
|
175
|
-
|
241
|
+
# Get all music services that are used to generate tag feeds
|
242
|
+
#
|
243
|
+
# refresh_services: By default all tag services are cached. Setting this value to true
|
244
|
+
# will result in the values being repopulated from the database
|
245
|
+
def self.get_music_tag_services(refresh_services = false)
|
246
|
+
@music_services = nil if refresh_services
|
247
|
+
@music_services ||= get_tag_services(nil, refresh_services).find_all{|service| service.service_category.name == 'Music' }
|
176
248
|
end
|
177
249
|
|
178
|
-
#
|
179
|
-
|
250
|
+
# Get all general services that are used to generate tag feeds
|
251
|
+
#
|
252
|
+
# refresh_services: By default all tag services are cached. Setting this value to true
|
253
|
+
# will result in the values being repopulated from the database
|
254
|
+
def self.get_general_tag_services(refresh_services = false)
|
255
|
+
@general_services = nil if refresh_services
|
256
|
+
@general_services ||= get_tag_services(nil, refresh_services).find_all{|service| !['Photos', 'Videos', 'Bookmarks', 'Music'].include?(service.service_category.name) }
|
257
|
+
end
|
258
|
+
|
259
|
+
# Builds tag based feeds for the given term. Feeds are not saved to the database.
|
260
|
+
#
|
261
|
+
# terms: Terms for which to generate feeds. This value can be an array, a single string,
|
262
|
+
# or a list of items seperated by a comma.
|
263
|
+
# user: User to attach the feed to. This is the feed 'contributor.
|
264
|
+
# selected_service_ids: ids for services to select.
|
265
|
+
# refresh_services: By default all tag services are cached. Setting this value to true
|
266
|
+
# will result in the values being repopulated from the database
|
267
|
+
def self.build_tag_feeds(terms, user, selected_service_ids = nil, refresh_services = false)
|
268
|
+
services = get_tag_services(selected_service_ids, refresh_services)
|
180
269
|
split_terms(terms).collect { |tag|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
270
|
+
services.collect { |service| Feed.new(:uri => service.generate_tag_uri(tag),
|
271
|
+
:display_uri => service.human_uri(tag),
|
272
|
+
:title => I18n.t('muck.raker.service_feed_name', :term => CGI.unescape(tag).humanize, :service => service.name),
|
273
|
+
:service_id => service.id,
|
274
|
+
:contributor_id => user) }
|
186
275
|
}.flatten!
|
187
276
|
end
|
188
277
|
|
189
278
|
# Builds feeds (does not save them to the db) for the given term. Note that this
|
190
|
-
# method calls each feed created
|
191
|
-
|
279
|
+
# method calls the url for each feed created to attempt auto discovery and so it
|
280
|
+
# can take a while to run.
|
281
|
+
#
|
282
|
+
# terms: Terms for which to generate feeds. This value can be an array, a single string,
|
283
|
+
# or a list of items seperated by a comma.
|
284
|
+
# user: User to attach the feed to. This is the feed 'contributor.
|
285
|
+
# selected_service_ids: ids for services to select.
|
286
|
+
def self.build_live_tag_feeds(terms, user, selected_service_ids = nil)
|
192
287
|
uris = generate_tag_uris(terms, selected_service_ids)
|
193
288
|
feed_uris = uris.collect { |uri| Feed.discover_feeds(uri)}
|
194
289
|
feed_uris.collect { |feed| Feed.new(:uri => feed.url,
|
@@ -197,46 +292,72 @@ class Service < ActiveRecord::Base
|
|
197
292
|
:contributor_id => user) }
|
198
293
|
end
|
199
294
|
|
200
|
-
# Create feeds for the given terms
|
201
|
-
|
295
|
+
# Create feeds for the given terms and save them to the database.
|
296
|
+
# terms: Terms for which to generate feeds. This value can be an array, a single string,
|
297
|
+
# or a list of items seperated by a comma.
|
298
|
+
# user: User to attach the feed to. This is the feed 'contributor.
|
299
|
+
# selected_service_ids: ids for services to select.
|
300
|
+
# refresh_services: By default all tag services are cached. Setting this value to true
|
301
|
+
# will result in the values being repopulated from the database
|
302
|
+
def self.create_tag_feeds(terms, user = nil, selected_service_ids = nil, refresh_services = false)
|
303
|
+
services = get_tag_services(selected_service_ids, refresh_services)
|
202
304
|
split_terms(terms).collect { |tag|
|
203
|
-
|
305
|
+
services.collect { |service| Feed.find_or_create(service.generate_tag_uri(tag), tag, '', '', service.id, user, service.human_uri(tag)) }
|
204
306
|
}.flatten!
|
205
307
|
end
|
206
308
|
|
309
|
+
# Splits terms using a comma. This method also URI encodes all resulting terms
|
310
|
+
# terms: A string, array or comma delimited string of terms (tags).
|
207
311
|
def self.split_terms(terms)
|
208
312
|
return '' if terms.blank?
|
209
313
|
terms = terms.split(',') unless terms.is_a?(Array)
|
210
314
|
terms.collect { |tag| CGI.escape(tag.strip) }
|
211
315
|
end
|
212
316
|
|
213
|
-
|
317
|
+
# Gets all services with the specified service ids. If selected_service_ids is not
|
318
|
+
# provided then this method will get all tag services
|
319
|
+
#
|
320
|
+
# selected_service_ids: ids for services to select.
|
321
|
+
# refresh_services: By default all tag services are cached. Setting this value to true
|
322
|
+
# will result in the values being repopulated from the database
|
323
|
+
def self.get_tag_services(selected_service_ids = nil, refresh_services = false)
|
214
324
|
if selected_service_ids
|
215
325
|
selected_service_ids.collect! { |service_id| service_id.to_i } # make sure the ids are ints
|
216
326
|
Service.tag_services.find_all { |service| selected_service_ids.include?(service.id) }
|
217
327
|
else
|
218
|
-
|
328
|
+
if refresh_services
|
329
|
+
@tag_services = Service.tag_services
|
330
|
+
else
|
331
|
+
@tag_services ||= Service.tag_services
|
332
|
+
end
|
219
333
|
end
|
220
334
|
end
|
221
|
-
|
222
|
-
#
|
335
|
+
|
336
|
+
# Selects and caches all services from the database.
|
337
|
+
#
|
338
|
+
# refresh_services: By default all tag services are cached. Setting this value to true
|
339
|
+
# will result in the values being repopulated from the database
|
340
|
+
def self.get_services(refresh_services = false)
|
341
|
+
@all_services = nil if refresh_services
|
342
|
+
@all_services ||= Service.all
|
343
|
+
end
|
344
|
+
|
345
|
+
# Attempts to find a service object using a uri
|
346
|
+
#
|
223
347
|
# uri: Uri to search for. This method will attempt to all services for any part of the provided uri.
|
224
348
|
# refresh_services: Forces a refresh of the services. By default the services are cached for the duration of the request.
|
225
349
|
def self.find_service_by_uri(uri, refresh_services = false)
|
226
|
-
|
227
|
-
@services = Service.all
|
228
|
-
else
|
229
|
-
@services ||= Service.all
|
230
|
-
end
|
231
|
-
service = @services.detect { |service| service.uri && service.uri.length > 0 && (uri.include?(service.uri) || service.uri.include?(uri)) }
|
350
|
+
service = get_services(refresh_services).detect { |service| service.uri && service.uri.length > 0 && (uri.include?(service.uri) || service.uri.include?(uri)) }
|
232
351
|
service ||= default_service
|
233
352
|
service
|
234
353
|
end
|
235
354
|
|
355
|
+
# Turns all items in an array into integers.
|
236
356
|
def self.make_int_array(a)
|
237
357
|
a.collect{|i| i.to_i}
|
238
358
|
end
|
239
359
|
|
360
|
+
# Default service is RSS
|
240
361
|
def self.default_service
|
241
362
|
Service.find_by_name('rss') # this will return the default rss service
|
242
363
|
end
|
@@ -10,7 +10,7 @@
|
|
10
10
|
<%= link_to('[' + t('muck.raker.show_tagged_courses') + ']', @tag_filter.nil? ? {:q => @search, :grain_size => 'course'} : {:grain_size => 'course'}) %>
|
11
11
|
<% end %>
|
12
12
|
|
13
|
-
<%= link_to('[' + t('muck.raker.explore', :topic => @search) + ']', topic_path(@search)) %>
|
13
|
+
<%= link_to('[' + t('muck.raker.explore', :topic => @search.titleize) + ']', topic_path(URI.escape(@search))) %>
|
14
14
|
</span>
|
15
15
|
</div>
|
16
16
|
</div>
|
data/lib/muck_raker/languages.rb
CHANGED
@@ -49,5 +49,9 @@ module Recommender
|
|
49
49
|
CZECH, DANISH, DUTCH, ENGLISH, FILIPINO, FRENCH, GERMAN, GREEK, HEBREW,
|
50
50
|
ITALIAN, JAPANESE, KOREAN, LATVIAN, LITHUANIAN, NORWEGIAN, POLISH, PORTUGESE,
|
51
51
|
ROMANIAN, RUSSIAN, SERBIAN, SLOVAK, SLOVENIAN, SPANISH, SWEDISH, UKRANIAN, VIETNAMESE]
|
52
|
+
|
53
|
+
def self.supported_languages
|
54
|
+
AVAILABLE_LOCALES.gsub('^', '').split('|')
|
55
|
+
end
|
52
56
|
end
|
53
57
|
end
|
data/lib/muck_raker.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'muck_raker/muck_custom_form_builder'
|
2
2
|
require 'muck_raker/services'
|
3
|
+
require 'muck_raker/languages'
|
3
4
|
|
4
5
|
ActionController::Base.send :helper, MuckRakerHelper
|
5
6
|
ActionController::Base.send :helper, MuckRakerFeedsHelper
|
@@ -7,6 +8,7 @@ ActionController::Base.send :helper, MuckRakerServicesHelper
|
|
7
8
|
ActionController::Base.send :helper, MuckRakerAggregationsHelper
|
8
9
|
ActionController::Base.send :helper, MuckRakerGoogleHelper
|
9
10
|
|
11
|
+
ActiveRecord::Base.class_eval { include MuckRaker::Exceptions }
|
10
12
|
ActiveRecord::Base.class_eval { include ActiveRecord::Acts::MuckFeedParent }
|
11
13
|
ActiveRecord::Base.class_eval { include ActiveRecord::Acts::MuckRakerComment }
|
12
14
|
ActiveRecord::Base.class_eval { include ActiveRecord::Acts::MuckRakerShare }
|
data/locales/en.yml
CHANGED
data/muck-raker.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{muck-raker}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.41"
|
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{2009-10-
|
12
|
+
s.date = %q{2009-10-19}
|
13
13
|
s.description = %q{The aggregation and recommendation engine for the muck system.}
|
14
14
|
s.email = %q{justinball@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -416,6 +416,7 @@ Gem::Specification.new do |s|
|
|
416
416
|
"lib/active_record/acts/muck_raker_comment.rb",
|
417
417
|
"lib/active_record/acts/muck_raker_share.rb",
|
418
418
|
"lib/muck_raker.rb",
|
419
|
+
"lib/muck_raker/exceptions.rb",
|
419
420
|
"lib/muck_raker/initialize_routes.rb",
|
420
421
|
"lib/muck_raker/languages.rb",
|
421
422
|
"lib/muck_raker/muck_custom_form_builder.rb",
|
@@ -35,7 +35,7 @@ class Muck::TopicsControllerTest < ActionController::TestCase
|
|
35
35
|
|
36
36
|
context "GET show without terms" do
|
37
37
|
setup do
|
38
|
-
get :show, :id => ''
|
38
|
+
get :show, :id => ' '
|
39
39
|
end
|
40
40
|
should_set_the_flash_to(I18n.t('muck.raker.no_terms_error'))
|
41
41
|
should_redirect_to("new topic") { new_topic_path }
|
@@ -59,6 +59,15 @@ class ActsAsSolr::Post
|
|
59
59
|
end
|
60
60
|
|
61
61
|
|
62
|
+
# Used to add in a music service since services.yml doesn't currently have any.
|
63
|
+
def build_music_service
|
64
|
+
# We don't have any music services in the default services.yml so we build one here
|
65
|
+
template = "http://example.com/{tag}.rss"
|
66
|
+
uri_template = "http://example.com/{tag}"
|
67
|
+
service_category = Factory(:service_category, :name => 'Music')
|
68
|
+
Factory(:service, :uri_data_template => template, :uri_template => uri_template, :use_for => 'tags', :service_category_id => service_category.id)
|
69
|
+
end
|
70
|
+
|
62
71
|
# load in the default data required to run the app
|
63
72
|
def bootstrap_services
|
64
73
|
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
|
@@ -68,9 +68,10 @@ class AggregationTest < ActiveSupport::TestCase
|
|
68
68
|
|
69
69
|
context "filter feed types" do
|
70
70
|
setup do
|
71
|
+
build_music_service
|
71
72
|
Aggregation.delete_all
|
72
73
|
@aggregation = Factory(:aggregation, :terms => 'autumn')
|
73
|
-
@aggregation.add_feeds # Generate all feeds
|
74
|
+
@aggregation.add_feeds(nil, nil, true) # Generate all feeds
|
74
75
|
end
|
75
76
|
should "get all feeds" do
|
76
77
|
assert @aggregation.all_feeds.length > 0
|
@@ -78,25 +79,25 @@ class AggregationTest < ActiveSupport::TestCase
|
|
78
79
|
assert @aggregation.all_feeds.any?{ |feed| feed.service.video? }
|
79
80
|
assert @aggregation.all_feeds.any?{ |feed| feed.service.bookmark? }
|
80
81
|
assert @aggregation.all_feeds.any?{ |feed| feed.service.general? }
|
81
|
-
end
|
82
|
+
end
|
82
83
|
should "only get photo feeds" do
|
83
|
-
assert @aggregation.photo_feeds.length > 0
|
84
|
+
assert @aggregation.photo_feeds(true).length > 0
|
84
85
|
assert @aggregation.photo_feeds.all?{ |feed| feed.service.photo? }
|
85
86
|
end
|
86
87
|
should "only get video feeds" do
|
87
|
-
assert @aggregation.video_feeds.length > 0
|
88
|
+
assert @aggregation.video_feeds(true).length > 0
|
88
89
|
assert @aggregation.video_feeds.all?{ |feed| feed.service.video? }
|
89
90
|
end
|
90
91
|
should "only get bookmark feeds" do
|
91
|
-
assert @aggregation.bookmark_feeds.length > 0
|
92
|
+
assert @aggregation.bookmark_feeds(true).length > 0
|
92
93
|
assert @aggregation.bookmark_feeds.all?{ |feed| feed.service.bookmark? }
|
93
94
|
end
|
94
95
|
should "only get music feeds" do
|
95
|
-
assert @aggregation.music_feeds.length > 0
|
96
|
+
assert @aggregation.music_feeds(true).length > 0
|
96
97
|
assert @aggregation.music_feeds.all?{ |feed| feed.service.music? }
|
97
98
|
end
|
98
99
|
should "only get general feeds" do
|
99
|
-
assert @aggregation.general_feeds.length > 0
|
100
|
+
assert @aggregation.general_feeds(true).length > 0
|
100
101
|
assert @aggregation.general_feeds.all?{ |feed| feed.service.general? }
|
101
102
|
end
|
102
103
|
|
@@ -106,7 +107,7 @@ class AggregationTest < ActiveSupport::TestCase
|
|
106
107
|
setup do
|
107
108
|
@uris = ['http://www.example.com', 'http://www.justinball.com']
|
108
109
|
@aggregation = Factory(:aggregation)
|
109
|
-
@aggregation.add_feeds_by_uri(nil, uris)
|
110
|
+
@aggregation.add_feeds_by_uri(nil, @uris)
|
110
111
|
@aggregation.reload
|
111
112
|
end
|
112
113
|
should "add feeds" do
|
@@ -48,6 +48,18 @@ class EntryTest < ActiveSupport::TestCase
|
|
48
48
|
subject { @entry }
|
49
49
|
|
50
50
|
should_belong_to :feed
|
51
|
+
|
52
|
+
context "search" do
|
53
|
+
# should "search indexes for ruby" do
|
54
|
+
# Entry.search('ruby', 'all', 'en', 10, 0)
|
55
|
+
# end
|
56
|
+
should "raise invalid language error" do
|
57
|
+
assert_raise(MuckRaker::Exceptions::LanguageNotSupported) do
|
58
|
+
Entry.search('ruby', 'all', 'foo', 10, 0)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
51
63
|
end
|
52
64
|
|
53
65
|
end
|
@@ -22,6 +22,7 @@ require File.dirname(__FILE__) + '/../test_helper'
|
|
22
22
|
class ServiceTest < ActiveSupport::TestCase
|
23
23
|
|
24
24
|
context "service instance" do
|
25
|
+
|
25
26
|
should_belong_to :service_category
|
26
27
|
should_have_named_scope :sorted
|
27
28
|
should_have_named_scope :identity_services
|
@@ -33,7 +34,7 @@ class ServiceTest < ActiveSupport::TestCase
|
|
33
34
|
@service = Factory(:service, :service_category_id => service_category.id)
|
34
35
|
end
|
35
36
|
should "be a photo service" do
|
36
|
-
assert @service.photo?
|
37
|
+
assert @service.photo?(true)
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
@@ -43,7 +44,37 @@ class ServiceTest < ActiveSupport::TestCase
|
|
43
44
|
@service = Factory(:service, :service_category_id => service_category.id)
|
44
45
|
end
|
45
46
|
should "be a video service" do
|
46
|
-
assert @service.video?
|
47
|
+
assert @service.video?(true)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "bookmarks" do
|
52
|
+
setup do
|
53
|
+
service_category = Factory(:service_category, :name => 'Bookmarks')
|
54
|
+
@service = Factory(:service, :service_category_id => service_category.id)
|
55
|
+
end
|
56
|
+
should "be a bookmark service" do
|
57
|
+
assert @service.bookmark?(true)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "music" do
|
62
|
+
setup do
|
63
|
+
service_category = Factory(:service_category, :name => 'Music')
|
64
|
+
@service = Factory(:service, :service_category_id => service_category.id)
|
65
|
+
end
|
66
|
+
should "be a music service" do
|
67
|
+
assert @service.music?(true)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "general" do
|
72
|
+
setup do
|
73
|
+
service_category = Factory(:service_category, :name => 'RSS')
|
74
|
+
@service = Factory(:service, :service_category_id => service_category.id)
|
75
|
+
end
|
76
|
+
should "be a general service" do
|
77
|
+
assert @service.general?(true)
|
47
78
|
end
|
48
79
|
end
|
49
80
|
|
@@ -81,30 +112,30 @@ class ServiceTest < ActiveSupport::TestCase
|
|
81
112
|
end
|
82
113
|
should "set display uri when building a feed" do
|
83
114
|
tag = 'identity'
|
84
|
-
feeds = Service.
|
115
|
+
feeds = Service.build_tag_feeds(tag, @user, nil, true)
|
85
116
|
assert feeds.any?{|feed| feed.display_uri == (@uri_template.sub('{tag}', tag))}
|
86
117
|
end
|
87
118
|
should "build a feed for every tag service" do
|
88
119
|
tag = 'cycling'
|
89
|
-
feeds = Service.
|
120
|
+
feeds = Service.build_tag_feeds(tag, @user, nil, true)
|
90
121
|
assert_equal Service.tag_services.length, feeds.length
|
91
122
|
assert feeds.any?{|feed| feed.uri == (@template.sub('{tag}', tag))}
|
92
123
|
end
|
93
124
|
should "build a limited number of feeds for tag" do
|
94
125
|
tag = 'ruby'
|
95
|
-
feeds = Service.
|
126
|
+
feeds = Service.build_tag_feeds(tag, @user, [@service.id], true)
|
96
127
|
assert_equal 1, feeds.length
|
97
128
|
assert feeds.any?{|feed| feed.uri == (@template.sub('{tag}', tag))}
|
98
129
|
end
|
99
130
|
should "create a feed for every tag service" do
|
100
131
|
tag = 'physics'
|
101
|
-
feeds = Service.
|
132
|
+
feeds = Service.create_tag_feeds(tag, @user, nil, true)
|
102
133
|
assert_equal Service.tag_services.length, feeds.length
|
103
134
|
assert feeds.any?{|feed| feed.uri == (@template.sub('{tag}', tag))}
|
104
135
|
end
|
105
136
|
should "create a limited number of feeds for tag" do
|
106
137
|
tag = 'math'
|
107
|
-
feeds = Service.
|
138
|
+
feeds = Service.create_tag_feeds(tag, @user, [@service.id], true)
|
108
139
|
assert_equal 1, feeds.length
|
109
140
|
assert feeds.any?{|feed| feed.uri == (@template.sub('{tag}', tag))}
|
110
141
|
end
|
@@ -119,7 +150,7 @@ class ServiceTest < ActiveSupport::TestCase
|
|
119
150
|
@user = Factory(:user)
|
120
151
|
end
|
121
152
|
should "create feed from service" do
|
122
|
-
feeds = Service.
|
153
|
+
feeds = Service.create_tag_feeds_for_service(@service, '', @login, @password, @user.id)
|
123
154
|
feed = feeds[0]
|
124
155
|
assert_equal @uri_data_template.sub("{username}", @login), feed.uri
|
125
156
|
assert_equal @login, feed.login
|
@@ -127,7 +158,7 @@ class ServiceTest < ActiveSupport::TestCase
|
|
127
158
|
assert_equal @service.id, feed.service_id
|
128
159
|
end
|
129
160
|
should "create feed from service even with nil template" do
|
130
|
-
feeds = Service.
|
161
|
+
feeds = Service.create_tag_feeds_for_service(@service, '', @login, @password, @user.id)
|
131
162
|
feed = feeds[0]
|
132
163
|
assert_equal @uri_data_template.sub("{username}", @login), feed.uri
|
133
164
|
assert_equal @login, feed.login
|
@@ -189,7 +220,8 @@ class ServiceTest < ActiveSupport::TestCase
|
|
189
220
|
end
|
190
221
|
context "music feeds" do
|
191
222
|
setup do
|
192
|
-
|
223
|
+
build_music_service
|
224
|
+
@feeds = Service.build_music_feeds(@terms, @user.id, nil, true) # We build the music service above so we have to force a cache refresh
|
193
225
|
end
|
194
226
|
should "only create music feeds" do
|
195
227
|
assert @feeds.length > 0
|
@@ -199,29 +231,32 @@ class ServiceTest < ActiveSupport::TestCase
|
|
199
231
|
end
|
200
232
|
|
201
233
|
context "service types" do
|
234
|
+
setup do
|
235
|
+
build_music_service
|
236
|
+
end
|
202
237
|
should "get photo services" do
|
203
|
-
assert Service.
|
204
|
-
assert Service.
|
238
|
+
assert Service.get_photo_tag_services(true).length > 0
|
239
|
+
assert Service.get_photo_tag_services.all? { |service| service.service_category.name == "Photos" }
|
205
240
|
end
|
206
241
|
should "get video services" do
|
207
|
-
assert Service.
|
208
|
-
assert Service.
|
242
|
+
assert Service.get_video_tag_services(true).length > 0
|
243
|
+
assert Service.get_video_tag_services.all? { |service| service.service_category.name == "Videos" }
|
209
244
|
end
|
210
245
|
should "get bookmark services" do
|
211
|
-
assert Service.
|
212
|
-
assert Service.
|
246
|
+
assert Service.get_bookmark_tag_services(true).length > 0
|
247
|
+
assert Service.get_bookmark_tag_services.all? { |service| service.service_category.name == "Bookmarks" }
|
213
248
|
end
|
214
249
|
should "get music services" do
|
215
|
-
assert Service.
|
216
|
-
assert Service.
|
250
|
+
assert Service.get_music_tag_services(true).length > 0
|
251
|
+
assert Service.get_music_tag_services.all? { |service| service.service_category.name == "Music" }
|
217
252
|
end
|
218
253
|
should "get general services" do
|
219
|
-
assert Service.
|
220
|
-
assert !Service.
|
221
|
-
assert !Service.
|
222
|
-
assert !Service.
|
223
|
-
assert !Service.
|
254
|
+
assert Service.get_general_tag_services(true).length > 0
|
255
|
+
assert !Service.get_general_tag_services.any? { |service| service.service_category.name == "Photos" }
|
256
|
+
assert !Service.get_general_tag_services.any? { |service| service.service_category.name == "Videos" }
|
257
|
+
assert !Service.get_general_tag_services.any? { |service| service.service_category.name == "Bookmarks" }
|
258
|
+
assert !Service.get_general_tag_services.any? { |service| service.service_category.name == "Music" }
|
224
259
|
end
|
225
260
|
end
|
226
|
-
|
261
|
+
|
227
262
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: muck-raker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.41
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Duffin Justin Ball
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-19 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -511,6 +511,7 @@ files:
|
|
511
511
|
- lib/active_record/acts/muck_raker_comment.rb
|
512
512
|
- lib/active_record/acts/muck_raker_share.rb
|
513
513
|
- lib/muck_raker.rb
|
514
|
+
- lib/muck_raker/exceptions.rb
|
514
515
|
- lib/muck_raker/initialize_routes.rb
|
515
516
|
- lib/muck_raker/languages.rb
|
516
517
|
- lib/muck_raker/muck_custom_form_builder.rb
|