muck-raker 0.2.7 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -5,9 +5,6 @@ require 'rake/rdoctask'
5
5
  desc 'Default: run unit tests.'
6
6
  task :default => :test
7
7
 
8
- desc 'Default: run unit tests.'
9
- task :default => :test
10
-
11
8
  desc 'Test muck-raker.'
12
9
  Rake::TestTask.new(:test) do |t|
13
10
  t.libs << 'lib'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.7
1
+ 0.2.8
@@ -68,7 +68,7 @@ class Muck::AggregationsController < ApplicationController
68
68
  @music_feeds = Service.build_music_feeds(terms, current_user)
69
69
  @general_feeds = Service.build_general_feeds(terms, current_user)
70
70
 
71
- @discovered_feeds = GoogleFeedRequest.find_feeds(terms)
71
+ @discovered_feeds = Overlord::GoogleFeedRequest.find_feeds(terms)
72
72
  @title = terms.titleize
73
73
  @terms = terms
74
74
 
@@ -90,7 +90,7 @@ class Muck::TopicsController < ApplicationController
90
90
 
91
91
  @general_feeds = Service.build_general_feeds(@terms, current_user, params[:service_ids])
92
92
 
93
- @discovered_feeds = GoogleFeedRequest.find_feeds(@terms)
93
+ @discovered_feeds = Overlord::GoogleFeedRequest.find_feeds(@terms)
94
94
 
95
95
  @feeds = @photo_feeds + @video_feeds + @bookmark_feeds + @music_feeds + @news_feeds + @blog_feeds + @search_feeds + @general_feeds + @discovered_feeds
96
96
 
@@ -98,14 +98,14 @@ class Muck::TopicsController < ApplicationController
98
98
 
99
99
  def load_feeds
100
100
  if @load_feeds_on_server
101
- @server_loaded_general_feeds = GoogleFeedRequest.load_feeds(@general_feeds + @discovered_feeds, @number_of_items)
102
- @server_loaded_photo_feeds = GoogleFeedRequest.load_feeds(@photo_feeds, @number_of_images)
103
- @server_loaded_video_feeds = GoogleFeedRequest.load_feeds(@video_feeds, @number_of_videos)
104
- @server_loaded_bookmark_feeds = GoogleFeedRequest.load_feeds(@bookmark_feeds, @number_of_items)
105
- @server_loaded_music_feeds = GoogleFeedRequest.load_feeds(@music_feeds, @number_of_items)
106
- @server_loaded_news_feeds = GoogleFeedRequest.load_feeds(@news_feeds, @number_of_items)
107
- @server_loaded_blog_feeds = GoogleFeedRequest.load_feeds(@blog_feeds, @number_of_items)
108
- @server_loaded_search_feeds = GoogleFeedRequest.load_feeds(@search_feeds, @number_of_items)
101
+ @server_loaded_general_feeds = Overlord::GoogleFeedRequest.load_feeds(@general_feeds + @discovered_feeds, @number_of_items)
102
+ @server_loaded_photo_feeds = Overlord::GoogleFeedRequest.load_feeds(@photo_feeds, @number_of_images)
103
+ @server_loaded_video_feeds = Overlord::GoogleFeedRequest.load_feeds(@video_feeds, @number_of_videos)
104
+ @server_loaded_bookmark_feeds = Overlord::GoogleFeedRequest.load_feeds(@bookmark_feeds, @number_of_items)
105
+ @server_loaded_music_feeds = Overlord::GoogleFeedRequest.load_feeds(@music_feeds, @number_of_items)
106
+ @server_loaded_news_feeds = Overlord::GoogleFeedRequest.load_feeds(@news_feeds, @number_of_items)
107
+ @server_loaded_blog_feeds = Overlord::GoogleFeedRequest.load_feeds(@blog_feeds, @number_of_items)
108
+ @server_loaded_search_feeds = Overlord::GoogleFeedRequest.load_feeds(@search_feeds, @number_of_items)
109
109
  if @show_combined
110
110
  @server_combined_general_feeds = Feed.combine_sort(@server_loaded_general_feeds)
111
111
  @server_combined_photo_feeds = Feed.combine_sort(@server_loaded_photo_feeds)
@@ -1,5 +1,13 @@
1
1
  module MuckRakerHelper
2
2
 
3
+ def tag_list(tags)
4
+ atags = tags.split(',')
5
+ # get rid of the first two items
6
+ atags.shift
7
+ atags.shift
8
+ atags.each_slice(2){|tag,frequency| yield tag,frequency }
9
+ end
10
+
3
11
  def tag_cloud(tag_list, classes)
4
12
  atags = tag_list.split(',')
5
13
  min = atags.shift.to_f
data/lib/muck_raker.rb CHANGED
@@ -9,7 +9,6 @@ ActionController::Base.send :helper, MuckRakerHelper
9
9
  ActionController::Base.send :helper, MuckRakerFeedsHelper
10
10
  ActionController::Base.send :helper, MuckRakerServicesHelper
11
11
  ActionController::Base.send :helper, MuckRakerAggregationsHelper
12
- ActionController::Base.send :helper, MuckRakerGoogleHelper
13
12
 
14
13
  ActiveRecord::Base.class_eval { include MuckRaker::Exceptions }
