Class: Shokkenki::Consumer::Stubber::Request
- Inherits:
-
Object
- Object
- Shokkenki::Consumer::Stubber::Request
- Defined in:
- lib/shokkenki/consumer/stubber/request.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#interaction ⇒ Object
Returns the value of attribute interaction.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Class Method Summary collapse
- .as_header_name(name) ⇒ Object
- .from_rack(rack_env) ⇒ Object
- .headers_from(env) ⇒ Object
- .query_from(query_string) ⇒ Object
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Request
constructor
A new instance of Request.
- #to_hash ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Request
Returns a new instance of Request.
22 23 24 25 26 27 28 |
# 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 |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
8 9 10 |
# File 'lib/shokkenki/consumer/stubber/request.rb', line 8 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
8 9 10 |
# File 'lib/shokkenki/consumer/stubber/request.rb', line 8 def headers @headers end |
#interaction ⇒ Object
Returns the value of attribute interaction.
9 10 11 |
# File 'lib/shokkenki/consumer/stubber/request.rb', line 9 def interaction @interaction end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
8 9 10 |
# File 'lib/shokkenki/consumer/stubber/request.rb', line 8 def method @method end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/shokkenki/consumer/stubber/request.rb', line 8 def path @path end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
8 9 10 |
# File 'lib/shokkenki/consumer/stubber/request.rb', line 8 def query @query end |
Class Method Details
.as_header_name(name) ⇒ Object
66 67 68 |
# 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) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# 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) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# 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 |
.query_from(query_string) ⇒ Object
58 59 60 61 62 63 64 |
# 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 |
Instance Method Details
#to_hash ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# 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 |