Class: Simple::OAuth2::Responses

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_oauth2/responses.rb

Overview

Processes Rack Responses and contains helper methods

Examples:

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
  >
]

Returns:

  • (Object)

    Rack response

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Responses

Simple::OAuth2 response class

Parameters:

  • response (Array)

    raw Rack::Response object



39
40
41
# File 'lib/simple_oauth2/responses.rb', line 39

def initialize(response)
  @response = response
end

Instance Method Details

#bodyObject

Response JSON-parsed body



54
55
56
57
58
59
# 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

#headersObject

Response headers



49
50
51
# File 'lib/simple_oauth2/responses.rb', line 49

def headers
  @response[1]
end

#statusObject

Response status



44
45
46
# File 'lib/simple_oauth2/responses.rb', line 44

def status
  @response[0]
end