15
14
  ActiveRecord::Base.class_eval { include ActiveRecord::Acts::MuckFeedParent }
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.2.7"
8
+ s.version = "0.2.8"
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-29}
12
+ s.date = %q{2009-10-31}
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 = [
@@ -35,7 +35,6 @@ Gem::Specification.new do |s|
35
35
  "app/controllers/muck/visits_controller.rb",
36
36
  "app/helpers/muck_raker_aggregations_helper.rb",
37
37
  "app/helpers/muck_raker_feeds_helper.rb",
38
- "app/helpers/muck_raker_google_helper.rb",
39
38
  "app/helpers/muck_raker_helper.rb",
40
39
  "app/helpers/muck_raker_services_helper.rb",
41
40
  "app/models/aggregation.rb",
@@ -45,7 +44,6 @@ Gem::Specification.new do |s|
45
44
  "app/models/entry.rb",
46
45
  "app/models/feed.rb",
47
46
  "app/models/feed_parent.rb",
48
- "app/models/google_feed_request.rb",
49
47
  "app/models/identity_feed.rb",
50
48
  "app/models/oai_endpoint.rb",
51
49
  "app/models/raker_mailer.rb",
@@ -99,14 +97,6 @@ Gem::Specification.new do |s|
99
97
  "app/views/feeds/new_oai_rss.html.erb",
100
98
  "app/views/feeds/show.html.erb",
101
99
  "app/views/feeds/unban.html.erb",
102
- "app/views/google/_combined_feed.html.erb",
103
- "app/views/google/_dynamic_feeds_vertical.html.erb",
104
- "app/views/google/_feed.html.erb",
105
- "app/views/google/_feed_search.html.erb",
106
- "app/views/google/_feeds_scripts.html.erb",
107
- "app/views/google/_hot_trends.html.erb",
108
- "app/views/google/_search.html.erb",
109
- "app/views/google/_slide_show.html.erb",
110
100
  "app/views/identity_feeds/_available_service_categories.html.erb",
111
101
  "app/views/identity_feeds/_form.html.erb",
112
102
  "app/views/identity_feeds/_services_for_user.html.erb",
@@ -888,7 +878,6 @@ Gem::Specification.new do |s|
888
878
  "test/rails_root/test/unit/entry_test.rb",
889
879
  "test/rails_root/test/unit/feed_parent_test.rb",
890
880
  "test/rails_root/test/unit/feed_test.rb",
891
- "test/rails_root/test/unit/google_feed_request_test.rb",
892
881
  "test/rails_root/test/unit/identity_feed_test.rb",
893
882
  "test/rails_root/test/unit/oai_endpoint_test.rb",
894
883
  "test/rails_root/test/unit/raker_mailer_test.rb",
@@ -24,6 +24,8 @@ Rails::Initializer.run do |config|
24
24
  config.gem "muck-feedbag", :lib => "feedbag", :source => "http://gems.github.com"
25
25
  config.gem "pauldix-feedzirra", :lib => 'feedzirra', :source => "http://gems.github.com"
26
26
  config.gem "httparty"
27
+ config.gem "river"
28
+ config.gem "overlord"
27
29
  config.gem "friendly_id", :version => '>=2.1.3'
28
30
  config.gem 'muck-engine', :lib => 'muck_engine'
29
31
  config.gem 'muck-users', :lib => 'muck_users'
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.2.7
4
+ version: 0.2.8
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-29 00:00:00 -06:00
12
+ date: 2009-10-31 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -150,7 +150,6 @@ files:
150
150
  - app/controllers/muck/visits_controller.rb
151
151
  - app/helpers/muck_raker_aggregations_helper.rb
152
152
  - app/helpers/muck_raker_feeds_helper.rb
153
- - app/helpers/muck_raker_google_helper.rb
154
153
  - app/helpers/muck_raker_helper.rb
155
154
  - app/helpers/muck_raker_services_helper.rb
156
155
  - app/models/aggregation.rb
@@ -160,7 +159,6 @@ files:
160
159
  - app/models/entry.rb
161
160
  - app/models/feed.rb
162
161
  - app/models/feed_parent.rb
163
- - app/models/google_feed_request.rb
164
162
  - app/models/identity_feed.rb
165
163
  - app/models/oai_endpoint.rb
166
164
  - app/models/raker_mailer.rb
@@ -214,14 +212,6 @@ files:
214
212
  - app/views/feeds/new_oai_rss.html.erb
215
213
  - app/views/feeds/show.html.erb
216
214
  - app/views/feeds/unban.html.erb
217
- - app/views/google/_combined_feed.html.erb
218
- - app/views/google/_dynamic_feeds_vertical.html.erb
219
- - app/views/google/_feed.html.erb
220
- - app/views/google/_feed_search.html.erb
221
- - app/views/google/_feeds_scripts.html.erb
222
- - app/views/google/_hot_trends.html.erb
223
- - app/views/google/_search.html.erb
224
- - app/views/google/_slide_show.html.erb
225
215
  - app/views/identity_feeds/_available_service_categories.html.erb
226
216
  - app/views/identity_feeds/_form.html.erb
227
217
  - app/views/identity_feeds/_services_for_user.html.erb
@@ -1024,7 +1014,6 @@ test_files:
1024
1014
  - test/rails_root/test/unit/entry_test.rb
1025
1015
  - test/rails_root/test/unit/feed_parent_test.rb
1026
1016
  - test/rails_root/test/unit/feed_test.rb
1027
- - test/rails_root/test/unit/google_feed_request_test.rb
1028
1017
  - test/rails_root/test/unit/identity_feed_test.rb
1029
1018
  - test/rails_root/test/unit/oai_endpoint_test.rb
1030
1019
  - test/rails_root/test/unit/raker_mailer_test.rb
@@ -1,253 +0,0 @@
1
- module MuckRakerGoogleHelper
2
-
3
- # Render a google custom search control. If feeds are provided then the search will be restricted to the
4
- # 'display_url' for each feed. If search_for is specified then a default search will be executed.
5
- # It is not recommended that you provide feeds and locale since the overlap between the feeds provided
6
- # and the languages might be nothing.
7
- # Examples:
8
- #
9
- # Create a custom search over a specific set of feeds:
10
- # <%= google_search('Google Search (Search within these results)', [], '', %w{web}, 'google_restricted_search') %>
11
- #
12
- # Create a general google search based on the current locale:
13
- # <%= google_search('Google Search', [], @terms, %w{web video blog news image local book patent}, 'google_search', I18n.locale) %>
14
- #
15
- # feeds: An array of feeds to render each with a property 'display_uri' defined
16
- # search_for: Terms to search for by default. If none are specified then no default search will be performed.
17
- # search_types: Types of google searches to add to the dialog. Valid values are web video blog news image local book patent
18
- # content_id: Name of the div that will hold the widget google generates.
19
- # If this method is called more than once on a given page then you will need to
20
- # specify different content_ids for each call.
21
- # locale: Locale to restrict searches. For example, to restrict the search to only German sites specify 'de'
22
- # A complete set of valid Google languages can be found here:
23
- # http://code.google.com/apis/ajaxlanguage/documentation/#SupportedLanguages
24
- # For a list of valid codes you can also look at the babelphish gem. Codes can be found in languages.rb.
25
- def google_search(title, feeds = [], search_for = '', search_types = %w{web video blog news image local book patent}, content_id = 'google_search', locale = nil)
26
- render :partial => 'google/search', :locals => { :title => title,
27
- :feeds => feeds,
28
- :search_for => search_for,
29
- :search_types => search_types,
30
- :content_id => content_id,
31
- :locale => locale }
32
- end
33
-
34
- # Utility method for generating scripts required to to build google search
35
- # type: Type of Google search. Should be one of web video blog news image local book patent
36
- # feeds: An array of feeds to render each with a property 'display_uri' defined
37
- # locale: Locale to restrict searches. For example, to restrict the search to only German sites specify 'de'
38
- # A complete set of valid Google languages can be found here:
39
- # http://code.google.com/apis/ajaxlanguage/documentation/#SupportedLanguages
40
- # For a list of valid codes you can also look at the babelphish gem. Codes can be found in languages.rb.
41
- def google_typed_search(type, feeds = [], locale = nil)
42
- content = "var #{type}Search = new google.search.#{type.capitalize}Search();\n"
43
- if !['video', 'blog'].include?(type)
44
- if !locale.blank?
45
- content << "#{type}Search.setRestriction(google.search.Search.RESTRICT_EXTENDED_ARGS, {lr:'lang_#{locale}'});\n"
46
- end
47
- end
48
- if !['video', 'local', 'patent', 'book'].include?(type)
49
- feeds.each do |feed|
50
- if !feed.display_uri.blank?
51
- content << "#{type}Search.setSiteRestriction('#{feed.display_uri}');\n"
52
- end
53
- end
54
- end
55
- content << "searchControl.addSearcher(#{type}Search);\n"
56
- end
57
-
58
- # Render feeds using Google's api
59
- # feeds: Feed object.
60
- # show_controls: Indicates whether or not to show editing controls. ie Remove
61
- # number_of_items: Number of items to display for the given feed.
62
- # number_of_images: Number of images to get from the feed.
63
- # number_of_videos: Number of videos to get from the feed.
64
- # use_uri_for_control: If set to true then a hidden field will be generated containing the feed's uri. If false then the hidden field will contain the feed's service id. This is used to
65
- # regenerate the feed after submission to the server.
66
- # javascript_callback: Name of a javascript method to call after the feed has finished loading. The
67
- # method should accept the feed uri and the content id. ie feed_callback(uri, content_id).
68
- def google_feeds(feeds, show_controls = false, number_of_items = 6, number_of_images = 20, number_of_videos = 6,
69
- use_uri_for_control = false, run_load_scripts = false, javascript_callback = 'google_load_complete')
70
- render :partial => 'google/feed', :collection => feeds, :locals => {:number_of_items => number_of_items,
71
- :number_of_images => number_of_images,
72
- :number_of_videos => number_of_videos,
73
- :javascript_callback => javascript_callback,
74
- :show_controls => show_controls,
75
- :use_uri_for_control => use_uri_for_control,
76
- :run_load_scripts => run_load_scripts}
77
- end
78
-
79
- # Render combined feed using Google's api
80
- #
81
- # feeds: Array of feeds that have attribute 'uri' defined.
82
- # content_id: Name of the div that will hold the widget google generates.
83
- # If this method is called more than once on a given page then you will need to
84
- # specify different content_ids for each call.
85
- # javascript_callback: Name of a javascript method to call after the feed has finished loading. The
86
- # method should accept the feed uri and the content id. ie feed_callback(uri, content_id).
87
- def google_combined_feeds(feeds, content_id = 'google_combined_feed', javascript_callback = nil)
88
- render :partial => 'google/combined_feed', :locals => { :feeds => feeds, :content_id => content_id, :javascript_callback => javascript_callback }
89
- end
90
-
91
- # Render a google dynamic feed control.
92
- #
93
- # feeds: An array of feeds to render each with a property 'title' and 'uri' defined
94
- # content_id: Name of the div that will hold the widget google generates.
95
- # If this method is called more than once on a given page then you will need to
96
- # specify different content_ids for each call.
97
- # options: A hash containing the values to pass to the Google widget. The available options are defined here:
98
- # http://www.google.com/uds/solutions/dynamicfeed/reference.html.
99
- def google_dynamic_feeds_vertical(feeds,
100
- content_id = 'dynamic_feed_vertical_content',
101
- options = { :numResults => 20, :stacked => true, :horizontal => false })
102
- render :partial => 'google/dynamic_feeds_vertical', :locals => { :feeds => feeds, :content_id => content_id, :options => options }
103
- end
104
-
105
- # Find and output feeds related to the given query
106
- #
107
- # query: A tag or search query to pass to Google. Google will find feeds that match this value.
108
- # content_id: Name of the div that will hold the widget google generates.
109
- # If this method is called more than once on a given page then you will need to
110
- # specify different content_ids for each call.
111
- def google_feed_search(query, content_id = 'feed_search_content')
112
- render :partial => 'google/feed_search', :locals => { :query => query, :content_id => content_id }
113
- end
114
-
115
- # Generate a slide show from a feed
116
- # feed: Url for which to generate the feed.
117
- # content_id: Name of the div that will hold the widget google generates.
118
- # If this method is called more than once on a given page then you will need to
119
- # specify different content_ids for each call.
120
- # options: A hash containing the values to pass to the Google widget. The available options are defined here:
121
- # http://www.google.com/uds/solutions/slideshow/index.html
122
- def google_slide_show(feed,
123
- content_id = 'slide_show_content',
124
- options = { :displayTime => 2000, :transistionTime => 600, :scaleImages => true, :fullControlPanel => true })
125
- render :partial => 'google/slide_show', :locals => { :feed => feed, :content_id => content_id, :options => options }
126
- end
127
-
128
- # Given a feed attempts to assign an appropriate class
129
- def feed_class(feed)
130
- if feed.service.photo?
131
- "feed-photos"
132
- elsif feed.service.bookmark?
133
- "feed-bookmarks"
134
- elsif feed.service.video?
135
- "feed-videos"
136
- elsif feed.service.music?
137
- "feed-music"
138
- end
139
- end
140
-
141
- # Generates a valid dom id for the feed
142
- def feed_content_id(feed)
143
- "feed_#{feed.id}_#{feed.title.parameterize}_#{feed.service.name.parameterize}".gsub('+', '-')
144
- end
145
-
146
- # Outputs the appropriate script for handling the google response once the feed is loaded
147
- # feed: Url for which to generate the feed.
148
- # content_id: Name of the div that will hold the widget google generates.
149
- # If this method is called more than once on a given page then you will need to
150
- # specify different content_ids for each call.
151
- # javascript_callback: Name of a javascript method to call after the feed has finished loading. The
152
- # method should accept the feed uri and the content id. ie feed_callback(uri, content_id).
153
- def google_muck_load_script(feed, content_id = nil, javascript_callback = nil)
154
- if feed.service.photo?
155
- google_load_images_script(javascript_callback, feed.uri, content_id)
156
- elsif feed.service.bookmark?
157
- google_load_bookmarks_script(javascript_callback, feed.uri, content_id)
158
- elsif feed.service.video?
159
- google_load_videos_script(javascript_callback, feed.uri, content_id)
160
- elsif feed.service.music?
161
- # TODO need to get music feeds into tag system so that we can search for music feeds and then integrate in a way that can play the tunes.
162
- google_load_entries_script(javascript_callback, feed.uri, content_id)
163
- else
164
- google_load_entries_script(javascript_callback, feed.uri, content_id)
165
- end
166
- end
167
-
168
- def google_muck_load_callback_script(feed, content_id, number_of_items = 4, number_of_images = 6, number_of_videos = 6)
169
- if feed.service.photo?
170
- "google_load_images('#{feed.uri}', '#{content_id}', #{number_of_images});"
171
- elsif feed.service.bookmark?
172
- "google_load_bookmarks('#{feed.uri}', '#{content_id}', #{number_of_items});"
173
- elsif feed.service.video?
174
- "google_load_videos('#{feed.uri}', '#{content_id}', #{number_of_videos});"
175
- elsif feed.service.music?
176
- "google_load_entries('#{feed.uri}', '#{content_id}', #{number_of_items});"
177
- else
178
- "google_load_entries('#{feed.uri}', '#{content_id}', #{number_of_items});"
179
- end
180
- end
181
-
182
- def google_load_videos_script(javascript_callback, uri, content_id)
183
- google_load_template_script 'google_load_videos', javascript_callback, uri, content_id do
184
- %Q{var link = jQuery(item.content).find('img').parent('a');
185
- link.attr('rel', '#{content_id}');
186
- link.addClass('feed-video');
187
- jQuery('#' + content_id).append(link);}
188
- end
189
- end
190
-
191
- def google_load_images_script(javascript_callback, uri, content_id)
192
- google_load_template_script 'google_load_images', javascript_callback, uri, content_id do
193
- %Q{var link = jQuery(item.content).find('img').parent('a');
194
- link.attr('rel', '#{content_id}');
195
- link.addClass('feed-photo');
196
- jQuery('#' + content_id).append(link);}
197
- end
198
- end
199
-
200
- def google_load_entries_script(javascript_callback, uri, content_id)
201
- google_load_template_script 'google_load_entries', javascript_callback, uri, content_id do
202
- %Q{var status_class = 'even';
203
- if(i%2 > 0) { status_class = 'odd'; }
204
- jQuery('#' + content_id).append('<div class="hentry ' + status_class + '"><h4 class="title"><a class="entry-link" href="#" target="blank">' + item.title + '</a><span class="entry-close"><a class="entry-link-close" href="#">#{t('muck.raker.close')}</a></span></h4><div class="entry">' + item.content + ' <p><a href="' + item.link + '">#{t('muck.raker.read_more')}</a></p></div></div>');}
205
- end
206
- end
207
-
208
- def google_load_bookmarks_script(javascript_callback, uri, content_id)
209
- google_load_template_script 'google_load_bookmarks', javascript_callback, uri, content_id do
210
- %Q{var status_class = 'even';
211
- if(i%2 > 0) { status_class = 'odd'; }
212
- jQuery('#' + content_id).append('<div class="hentry ' + status_class + '"><h4 class="title"><a class="bookmark-link" href="' + item.link + '" target="_blank">' + item.title + '</a></h4></div>');}
213
- end
214
- end
215
-
216
- # Generates the template code used by all the calls to google.
217
- def google_load_template_script(method_name, javascript_callback, uri, content_id)
218
- included_name = "@#{method_name}_included"
219
- return '' if instance_variable_get(included_name) rescue false
220
- instance_variable_set(included_name, true)
221
- %Q{<script type="text/javascript">
222
- function #{method_name}(uri, content_id, number_of_items){
223
- jQuery('#' + content_id).html('');
224
- var feed = new google.feeds.Feed(uri);
225
- feed.setNumEntries(number_of_items);
226
- feed.load(function(result) {
227
- if (!result.error) {
228
- jQuery.each(result.feed.entries, function(i,item){
229
- #{yield}
230
- #{javascript_callback}('#{uri}', '#{content_id}');
231
- });
232
- }
233
- if (result.error || result.feed.entries.length <= 0) {
234
- jQuery('#' + content_id).append('<div class="hentry">#{t('muck.raker.no_entries_found')}</div>');
235
- }
236
- });
237
- }
238
- </script>}
239
- end
240
-
241
- # Renders a partial with the latest trends from google.
242
- def google_hot_trends(limit = 10)
243
- feed = Feed.fetch_feed('http://www.google.com/trends/hottrends/atom/hourly')
244
- result = Nokogiri::HTML(feed.entries[0].content)
245
- google_hot_trends_terms = result.css('a').collect{ |a| change_chars(a.text) }.compact
246
- render :partial => 'google/hot_trends', :locals => { :google_hot_trends_terms => google_hot_trends_terms[0, limit] }
247
- end
248
-
249
- def change_chars(term)
250
- term.gsub('+', ' ').gsub('.', '-')
251
- end
252
-
253
- end
@@ -1,114 +0,0 @@
1
- # Google ajax feed api reference:
2
- # http://code.google.com/apis/ajaxfeeds/documentation/reference.html
3
- #
4
- # Google code playground:
5
- # http://code.google.com/apis/ajax/playground/?exp=search#load_feed
6
- #
7
- class GoogleFeedRequest
8
- include HTTParty
9
- format :json
10
-
11
- # Initialize Google Request.
12
- # Parameters:
13
- # api_key_id: Valid Google access key (optional)
14
- def initialize(api_key_id = nil)
15
- @api_key_id = api_key_id
16
- end
17
-
18
- # Lookup a given feed.
19
- def self.lookup_feed(uri)
20
- get('http://ajax.googleapis.com/ajax/services/feed/lookup', :query => build_google_query({:q => uri}))
21
- end
22
-
23
- # Requests entries for a single feed
24
- #
25
- # uri: Uri of the feed to load
26
- # number_of_items: Number of items to load from the feed
27
- def self.load_feed(uri, number_of_items = 5)
28
- get('http://ajax.googleapis.com/ajax/services/feed/load', :query => build_google_query({:q => uri, :num => number_of_items}))
29
- end
30
-
31
- # Requests a set of feeds from Google
32
- #
33
- # feeds: An array of objects with the attributes 'uri' and 'service_id' defined
34
- def self.load_feeds(feeds, number_of_items = 5)
35
- feeds = feeds.collect do |feed|
36
- json = load_feed(feed.uri, number_of_items)
37
- new_feed = convert_google_feed_json_to_feed(feed, json)
38
- new_feed.entries << convert_google_feed_json_to_entries(new_feed, json).compact if new_feed
39
- new_feed
40
- end
41
- if feeds
42
- feeds.compact
43
- else
44
- []
45
- end
46
- end
47
-
48
- # Converts json returned from google into a feed object
49
- def self.convert_google_feed_json_to_feed(feed, json)
50
- if json['responseStatus'] == 200
51
- if json['responseData']['feed']
52
- Feed.new( :uri => feed.uri,
53
- :service_id => feed.service_id,
54
- :display_uri => json['responseData']['feed']['link'],
55
- :title => json['responseData']['feed']['title'],
56
- :service => feed.service)
57
- end
58
- end
59
- end
60
-
61
- # Converts json returned from google into an array of entries
62
- def self.convert_google_feed_json_to_entries(feed, json)
63
- if json['responseData']['feed']['entries']
64
- json['responseData']['feed']['entries'].collect do |entry|
65
- published_at = DateTime.parse(entry['publishedDate']) rescue DateTime.now - 1.day
66
- Entry.new(:permalink => entry['link'],
67
- :author => entry['author'],
68
- :title => entry['title'],
69
- :description => entry['contentSnippet'],
70
- :content => entry['content'],
71
- :published_at => published_at,
72
- :tag_list => entry['categories'],
73
- :direct_link => entry['link'],
74
- :feed => feed)
75
- end
76
- end
77
- end
78
-
79
- # Search for feeds using google. This will return
80
- # a collection of 'Feed' objects
81
- def self.find_feeds(query)
82
- query = query.join('+') if query.is_a?(Array)
83
- feed_response = find_google_feeds(query)
84
- if 200 == feed_response['responseStatus']
85
- convert_google_find_feeds_json_to_feeds(feed_response)
86
- else
87
- []
88
- end
89
- end
90
-
91
- # Search for feeds using google. This will return
92
- # a hash with the results
93
- def self.find_google_feeds(query, number_of_items = 5)
94
- get('http://ajax.googleapis.com/ajax/services/feed/find', :query => build_google_query({:q => query}))
95
- end
96
-
97
- # convert the result of a google query to 'Feed' objects
98
- def self.convert_google_find_feeds_json_to_feeds(google_feeds)
99
- google_feeds['responseData']['entries'].collect do |google_feed|
100
- Feed.new( :uri => google_feed['url'],
101
- :display_uri => google_feed['link'],
102
- :title => google_feed['title'],
103
- :service_id => Service.find_service_by_uri(google_feed['link']).id)
104
- end
105
- end
106
-
107
- # Add standard items to the google query
108
- def self.build_google_query(query_options)
109
- query_options[:v] = '1.0'
110
- query_options[:key] = GlobalConfig.google_ajax_api_key if GlobalConfig.google_ajax_api_key
111
- query_options
112
- end
113
-
114
- end
@@ -1,54 +0,0 @@
1
- <% content_for :head do -%>
2
- <%= google_ajax_api_scripts -%>
3
- <%= google_load_feeds -%>
4
- <% end -%>
5
-
6
- <script type="text/javascript">
7
- entries = [];
8
- function feed_loaded(result) {
9
- if (!result.error) {
10
- jQuery('#<%= content_id %> .waiting').hide();
11
- jQuery('#<%= content_id %> ul').html('');
12
- new_entries = result.feed.entries;
13
- for (var i=0; i<new_entries.length; i++){
14
- new_entries[i].feed = result.feed;
15
- }
16
- entries = jQuery.merge(entries, new_entries);
17
- entries = entries.sort(function(a,b){
18
- return a.publishedDate > b.publishedDate;
19
- });
20
- for (var i=0; i<entries.length; i++) {
21
- var html = '<li class="feed-item" style="background: transparent url(/images/service_icons/24/' + get_service_name(entries[i]) + ') no-repeat scroll left top;">';
22
- html += '<div class="feed-title"><a href="' + entries[i].link + '" target="_blank">' + entries[i].title + '</a></div>';
23
- html += '<div class="feed-content" style="display:none;">';
24
- html += '<h3><a href="' + entries[i].link + '" target="_blank">' + entries[i].title + '</a></h3>';
25
- html += entries[i].content;
26
- html += '</div>';
27
- html += '</li>';
28
- jQuery('#<%= content_id %> ul').append(html);
29
- }
30
- apply_show_entry_content();
31
- <%= "#{javascript_callback}('#{content_id}');" if javascript_callback -%>
32
- }
33
- }
34
- google.setOnLoadCallback(function(){
35
- <% feeds.each do |feed| -%>
36
- new google.feeds.Feed("<%=feed.uri%>").load(feed_loaded);
37
- <% end -%>
38
- });
39
-
40
- function get_service_name(entry) {
41
- var services = eval(<%= Service.all.to_json(:only => [ :uri_key, :icon ]) %>);
42
- for(var i=0; i<services.length; i++){
43
- if(services[i].uri_key && (entry.link.indexOf(services[i].uri_key) >= 0 || entry.feed.link.indexOf(services[i].uri_key) >= 0)){
44
- return services[i].icon;
45
- }
46
- }
47
- return 'feed.png';
48
- }
49
- </script>
50
-
51
- <div id="<%= content_id %>" class="combined-feed">
52
- <span class="waiting"><%= t('muck.raker.loading_message') %></span>
53
- <ul class="combined-feed-list"></ul>
54
- </div>
@@ -1,22 +0,0 @@
1
- <% content_for :head do -%>
2
- <%= google_ajax_api_scripts -%>
3
- <script src="http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.js" type="text/javascript"></script>
4
- <style type="text/css">
5
- @import url("http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.css");
6
- </style>
7
- <%= google_load_feeds -%>
8
- <% end -%>
9
- <% content_for :javascript do -%>
10
- google.setOnLoadCallback(function() {
11
- var feeds = [
12
- <%= feeds.collect { |feed|
13
- "{ title: '#{feed.title}', url: '#{feed.uri}' }"
14
- }.join(',') -%>
15
- ];
16
- new GFdynamicFeedControl(feeds, '<%= content_id %>', <%= options.to_json %>);
17
- });
18
- <% end -%>
19
- <div id="<%= content_id %>">
20
- <%= t('muck.raker.loading_message') %>
21
- <img src="/images/spinner.gif" alt="<%= t('muck.raker.loading_image') %>" />
22
- </div>
@@ -1,43 +0,0 @@
1
- <% content_id ||= feed_content_id(feed) -%>
2
- <% content_for :head do -%>
3
- <%= google_ajax_api_scripts -%>
4
- <%= google_load_feeds -%>
5
- <%= google_muck_load_script(feed, content_id, javascript_callback) %>
6
- <% end -%>
7
-
8
- <% if run_load_scripts -%>
9
- <script type="text/javascript">
10
- <%= google_muck_load_callback_script(feed, content_id, number_of_items, number_of_images, number_of_videos) %>
11
- setup_delete_links();
12
- </script>
13
- <% else -%>
14
- <% content_for :javascript do -%>
15
- google.setOnLoadCallback(function() {
16
- <%= google_muck_load_callback_script(feed, content_id, number_of_items, number_of_images, number_of_videos) %>
17
- });
18
- <% end -%>
19
- <% end -%>
20
-
21
- <div class="feed">
22
- <div class="feed-header">
23
- <h3 <%= service_icon_background(feed.service) %>>
24
- <%= link_to "#{feed.title.humanize}", feed.display_uri, :target => 'blank' %>
25
- <%= link_to "(rss)", feed.uri, :target => 'blank' %>
26
- <% if defined?(show_controls) && show_controls -%>
27
- <span class="remove-feed feed-control">
28
- <%= link_to t('muck.raker.remove'), aggregation_feed_path(0, :aggregation_id => @aggregation.id, :feed_id => feed.id), :class => 'delete-link' %>
29
- </span>
30
- <% if use_uri_for_control -%>
31
- <%= hidden_field_tag "uris[]", feed.uri -%>
32
- <% else -%>
33
- <%= hidden_field_tag "service_ids[]", feed.service.id -%>
34
- <% end -%>
35
- <% end -%>
36
- </h3>
37
- </div>
38
- <div class="feed-content">
39
- <div id="<%= content_id %>" class="feed-item <%= feed_class(feed) %>">
40
- <span class="waiting"><%= t('muck.raker.loading_message') %></span>
41
- </div>
42
- </div>
43
- </div>
@@ -1,26 +0,0 @@
1
- <% content_for :head do -%>
2
- <%= google_ajax_api_scripts -%>
3
- <%= google_load_feeds -%>
4
- <% end -%>
5
- <% content_for :javascript do -%>
6
- google.setOnLoadCallback(function() {
7
- google.feeds.findFeeds('<%= query %>', findDone);
8
- });
9
- function findDone(result) {
10
- // Make sure we didn't get an error.
11
- if (!result.error) {
12
- // Get content div
13
- var content = document.getElementById('<%= content_id %>');
14
- var html = '';
15
- for (var i = 0; i < result.entries.length; i++) {
16
- var entry = result.entries[i];
17
- html += '<p><a href="' + entry.url + '">' + entry.title + '</a></p>';
18
- }
19
- content.innerHTML = html;
20
- }
21
- }
22
- <% end -%>
23
- <div id="<%= content_id %>">
24
- <%= t('muck.raker.loading_message') %>
25
- <img src="/images/spinner.gif" alt="Loading content image" />
26
- </div>
@@ -1,36 +0,0 @@
1
- <% content_for :javascript do -%>
2
- function google_load_complete(uri, content_id) {
3
- jQuery('.hentry .entry').hide();
4
- jQuery('.hentry h4 .entry-close').hide();
5
- jQuery('.hentry h4 a.entry-link-close').click(function(){
6
- jQuery(this).parent().parent().siblings('.entry').hide();
7
- jQuery(this).parent().hide();
8
- return false;
9
- });
10
- jQuery('.hentry h4 a.entry-link').click(function(){
11
- jQuery(this).parent().siblings('.entry').show();
12
- jQuery(this).siblings('.entry-close').show();
13
- return false;
14
- });
15
- }
16
- function setup_delete_links() {
17
- jQuery(".delete-link").click(function() {
18
- var container = jQuery(this).parents('div.feed');
19
- container.fadeOut(500, function() {
20
- jQuery(this).remove();
21
- });
22
- jQuery.post(jQuery(this).attr('href'), { '_method': 'delete', 'format': 'json' },
23
- function(data){
24
- var json = eval('(' + data + ')');
25
- if(!json.success){
26
- <%= jquery_message('#ajax-messages') %>
27
- }
28
- });
29
- return false;
30
- });
31
- }
32
- jQuery(document).ready(function() {
33
- google_load_complete('','');
34
- setup_delete_links();
35
- });
36
- <% end -%>
@@ -1,5 +0,0 @@
1
- <ul class="google-trends">
2
- <% google_hot_trends_terms.each do |term| -%>
3
- <li><%= link_to h(term).titleize, topic_path(CGI.escape(term)) %></li>
4
- <% end -%>
5
- </ul>
@@ -1,39 +0,0 @@
1
- <% content_for :head do -%>
2
- <%= google_ajax_api_scripts -%>
3
- <%= google_load_search -%>
4
- <% end -%>
5
- <script type="text/javascript">
6
- function google_load_search() {
7
- var searchControl = new google.search.SearchControl();
8
-
9
- <% search_types.each do |type| -%>
10
- <%= google_typed_search(type, feeds, locale) %>
11
- <% end -%>
12
-
13
- <% if GlobalConfig.google_ad_partner_pub -%>
14
- searchControl.enableAds('<%= GlobalConfig.google_ad_partner_pub %>');
15
- <% end -%>
16
-
17
- <% if search_types.length > 1 -%>
18
- var drawOptions = new google.search.DrawOptions();
19
- drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);
20
- searchControl.draw(document.getElementById("<%= content_id %>"), drawOptions);
21
- <% else -%>
22
- searchControl.draw(document.getElementById("<%= content_id %>"));
23
- <% end -%>
24
-
25
- searchControl.execute('<%=search_for%>');
26
- }
27
- google.setOnLoadCallback(google_load_search);
28
- </script>
29
- <div class="feed">
30
- <div class="feed-header">
31
- <h3 class="google-header"><%= title %></h3>
32
- </div>
33
- <div class="feed-content">
34
- <div id="<%= content_id %>" class="search-container">
35
- <span class="waiting"><%= t('muck.raker.loading_message') %></span>
36
- </div>
37
- </div>
38
- </div>
39
-
@@ -1,14 +0,0 @@
1
- <% content_for :head do -%>
2
- <%= google_ajax_api_scripts -%>
3
- <%= google_ajax_slideshow_scripts -%>
4
- <%= google_load_feeds -%>
5
- <% end -%>
6
- <% content_for :javascript do -%>
7
- google.setOnLoadCallback(function() {
8
- new GFslideShow("<%= feed.uri %>", "<%= content_id %>", <%= options.to_json %>);
9
- });
10
- <% end -%>
11
- <div id="<%= content_id %>" class="slide_show_content">
12
- <%= t('muck.raker.loading_message') %>
13
- <img src="/images/spinner.gif" alt="<%= t('muck.raker.loading_image') %>" />
14
- </div>
@@ -1,57 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper'
2
-
3
- class GoogleFeedRequestTest < ActiveSupport::TestCase
4
-
5
- context "google feed requests" do
6
-
7
- context "find feeds" do
8
- setup do
9
- @feeds = GoogleFeedRequest.find_feeds('ruby')
10
- end
11
- should "get feeds related to ruby" do
12
- assert @feeds.length > 0
13
- end
14
- should "build objects of type 'Feed'" do
15
- assert @feeds[0].is_a?(Feed)
16
- end
17
- end
18
-
19
- context "find feeds (raw results)" do
20
- setup do
21
- @feeds = GoogleFeedRequest.find_google_feeds('ruby')
22
- end
23
- should "get feeds related to ruby" do
24
- assert @feeds.length > 0
25
- end
26
- end
27
-
28
- context "lookup feed" do
29
- setup do
30
- @result = GoogleFeedRequest.lookup_feed('http://www.justinball.com')
31
- end
32
- should "discover rss feed using uri" do
33
- assert_equal 'http://www.justinball.com/feed/', @result['responseData']['url']
34
- end
35
- end
36
-
37
- context "load feed" do
38
- setup do
39
- @entries = GoogleFeedRequest.load_feed('http://www.justinball.com')
40
- end
41
- should "get entries from feed" do
42
- assert @entries.length > 0
43
- end
44
- end
45
-
46
- context "load an array of feeds" do
47
- setup do
48
- @feeds = [ Factory(:feed, :uri => 'http://www.justinball.com/feed'), Factory(:feed, :uri => 'http://www.engadget.com/rss.xml'), Factory(:feed, :uri => 'http://www.example.com') ]
49
- end
50
- should "load feeds" do
51
- @feeds = GoogleFeedRequest.load_feeds(@feeds)
52
- assert @feeds.entries.length > 0
53
- end
54
- end
55
- end
56
-
57
- end