class Simple::OAuth2::Responses

Processes Rack Responses and contains helper methods

@return [Object] Rack response

@example

rack_response = [
  200,
  { 'Content-Type' => 'application/json' },
  Rack::BodyProxy.new(Rack::Response.new('200'.to_json))
]
response = Simple::OAuth2::Responses.new(rack_response)

response.status  #=> 200
response.headers #=> {}
response.body    #=> '200'
response         #=> <Simple::OAuth2::Responses:0x007fc9f32080b8 @response=[
  200,
  {},
  <Rack::BodyProxy:0x007fc9f3208108
    @block=nil,
    @body= <Rack::Response:0x007fc9f3208388
      @block=nil,
      @body=["\"200\""],
      @header={"Content-Length"=>"5"},
      @length=5,
      @status=200
    >,
    @closed=false
  >
]

Public Class Methods

new(response) click to toggle source

Simple::OAuth2 response class

@param response [Array] raw Rack::Response object

# File lib/simple_oauth2/responses.rb, line 39
def initialize(response)
  @response = response
end

Public Instance Methods

body() click to toggle source

Response JSON-parsed body

# File lib/simple_oauth2/responses.rb, line 54
def body
  response_body = @response[2].body.first
  return {} if response_body.nil? || response_body.empty?

  JSON.parse(response_body)
end
headers() click to toggle source

Response headers

# File lib/simple_oauth2/responses.rb, line 49
def headers
  @response[1]
end
status() click to toggle source

Response status

# File lib/simple_oauth2/responses.rb, line 44
def status
  @response[0]
end