Class: MAuth::Rack::Response

Inherits:
MAuth::Response show all
Defined in:
lib/mauth/rack.rb

Overview

representation of a response composed from a rack response (status, headers, body) which can be passed to a Mauth::Client for signing

Constant Summary

Constants inherited from MAuth::Response

MAuth::Response::SIGNATURE_COMPONENTS, MAuth::Response::SIGNATURE_COMPONENTS_V2

Instance Method Summary collapse

Methods included from Signable

#normalize_path, #string_to_sign_v1, #string_to_sign_v2, #unescape_encode_query_string, #uri_escape

Constructor Details

#initialize(status, headers, body) ⇒ Response

Returns a new instance of Response.



161
162
163
164
165
# File 'lib/mauth/rack.rb', line 161

def initialize(status, headers, body)
  @status = status
  @headers = headers
  @body = body
end

Instance Method Details

#attributes_for_signingObject



171
172
173
174
175
176
177
178
179
180
# File 'lib/mauth/rack.rb', line 171

def attributes_for_signing
  @attributes_for_signing ||= begin
    body = +''
    # NOTE: rack only requires #each be defined on the body, so not using map or inject
    @body.each do |part|
      body << part
    end
    { status_code: @status.to_i, body: body }
  end
end

#merge_headers(headers) ⇒ Object

takes a Hash of headers; returns an instance of this class whose headers have been updated with the argument headers



184
185
186
# File 'lib/mauth/rack.rb', line 184

def merge_headers(headers)
  self.class.new(@status, @headers.merge(headers), @body)
end

#status_headers_bodyObject



167
168
169
# File 'lib/mauth/rack.rb', line 167

def status_headers_body
  [@status, @headers, @body]
end