class Shokkenki::Consumer::Stubber::Request
Attributes
body[R]
headers[R]
interaction[RW]
method[R]
path[R]
query[R]
Public Class Methods
as_header_name(name)
click to toggle source
# File lib/shokkenki/consumer/stubber/request.rb, line 66 def self.as_header_name name name.to_s.gsub(/^HTTP_/, '').gsub('_', '-').downcase.to_sym end
from_rack(rack_env)
click to toggle source
# File lib/shokkenki/consumer/stubber/request.rb, line 11 def self.from_rack rack_env env = rack_env.dup new( :path => env['PATH_INFO'], :method => env['REQUEST_METHOD'].downcase, :body => env['rack.input'].read, :query => query_from(env['QUERY_STRING']), :headers => headers_from(env) ) end
headers_from(env)
click to toggle source
# File lib/shokkenki/consumer/stubber/request.rb, line 42 def self.headers_from env env.reject{ |k, v| [ 'PATH_INFO', 'REQUEST_METHOD', 'QUERY_STRING' ].include?(k) }. reject { |k, v| k.start_with?('rack.') }. reject { |k, v| k.start_with?('async.') }. inject({}) do |headers, key_value| headers[as_header_name(key_value[0])] = key_value[1] headers end end
new(attributes)
click to toggle source
# File lib/shokkenki/consumer/stubber/request.rb, line 22 def initialize attributes @path = attributes[:path] @method = attributes[:method] @body = attributes[:body] @query = attributes[:query] @headers = attributes[:headers] end
query_from(query_string)
click to toggle source
# File lib/shokkenki/consumer/stubber/request.rb, line 58 def self.query_from query_string query_string.split('&').inject({}) do |query, param| k, v = param.split '=' query[k.to_sym] = URI.decode v query end end
Public Instance Methods
to_hash()
click to toggle source
# File lib/shokkenki/consumer/stubber/request.rb, line 30 def to_hash hash = { :path => @path, :method => @method, :headers => @headers, :query => @query, :body => @body } hash.merge!(:interaction => @interaction.to_hash) if @interaction hash end