feed_us_grabber 1.0.2 → 1.0.3
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/README.rdoc +13 -10
- data/lib/app/controllers/feed_us_grabber_controller.rb +9 -2
- data/lib/app/models/feed_us_grabber.rb +13 -8
- metadata +3 -3
data/README.rdoc
CHANGED
|
@@ -8,24 +8,24 @@ To be used with Rails 3.x and Ruby 1.9x. We're proud of our software, and we wa
|
|
|
8
8
|
|
|
9
9
|
Follow these steps to download and install the feed_us_grabber gem:
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
(1) In your rails application, edit your Gemfile to include:
|
|
12
12
|
gem 'feed_us_grabber'
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
(2) Run bundle install from the command line (this will download the feed_us_grabber to your environment)
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
(3) Open config/routes.rb and add following line:
|
|
17
17
|
match "rails_app/FeedUsGrabber" => "FeedUsGrabber#index"
|
|
18
18
|
** where rails_app is the root URL to your application. The match is case sensitive.
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
(4) Update environment.rb and include require 'net/http'
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
(5) Your installation is complete
|
|
23
23
|
|
|
24
24
|
== USAGE
|
|
25
|
-
|
|
25
|
+
(1) Add following line to each controller (or app/controllers/application_controller.rb):
|
|
26
26
|
include FeedUsGrabberHelper
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
(2) Add following code inside your controllers actions:
|
|
29
29
|
@grabber = feedUsGrabber(:FeedUsURL => '<FEED.US URL>',:FeedUsCacheInterval => FEED_INTERVAL, :FeedUsCacheIntervalLength => FEED_INTERVAL_LENGTH, :FeedUsCacheGroup => 'FEED CACHE GROUP NAME')
|
|
30
30
|
|
|
31
31
|
If you want to use FeedUsGrabber inside action index under controller "test" add following code inside action index of "test" controller
|
|
@@ -41,7 +41,7 @@ Follow these steps to download and install the feed_us_grabber gem:
|
|
|
41
41
|
@grabber = feedUsGrabber(:FeedUsURL => 'http://render.feed.us/Feed.aspx?g=00767d50-bde8-e111-9875-4040419a7f04')
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
(3) Inside the view of the action add the following code to render your content
|
|
45
45
|
<%= feedUsGrabberRender @grabber %>
|
|
46
46
|
|
|
47
47
|
Example
|
|
@@ -66,9 +66,12 @@ To clear cache goto following url
|
|
|
66
66
|
* Clear entire cache
|
|
67
67
|
http://rails_app/FeedUsGrabber?cachecommand=clearall
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
* Clear cache in specific folder
|
|
70
|
+
http://rails_app/FeedUsGrabber?cachecommand=clear&folder=myFolder (can also optionally include group=demo to clear the cache group demo under the myFolder directory)
|
|
71
|
+
|
|
72
|
+
:Note that if you receive a failure message that your IP is not authorized to clear the cache, add your IP to the ClientWhiteList in your controller (where xxx.xx.xx.xx is your IP)
|
|
70
73
|
def index
|
|
71
|
-
@grabber = feedUsGrabber(:FeedUsURL => 'http://render.feed.us/Feed.aspx?g=00767d50-bde8-e111-9875-4040419a7f04', :ClientWhiteList => '
|
|
74
|
+
@grabber = feedUsGrabber(:FeedUsURL => 'http://render.feed.us/Feed.aspx?g=00767d50-bde8-e111-9875-4040419a7f04', :ClientWhiteList => 'xxx.xx.xx.xx')
|
|
72
75
|
end
|
|
73
76
|
|
|
74
77
|
== LOCATION OF CACHE
|
|
@@ -27,6 +27,10 @@ class FeedUsGrabberController < ActionController::Base
|
|
|
27
27
|
unless params[:group].nil?
|
|
28
28
|
@mArgs[:FeedUsCacheGroup] = params[:group]
|
|
29
29
|
end
|
|
30
|
+
|
|
31
|
+
unless params[:folder].nil?
|
|
32
|
+
@mArgs[:FeedUsCacheFolder] = params[:folder]
|
|
33
|
+
end
|
|
30
34
|
|
|
31
35
|
unless params[:debug].nil?
|
|
32
36
|
@mArgs[:Debug] = params[:debug] == "1"
|
|
@@ -42,6 +46,8 @@ class FeedUsGrabberController < ActionController::Base
|
|
|
42
46
|
|
|
43
47
|
if @mArgs[:CacheCommand] == 'clear' && @mArgs[:FeedUsCacheGroup]
|
|
44
48
|
fetch = true
|
|
49
|
+
elsif @mArgs[:CacheCommand] == 'clear' && @mArgs[:FeedUsCacheFolder]
|
|
50
|
+
fetch = true
|
|
45
51
|
else
|
|
46
52
|
fetch = false
|
|
47
53
|
end
|
|
@@ -125,11 +131,12 @@ class FeedUsGrabberController < ActionController::Base
|
|
|
125
131
|
included = true
|
|
126
132
|
else
|
|
127
133
|
# User can specify additional IP's to add to whitelist
|
|
128
|
-
|
|
134
|
+
grabber = FeedUsGrabber.new
|
|
135
|
+
configuredClientWhiteList = grabber.getClientWhiteList
|
|
129
136
|
unless configuredClientWhiteList.nil? || configuredClientWhiteList.empty?
|
|
130
137
|
@mClientWhiteList.push(configuredClientWhiteList)
|
|
131
138
|
end
|
|
132
|
-
|
|
139
|
+
AddToDebugOutput(grabber.getDebugOutput)
|
|
133
140
|
AddToDebugOutput("Checking if IP #{@mClientIp} is in ClientWhiteList #{@mClientWhiteList.to_s}")
|
|
134
141
|
|
|
135
142
|
if @mClientWhiteList.nil? == false && @mClientWhiteList.include?(@mClientIp) == true
|
|
@@ -140,11 +140,13 @@ class FeedUsGrabber
|
|
|
140
140
|
if @mstrCacheCommand.nil? || @mstrCacheCommand == ''
|
|
141
141
|
if (!self.cachedFileExists) or self.cacheFileIsExpired
|
|
142
142
|
self.createCacheFile
|
|
143
|
-
end
|
|
143
|
+
end
|
|
144
144
|
else
|
|
145
145
|
if @mstrCacheCommand == "clear"
|
|
146
146
|
if @mstrCacheGroup != ''
|
|
147
147
|
self.clearCacheGroupFiles(@mstrCacheGroup)
|
|
148
|
+
elsif @mstrCacheFolder
|
|
149
|
+
self.clearCacheFolder(@mstrCacheFolder)
|
|
148
150
|
end
|
|
149
151
|
end
|
|
150
152
|
if @mstrCacheCommand == 'clearall' || @mstrCacheCommand == CACHE_COMMAND_FORCE
|
|
@@ -234,7 +236,7 @@ class FeedUsGrabber
|
|
|
234
236
|
end
|
|
235
237
|
|
|
236
238
|
def makeDirectory(dir, mode = 0755)
|
|
237
|
-
if File.directory?(dir) || FileUtils.
|
|
239
|
+
if File.directory?(dir) || FileUtils.mkdir_p(dir)
|
|
238
240
|
return true
|
|
239
241
|
end
|
|
240
242
|
return false
|
|
@@ -286,7 +288,7 @@ class FeedUsGrabber
|
|
|
286
288
|
logfile = File.open(File.join(Rails.root.to_s,'log','FeedUsGrabber.log'),'a');
|
|
287
289
|
grabber_logger = FeedUsGrabberLogger.new(logfile)
|
|
288
290
|
grabber_logger.error("Unable to render/open #{@mstrCachedFileName}")
|
|
289
|
-
logfile.close
|
|
291
|
+
logfile.close
|
|
290
292
|
end
|
|
291
293
|
end
|
|
292
294
|
|
|
@@ -299,19 +301,21 @@ class FeedUsGrabber
|
|
|
299
301
|
logfile.close
|
|
300
302
|
return
|
|
301
303
|
end
|
|
304
|
+
logMessage = "Clearing cache at group #{group} at path #{File.join(@mstrCacheFolder,group)}"
|
|
305
|
+
appendDebugOutput(logMessage)
|
|
302
306
|
logfile = File.open(File.join(Rails.root.to_s,'log','FeedUsGrabber.log'),'a');
|
|
303
307
|
grabber_logger = FeedUsGrabberLogger.new(logfile)
|
|
304
|
-
grabber_logger.info(
|
|
308
|
+
grabber_logger.info(logMessage)
|
|
305
309
|
logfile.close
|
|
306
310
|
self.clearCacheFolder(File.join(@mstrCacheFolder,group))
|
|
307
311
|
end
|
|
308
312
|
|
|
309
313
|
def clearAllCachedFiles
|
|
310
|
-
|
|
311
|
-
appendDebugOutput(
|
|
314
|
+
logMessage = "Clearing all caches at path = #{@mstrCacheFolder}"
|
|
315
|
+
appendDebugOutput(logMessage)
|
|
312
316
|
logfile = File.open(File.join(Rails.root.to_s,'log','FeedUsGrabber.log'),'a');
|
|
313
317
|
grabber_logger = FeedUsGrabberLogger.new(logfile)
|
|
314
|
-
grabber_logger.info(
|
|
318
|
+
grabber_logger.info(logMessage)
|
|
315
319
|
logfile.close
|
|
316
320
|
self.clearCacheFolder(@mstrCacheFolder);
|
|
317
321
|
end
|
|
@@ -320,7 +324,7 @@ class FeedUsGrabber
|
|
|
320
324
|
canConnect = canConnectToFeedUs()
|
|
321
325
|
|
|
322
326
|
if canConnect == true
|
|
323
|
-
appendDebugOutput("Clear cache folder can connect")
|
|
327
|
+
appendDebugOutput("Clear cache folder can connect, removing cache from #{folder}")
|
|
324
328
|
FileUtils.rm_r Dir.glob("#{folder}/*")
|
|
325
329
|
else
|
|
326
330
|
logError("Unable to connect to Feed.Us. Cache will not be cleared. URL that was checked: #{@mstrDynURL}")
|
|
@@ -353,6 +357,7 @@ class FeedUsGrabber
|
|
|
353
357
|
|
|
354
358
|
grabber_logger.error(contents)
|
|
355
359
|
logfile.close
|
|
360
|
+
appendDebugOutput(contents)
|
|
356
361
|
end
|
|
357
362
|
|
|
358
363
|
def addToDebugOutput(debugOutput, info)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: feed_us_grabber
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.3
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-04-
|
|
12
|
+
date: 2013-04-28 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: shoulda
|
|
@@ -124,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
124
124
|
version: '0'
|
|
125
125
|
segments:
|
|
126
126
|
- 0
|
|
127
|
-
hash:
|
|
127
|
+
hash: -47287185
|
|
128
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
129
|
none: false
|
|
130
130
|
requirements:
|