Class: Cachai::Middleware

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/cachai.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, opts = {}) ⇒ Middleware

Returns a new instance of Middleware.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cachai.rb', line 25

def initialize(app, opts = {})
  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}")
  else
    puts "No Akismet key found! Will not check comments for spam."
  end

  if mailgun_opts = opts.delete(:mailgun)
    require 'rest-client'
    @mailgun_domain  = mailgun_opts[:domain]
    @mailgun_api_key = mailgun_opts[:api_key]
    @recipient = opts.delete(:recipient) or raise "No recipient set!"
  end

  super(app)
end