feed_us_grabber 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +20 -0
- data/README.rdoc +78 -0
- data/lib/app/controllers/feed_us_grabber_controller.rb +101 -0
- data/lib/app/helpers/feed_us_grabber_helper.rb +37 -0
- data/lib/app/models/feed_us_grabber.rb +303 -0
- data/lib/app/models/feed_us_grabber_logger.rb +5 -0
- data/lib/feed_us_grabber/core_ext.rb +5 -0
- data/lib/feed_us_grabber/routing.rb +21 -0
- data/lib/feed_us_grabber.rb +18 -0
- metadata +140 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Cliff G
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
= feed_us_grabber
|
2
|
+
|
3
|
+
ENVIRONEMNT
|
4
|
+
To be used with Rails 3.x and Ruby 1.9x
|
5
|
+
|
6
|
+
INSTALLATION
|
7
|
+
Follow these steps to download and install the feed_us_grabber gem
|
8
|
+
1. In your rails application, edit your Gemfile to include:
|
9
|
+
gem 'feed_us_grabber'
|
10
|
+
2. Run bundle install from the command line (this will download the feed_us_grabber to your environment)
|
11
|
+
3. Open config/routes.rb and add following line match "rails_app/FeedUsGrabber" => "FeedUsGrabber#index"
|
12
|
+
** where rails_app is the root URL to your application. The match is case sensitive.
|
13
|
+
4. Update environment.rb and include require 'net/http'
|
14
|
+
Your installation is complete
|
15
|
+
|
16
|
+
USAGE
|
17
|
+
Add following line to each controller (or app/controllers/application_controller.rb)
|
18
|
+
include FeedUsGrabberHelper
|
19
|
+
Add following code inside your controllers actions
|
20
|
+
@grabber = feedUsGrabber(:FeedUsURL => '<FEED.US URL>',:FeedUsCacheInterval => FEED_INTERVAL, :FeedUsCacheIntervalLength => FEED_INTERVAL_LENGTH, :FeedUsCacheGroup => 'FEED CACHE GROUP NAME')
|
21
|
+
e.g.
|
22
|
+
If you want to use FeedUsGrabber inside action index under controller "test" add following code inside action index of "test" controller
|
23
|
+
|
24
|
+
def index
|
25
|
+
@grabber = feedUsGrabber(:FeedUsURL => 'http://dev.render.feed.us/Feed.aspx?g=98397b1c-5494-de11-938c-00304891151d',:FeedUsCacheInterval => CI_DAYS, :FeedUsCacheIntervalLength => 2, :FeedUsCacheGroup => 'demo')
|
26
|
+
end
|
27
|
+
|
28
|
+
The most basic configuration is (Note you will replace the URL listed with the URL of your content from "Export" on Feed.Us):
|
29
|
+
|
30
|
+
def index
|
31
|
+
@grabber = feedUsGrabber(:FeedUsURL => 'http://dev.render.feed.us/Feed.aspx?g=98397b1c-5494-de11-938c-00304891151d')
|
32
|
+
end
|
33
|
+
|
34
|
+
now inside view of the action add the following code to render your content
|
35
|
+
<%= feedUsGrabberRender @grabber %>
|
36
|
+
e.g.
|
37
|
+
index.erb of "test" looks like
|
38
|
+
<table>
|
39
|
+
<tr>
|
40
|
+
<td width='20%'>
|
41
|
+
<%= feedUsGrabberRender @grabber %>
|
42
|
+
</td>
|
43
|
+
<td> Some text </td>
|
44
|
+
</tr>
|
45
|
+
</table>
|
46
|
+
|
47
|
+
CLEARING CACHE
|
48
|
+
To clear cache goto following url
|
49
|
+
http://rails_app/FeedUsGrabber
|
50
|
+
1. Clear a specific cache group
|
51
|
+
http://rails_app/FeedUsGrabber?cachecommand=clear&group=demo
|
52
|
+
OR
|
53
|
+
|
54
|
+
http://rails_app/FeedUsGrabber?group=demo
|
55
|
+
2. Clear entire cache
|
56
|
+
http://rails_app/FeedUsGrabber?cachecommand=clearall
|
57
|
+
|
58
|
+
LOCATION OF CACHE
|
59
|
+
Cache is maintained under RAILS_ROOT/tmp
|
60
|
+
|
61
|
+
LOCATION OF LOG
|
62
|
+
Log is maintained under RAILS_ROOT/log/FeedUsGrabber.log
|
63
|
+
|
64
|
+
== Contributing to feed_us_grabber
|
65
|
+
|
66
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
67
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
68
|
+
* Fork the project.
|
69
|
+
* Start a feature/bugfix branch.
|
70
|
+
* Commit and push until you are happy with your contribution.
|
71
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
72
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
73
|
+
|
74
|
+
== Copyright
|
75
|
+
|
76
|
+
Copyright (c) 2012 Cliff G. See LICENSE.txt for
|
77
|
+
further details.
|
78
|
+
|
@@ -0,0 +1,101 @@
|
|
1
|
+
include FeedUsGrabberHelper
|
2
|
+
|
3
|
+
# Constant already set in model
|
4
|
+
#CACHE_COMMAND_FORCE = "force_clear_all"
|
5
|
+
|
6
|
+
class FeedUsGrabberController < ActionController::Base
|
7
|
+
def index
|
8
|
+
def initialize
|
9
|
+
# Client ip check. Can remove all ip's to turn off the check.
|
10
|
+
# ! IMPORTANT: TO DISABLE THIS CHECK SET BOTH ARRAYS TO nil
|
11
|
+
@mClientWhiteList = [ "75.126.108.226", "75.126.107.10", "127.0.0.1" ]
|
12
|
+
@mClientHostNameWhileList = [ "request.feed.us", "feed.us", "classic.syndication.feed.us", "render.feed.us", "dev.feed.us", "stage.feed.us", "localhost"]
|
13
|
+
@mClientIp
|
14
|
+
end
|
15
|
+
|
16
|
+
args = {}
|
17
|
+
|
18
|
+
# URL that will be checked for connectivity before clearing the cache (phone home)
|
19
|
+
args[:FeedUsURL] = 'http://render.feed.us/grabberdefault.htm?phonehome=true'
|
20
|
+
|
21
|
+
unless params[:cachecommand].nil?
|
22
|
+
args[:CacheCommand] = params[:cachecommand]
|
23
|
+
end
|
24
|
+
unless params[:group].nil?
|
25
|
+
args[:FeedUsCacheGroup] = params[:group]
|
26
|
+
end
|
27
|
+
|
28
|
+
if args[:FeedUsCacheGroup] && args[:CacheCommand].nil?
|
29
|
+
args[:CacheCommand] = 'clear'
|
30
|
+
end
|
31
|
+
|
32
|
+
if args[:CacheCommand].nil?
|
33
|
+
args[:CacheCommand] = 'clearall'
|
34
|
+
end
|
35
|
+
|
36
|
+
if args[:CacheCommand] == 'clear' && args[:FeedUsCacheGroup]
|
37
|
+
fetch = true
|
38
|
+
else
|
39
|
+
fetch = false
|
40
|
+
end
|
41
|
+
if args[:CacheCommand] == 'clearall' || args[:CacheCommand] == CACHE_COMMAND_FORCE
|
42
|
+
fetch = true
|
43
|
+
end
|
44
|
+
|
45
|
+
# Client ip check
|
46
|
+
isPermittedToProceed = IsPermittedToProceed()
|
47
|
+
|
48
|
+
if isPermittedToProceed == false
|
49
|
+
render :text=> "<img src=\"http://feed.us/images/feedus_logo_people.png\"><br />
|
50
|
+
<p style=\"font-family:arial;\"> IP " + @mClientIp + " is not authorized. Modify the feed_us_grabber_controller @mClientWhiteList array if this IP should have access."
|
51
|
+
else
|
52
|
+
if fetch == true
|
53
|
+
feedUsGrabber(args)
|
54
|
+
render :text => "<img src=\"http://feed.us/images/feedus_logo_people.png\"><br />
|
55
|
+
<p style=\"font-family:arial;\">Congratulations! You have successfully refreshed your content.</p>
|
56
|
+
<p style=\"font-family:arial;\"><a href=\"/\">Home</a></p>"
|
57
|
+
else
|
58
|
+
render :text=> "<img src=\"http://feed.us/images/feedus_logo_people.png\"><br />
|
59
|
+
<p style=\"font-family:arial;\"> Please specify cachecommand=clear&group=GROUPNAME or cachecommand=clearall or cachecommand=force_clear_all in the URL"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def IsPermittedToProceed()
|
65
|
+
isPermitted = false
|
66
|
+
@mClientIp = request.remote_addr
|
67
|
+
|
68
|
+
if @mClientIp == "" || @mClientIp.nil?
|
69
|
+
@mClientIp = request.env["HTTP_X_FORWARDED_FOR"]
|
70
|
+
end
|
71
|
+
|
72
|
+
isPermitted = IsClientIpInWhiteList()
|
73
|
+
|
74
|
+
if isPermitted == false
|
75
|
+
if @mClientHostNameWhileList.nil? == false
|
76
|
+
# Try to resolve hostname from ip
|
77
|
+
begin
|
78
|
+
s = Socket.getaddrinfo(@mClientIp,nil)
|
79
|
+
host = s[0][2]
|
80
|
+
if @mClientHostNameWhileList.include?(host) == true
|
81
|
+
isPermitted = true
|
82
|
+
end
|
83
|
+
rescue
|
84
|
+
# Do Nothing
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
return isPermitted
|
90
|
+
end
|
91
|
+
|
92
|
+
def IsClientIpInWhiteList()
|
93
|
+
included = false
|
94
|
+
if @mClientWhiteList.nil? && @mClientHostNameWhileList.nil?
|
95
|
+
included = true
|
96
|
+
elsif @mClientWhiteList.nil? == false && @mClientWhiteList.include?(@mClientIp) == true
|
97
|
+
included = true
|
98
|
+
end
|
99
|
+
return included
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module FeedUsGrabberHelper
|
2
|
+
def feedUsGrabber(params)
|
3
|
+
grabber = FeedUsGrabber.new
|
4
|
+
|
5
|
+
unless params[:CacheCommand].nil?
|
6
|
+
grabber.setCacheCommand(params[:CacheCommand])
|
7
|
+
end
|
8
|
+
unless params[:FeedUsCacheGroup].nil?
|
9
|
+
grabber.setCacheGroup(params[:FeedUsCacheGroup])
|
10
|
+
end
|
11
|
+
unless params[:FeedUsCacheFolder].nil?
|
12
|
+
grabber.setCacheFolder(params[:FeedUsCacheFolder])
|
13
|
+
else
|
14
|
+
grabber.setCacheFolder(File.join(Rails.root.to_s,'tmp','CachedWebContent'));
|
15
|
+
end
|
16
|
+
unless params[:FeedUsCacheInterval].nil? && params[:FeedUsCacheIntervalLength].nil?
|
17
|
+
grabber.setCacheIntervalUnit(params[:FeedUsCacheInterval])
|
18
|
+
grabber.setCacheIntervalLength(params[:FeedUsCacheIntervalLength])
|
19
|
+
end
|
20
|
+
|
21
|
+
unless params[:FeedUsURL].nil?
|
22
|
+
grabber.setDynURL(params[:FeedUsURL])
|
23
|
+
if params[:includeFlag] == true
|
24
|
+
grabber.setIncludeFlag(true)
|
25
|
+
else
|
26
|
+
grabber.setIncludeFlag(false)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
grabber.autoCacheToFile()
|
31
|
+
grabber
|
32
|
+
end
|
33
|
+
|
34
|
+
def feedUsGrabberRender(grabber)
|
35
|
+
grabber.renderCacheFromFile.to_s.html_safe
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,303 @@
|
|
1
|
+
# defining constants
|
2
|
+
CI_MINUTES = 0
|
3
|
+
CI_HOURS = 1
|
4
|
+
CI_DAYS = 2
|
5
|
+
CI_FOREVER = 3
|
6
|
+
ERROR_RESPONSE = " "
|
7
|
+
CACHE_COMMAND_FORCE = "force_clear_all"
|
8
|
+
|
9
|
+
require 'time'
|
10
|
+
require 'fileutils'
|
11
|
+
|
12
|
+
|
13
|
+
class FeedUsGrabber
|
14
|
+
def initialize
|
15
|
+
@mintCacheIntervalUnit = CI_FOREVER
|
16
|
+
@mstrCacheFolder = File.join(Rails.root.to_s,'tmp','CachedWebContent')
|
17
|
+
@mstrCacheFileExt = ".cache"
|
18
|
+
@mstrCacheGroup = ""
|
19
|
+
end
|
20
|
+
|
21
|
+
def setCacheGroup(param)
|
22
|
+
@mstrCacheGroup = param
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
def setCacheFolder(param)
|
28
|
+
@mstrCacheFolder = param
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
def setCacheIntervalUnit(param)
|
34
|
+
@mintCacheIntervalUnit = param
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
def getCacheIntervalUnit
|
40
|
+
@mintCacheIntervalUnit
|
41
|
+
end
|
42
|
+
|
43
|
+
def setCacheFileExt(strNewValue)
|
44
|
+
@mstrCacheFileExt = strNewValue
|
45
|
+
end
|
46
|
+
|
47
|
+
def setCacheCommand(strNewValue)
|
48
|
+
@mstrCacheCommand = strNewValue
|
49
|
+
end
|
50
|
+
|
51
|
+
def getCacheCommand
|
52
|
+
@mstrCacheCommand
|
53
|
+
end
|
54
|
+
|
55
|
+
def getCacheFolder
|
56
|
+
@mstrCacheFolder
|
57
|
+
end
|
58
|
+
|
59
|
+
def setIncludeFlag(strNewValue)
|
60
|
+
@mblnInclude = $strNewValue
|
61
|
+
end
|
62
|
+
|
63
|
+
def getIncludeFlag
|
64
|
+
@mblnInclude
|
65
|
+
end
|
66
|
+
|
67
|
+
def getCacheGroup
|
68
|
+
@mstrCacheGroup
|
69
|
+
end
|
70
|
+
def getCachedFileName
|
71
|
+
@getCachedFileName
|
72
|
+
end
|
73
|
+
|
74
|
+
def setCacheIntervalLength(param)
|
75
|
+
@mintCacheIntervalLength = param
|
76
|
+
end
|
77
|
+
|
78
|
+
def getCacheIntervalLength
|
79
|
+
@mintCacheIntervalLength
|
80
|
+
end
|
81
|
+
|
82
|
+
def setDynURL(param)
|
83
|
+
@mstrDynURL = param
|
84
|
+
self.getCacheNames(param)
|
85
|
+
end
|
86
|
+
|
87
|
+
def getDynURL
|
88
|
+
@mstrDynURL
|
89
|
+
end
|
90
|
+
|
91
|
+
def getCacheNames(sURL)
|
92
|
+
if (sURL =~ /\?/) > 0
|
93
|
+
base = sURL.split('?')[0]
|
94
|
+
params = sURL.split('?')[1]
|
95
|
+
else
|
96
|
+
base = sURL
|
97
|
+
params = ''
|
98
|
+
end
|
99
|
+
#strip off the file extension
|
100
|
+
base = base.chomp(File.extname(base))
|
101
|
+
base.sub!('http://','')
|
102
|
+
base.gsub!(/[\?:\/\.]/,'_')
|
103
|
+
@mstrScriptBaseName = base
|
104
|
+
@mstrCacheFileQualifiers = self.getCacheFileQualifiers(params)
|
105
|
+
@mstrCachedFileName =File.join( @mstrCacheFolder,
|
106
|
+
@mstrCacheGroup,
|
107
|
+
@mstrScriptBaseName + "_" + @mstrCacheFileQualifiers + @mstrCacheFileExt)
|
108
|
+
@mstrCachedFileNameShort = @mstrScriptBaseName + "_" + @mstrCacheFileQualifiers + @mstrCacheFileExt
|
109
|
+
end
|
110
|
+
|
111
|
+
def getCacheFileQualifiers(strURLParams)
|
112
|
+
strResults = nil
|
113
|
+
strSeparator = "_"
|
114
|
+
strResults = '_' + strURLParams.gsub(/[=&%\.\/:]+/,'_')
|
115
|
+
strResults
|
116
|
+
end
|
117
|
+
|
118
|
+
def autoCacheToFile
|
119
|
+
if @bIsPostBack
|
120
|
+
return
|
121
|
+
end
|
122
|
+
|
123
|
+
if @mstrCacheCommand.nil? || @mstrCacheCommand == ''
|
124
|
+
if (!self.cachedFileExists) or self.cacheFileIsExpired
|
125
|
+
self.createCacheFile
|
126
|
+
end
|
127
|
+
else
|
128
|
+
if @mstrCacheCommand == "clear"
|
129
|
+
if @mstrCacheGroup != ''
|
130
|
+
self.clearCacheGroupFiles(@mstrCacheGroup)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
if @mstrCacheCommand == 'clearall' || @mstrCacheCommand == CACHE_COMMAND_FORCE
|
134
|
+
self.clearAllCachedFiles
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def cachedFileExists()
|
140
|
+
File.readable?(@mstrCachedFileName)
|
141
|
+
end
|
142
|
+
|
143
|
+
def cacheFileIsExpired()
|
144
|
+
# Ruby 1.9.x Time.parse expects d/m/y
|
145
|
+
strDate = File.mtime(@mstrCachedFileName).strftime('%d/%m/%Y %I:%M:%S %p')
|
146
|
+
case @mintCacheIntervalUnit
|
147
|
+
when CI_MINUTES then strUnit = 'n'
|
148
|
+
when CI_HOURS then strUnit = 'h'
|
149
|
+
when CI_DAYS then strUnit = 'd'
|
150
|
+
when CI_FOREVER then return false
|
151
|
+
end
|
152
|
+
|
153
|
+
if self.datediff(strUnit,strDate,Time.now().strftime('%d/%m/%Y %I:%M:%S %p')) > @mintCacheIntervalLength
|
154
|
+
return true
|
155
|
+
else
|
156
|
+
return false
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def createCacheFile()
|
161
|
+
strDynURL = @mstrDynURL
|
162
|
+
sFile = @mstrCachedFileName
|
163
|
+
# Fetch the url
|
164
|
+
begin
|
165
|
+
r = Net::HTTP.get_response(URI.parse(@mstrDynURL))
|
166
|
+
rescue
|
167
|
+
logfile = File.open(File.join(Rails.root.to_s,'log','FeedUsGrabber.log'),'a');
|
168
|
+
grabber_logger = FeedUsGrabberLogger.new(logfile)
|
169
|
+
|
170
|
+
grabber_logger.error("Unable to fetch URL #{@mstrDynURL}")
|
171
|
+
logfile.close
|
172
|
+
return;
|
173
|
+
end
|
174
|
+
|
175
|
+
if self.makeDirectory(File.join(@mstrCacheFolder,@mstrCacheGroup))
|
176
|
+
File.open(sFile,'w') do |file|
|
177
|
+
file.write(r.body)
|
178
|
+
end
|
179
|
+
return true
|
180
|
+
end
|
181
|
+
return false
|
182
|
+
end
|
183
|
+
|
184
|
+
def makeDirectory(dir, mode = 0755)
|
185
|
+
if File.directory?(dir) || FileUtils.mkdir(dir)
|
186
|
+
return true
|
187
|
+
end
|
188
|
+
return false
|
189
|
+
end
|
190
|
+
|
191
|
+
def datediff(interval, datefrom, dateto, using_timestamps = false)
|
192
|
+
#$interval can be:
|
193
|
+
#yyyy - Number of full years
|
194
|
+
#q - Number of full quarters
|
195
|
+
#m - Number of full months
|
196
|
+
#y - Difference between day numbers
|
197
|
+
#(eg 1st Jan 2004 is "1", the first day. 2nd Feb 2003 is "33". The datediff is "-32".)
|
198
|
+
#d - Number of full days
|
199
|
+
#w - Number of full weekdays
|
200
|
+
#ww - Number of full weeks
|
201
|
+
#h - Number of full hours
|
202
|
+
#n - Number of full minutes
|
203
|
+
#s - Number of full seconds (default)
|
204
|
+
|
205
|
+
unless using_timestamps
|
206
|
+
datefrom = Time.parse(datefrom).to_i
|
207
|
+
dateto = Time.parse(dateto).to_i
|
208
|
+
end
|
209
|
+
|
210
|
+
difference = dateto - datefrom # Difference in seconds
|
211
|
+
if interval == 'd'
|
212
|
+
datediff = (difference / 86400).floor
|
213
|
+
elsif interval == 'h'
|
214
|
+
datediff = (difference / 3600).floor
|
215
|
+
elsif interval == 'n'
|
216
|
+
datediff = (difference / 60).floor
|
217
|
+
else
|
218
|
+
datediff = difference
|
219
|
+
end
|
220
|
+
datediff
|
221
|
+
end
|
222
|
+
|
223
|
+
def renderCacheFromFile
|
224
|
+
sFile = @mstrCachedFileName
|
225
|
+
data = ''
|
226
|
+
begin
|
227
|
+
File.open(sFile,'r') do |file|
|
228
|
+
while temp_data = file.gets
|
229
|
+
data = data + temp_data
|
230
|
+
end
|
231
|
+
end
|
232
|
+
data
|
233
|
+
rescue
|
234
|
+
logfile = File.open(File.join(Rails.root.to_s,'log','FeedUsGrabber.log'),'a');
|
235
|
+
grabber_logger = FeedUsGrabberLogger.new(logfile)
|
236
|
+
grabber_logger.error("Unable to render/open #{@mstrCachedFileName}")
|
237
|
+
logfile.close
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
|
242
|
+
def clearCacheGroupFiles(group)
|
243
|
+
if group == '.' || group == '..'
|
244
|
+
logfile = File.open(File.join(Rails.root.to_s,'log','FeedUsGrabber.log'),'a');
|
245
|
+
grabber_logger = FeedUsGrabberLogger.new(logfile)
|
246
|
+
grabber_logger.warn("someone requested to delete . OR .. ")
|
247
|
+
logfile.close
|
248
|
+
return
|
249
|
+
end
|
250
|
+
logfile = File.open(File.join(Rails.root.to_s,'log','FeedUsGrabber.log'),'a');
|
251
|
+
grabber_logger = FeedUsGrabberLogger.new(logfile)
|
252
|
+
grabber_logger.info("Clearing cache at group #{group} at path #{File.join(@mstrCacheFolder,group)}")
|
253
|
+
logfile.close
|
254
|
+
self.clearCacheFolder(File.join(@mstrCacheFolder,group))
|
255
|
+
end
|
256
|
+
|
257
|
+
def clearAllCachedFiles
|
258
|
+
logfile = File.open(File.join(Rails.root.to_s,'log','FeedUsGrabber.log'),'a');
|
259
|
+
grabber_logger = FeedUsGrabberLogger.new(logfile)
|
260
|
+
grabber_logger.info("Clearing all caches at path #{@mstrCacheFolder}")
|
261
|
+
logfile.close
|
262
|
+
self.clearCacheFolder(@mstrCacheFolder);
|
263
|
+
end
|
264
|
+
|
265
|
+
def clearCacheFolder(folder)
|
266
|
+
canConnect = canConnectToFeedUs()
|
267
|
+
|
268
|
+
if canConnect == true
|
269
|
+
FileUtils.rm_r Dir.glob("#{folder}/*")
|
270
|
+
else
|
271
|
+
logError("Unable to connect to Feed.Us. Cache will not be cleared. URL that was checked: #{@mstrDynURL}")
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
def canConnectToFeedUs()
|
276
|
+
# Used for phone home check
|
277
|
+
canConnect = false
|
278
|
+
|
279
|
+
if @mstrCacheCommand == CACHE_COMMAND_FORCE
|
280
|
+
canConnect = true
|
281
|
+
else
|
282
|
+
begin
|
283
|
+
r = Net::HTTP.get_response(URI.parse(@mstrDynURL))
|
284
|
+
if r.body.nil? == false && r.body != ERROR_RESPONSE
|
285
|
+
canConnect = true
|
286
|
+
end
|
287
|
+
rescue
|
288
|
+
logError("Unable to connect to Feed.Us. Cache will not be cleared. URL #{@mstrDynURL}")
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
return canConnect;
|
293
|
+
end
|
294
|
+
|
295
|
+
def logError(contents)
|
296
|
+
logfile = File.open(File.join(Rails.root.to_s,'log','FeedUsGrabber.log'),'a');
|
297
|
+
grabber_logger = FeedUsGrabberLogger.new(logfile)
|
298
|
+
|
299
|
+
grabber_logger.error(contents)
|
300
|
+
logfile.close
|
301
|
+
end
|
302
|
+
|
303
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module FeedUsGrabberRoute #:nodoc: i
|
2
|
+
module Routing #:nodoc:
|
3
|
+
module MapperExtensions
|
4
|
+
def feedusgrabber
|
5
|
+
@set.add_route("/FeedUsGrabber", {:controller => "feed_us_grabber", :action => "index"})
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
if ActionPack::VERSION::MAJOR >= 3
|
12
|
+
# Commenting out for gem as generates -> uninitialized constant ActionDispatch::Routing::DeprecatedMapper (NameError)
|
13
|
+
#ActionDispatch::Routing::DeprecatedMapper.send :include, FeedUsGrabberRoute::Routing::MapperExtensions
|
14
|
+
#ActionDispatch::Routing::DeprecatedMapper :include, FeedUsGrabberRoute::Routing::MapperExtensions
|
15
|
+
else
|
16
|
+
ActionController::Routing::RouteSet::Mapper.send :include, FeedUsGrabberRoute::Routing::MapperExtensions
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# FeedUsGrabber
|
2
|
+
require 'feed_us_grabber/routing'
|
3
|
+
require File.join(File.dirname(__FILE__), 'app', 'models','feed_us_grabber')
|
4
|
+
require File.join(File.dirname(__FILE__), 'app', 'models','feed_us_grabber_logger')
|
5
|
+
|
6
|
+
# Added for gem
|
7
|
+
require File.join(File.dirname(__FILE__), 'app', 'helpers','feed_us_grabber_helper')
|
8
|
+
require File.join(File.dirname(__FILE__), 'app', 'controllers','feed_us_grabber_controller')
|
9
|
+
|
10
|
+
%w{ controllers helpers }.each do |dir|
|
11
|
+
|
12
|
+
path = File.join(File.dirname(__FILE__), 'app', dir)
|
13
|
+
$LOAD_PATH << path
|
14
|
+
|
15
|
+
# Commenting out for gem as generates error
|
16
|
+
#ActiveSupport::Dependencies.autoload_paths << path
|
17
|
+
#ActiveSupport::Dependencies.autoload_once_paths.delete(path)
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: feed_us_grabber
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Cliff G
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: shoulda
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rdoc
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.12'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.12'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.0.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.0.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: jeweler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.8.4
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.8.4
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: simplecov
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: This gem replaces the previous feed.us grabber rails plugin to render
|
95
|
+
content items from feed.us on your site.
|
96
|
+
email: clifford.gray@gmail.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files:
|
100
|
+
- LICENSE.txt
|
101
|
+
- README.rdoc
|
102
|
+
files:
|
103
|
+
- lib/app/controllers/feed_us_grabber_controller.rb
|
104
|
+
- lib/app/helpers/feed_us_grabber_helper.rb
|
105
|
+
- lib/app/models/feed_us_grabber.rb
|
106
|
+
- lib/app/models/feed_us_grabber_logger.rb
|
107
|
+
- lib/feed_us_grabber.rb
|
108
|
+
- lib/feed_us_grabber/core_ext.rb
|
109
|
+
- lib/feed_us_grabber/routing.rb
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.rdoc
|
112
|
+
homepage: http://github.com/cliffordru/feed_us_grabber
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
segments:
|
126
|
+
- 0
|
127
|
+
hash: 96139695
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 1.8.24
|
137
|
+
signing_key:
|
138
|
+
specification_version: 3
|
139
|
+
summary: Gem to render feed.us content from your rails app
|
140
|
+
test_files: []
|