Sha256: a539a0fbb6e44578561d61b496d58ce4dd913db02e4650a96122573077614797
Contents?: true
Size: 1.61 KB
Versions: 1
Compression:
Stored size: 1.61 KB
Contents
require 'nitro/cgi' module Nitro # The script adapter. Useful when running in console mode, or # when creating scripts for cron jobs, testing and more. Allows # you to programmatically 'drive' the web application. class ScriptAdapter # The last generated response. attr_accessor :response def initialize server @server = server end # Perform a programmatic http request to the web app. # # === Examples # # app.get 'users/logout' # app.post 'users/login', :params => { :name => 'gmosx', :password => 'pass' } # app.post 'users/login?name=gmosx;password=pass # app.post 'articles/view/1' def handle uri, options = {} context = Context.new(@server) begin context.params = options.fetch(:params, {}) context.headers = options.fetch(:headers, {}) context.headers['REQUEST_URI'] = uri context.headers['REQUEST_METHOD'] = options.fetch(:method, :get) context.headers['HTTP_COOKIE'] ||= options[:cookies] Cgi.parse_params context Cgi.parse_cookies context context.render uri context.close ensure $autoreload_dirty = false Og.manager.put_store if defined?(Og) and Og.respond_to?(:manager) and Og.manager end @response = context end # Perform a programmatic http get request to the web app. def get uri, options = {} options[:method] = :get handle uri, options end # Perform a programmatic http post request to the web app. def post uri, options = {} options[:method] = :post handle uri, options end end end # * George Moschovitis <gm@navel.gr>
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
nitro-0.31.0 | lib/nitro/adapter/script.rb |