lib/cachai.rb in cachai-0.2.6 vs lib/cachai.rb in cachai-0.2.7
- old
+ new
@@ -21,13 +21,14 @@
error do
'Oops, nasty error: ' + env['sinatra.error'].message
end
def initialize(app, opts = {})
- domain = opts.delete(:domain) or raise 'Domain required.'
- redis_host = opts.delete(:redis_host) || 'localhost'
- @duration = opts.delete(:duration)
+ domain = opts.delete(:domain) or raise 'Domain required.'
+ redis_host = opts.delete(:redis_host) || 'localhost'
+ @duration = opts.delete(:duration)
+ @blocked_ips = opts.delete(:blocked_ips) || []
Cachai.boot(domain, redis_host)
if key = opts.delete(:akismet_key)
@akismet = Akismet.new(:api_key => key, :blog => "http://#{Cachai.domain}")
@@ -98,14 +99,16 @@
:content => data['content'],
:author_name => data['author_name'],
:author_email => data['author_email'],
:author_url => data['author_url'],
:parent_id => data['parent_id'].to_i,
- :author_ip => request.ip
+ :author_ip => request.ip,
+ :approved => is_blocked?(request.ip) ? 0 : 1
}
response = Response.create!(attrs.merge(:post_id => post.id))
+
Cachai.clear_cache(data['path'])
notify_new_response(response, data['path']) if @recipient
headers['Access-Control-Allow-Origin'] = data['protocol'] + '//' + data['domain']
json({ :status => 'ok', :comment => response })
@@ -145,9 +148,13 @@
end
def json(obj)
content_type 'application/json'
return obj.is_a?(String) ? obj : obj.to_json
+ end
+
+ def is_blocked?(user_ip)
+ @blocked_ips.include?(user_ip)
end
def is_spam?(data, link, request)
return false unless @akismet
# return true if blacklisted?(name, email, content)