Class: SnapImage::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/snapimage/middleware.rb

Overview

SnapImage API Rack Middleware to handle all SnapImage API calls.

Instance Method Summary collapse

Constructor Details

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

Arguments:

  • app

    Rack application

  • options

    Options for the middleware

Options:

  • path

    The URL path to access the SnapImage API (defaults to “/snapimage_api”)

  • config

    Filename of the YAML or JSON config file or a config Hash # (defaults to “config/snapimage_config.yml”)



11
12
13
14
15
16
# File 'lib/snapimage/middleware.rb', line 11

def initialize(app, options = {})
  @app = app
  @path = options[:path] || "/snapimage_api"
  @config = SnapImage::Config.new(options[:config] || "config/snapimage_config.yml")
  @storage = SnapImage::Storage.new(@config)
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/snapimage/middleware.rb', line 18

def call(env)
  request = SnapImage::Request.new(env)
  if request.path_info == @path
    SnapImage::Server.new(request, @config, @storage).call
  else
    @app.call(env)
  end
end