Class: Acter::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/acter/response.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, headers, body) ⇒ Response

Returns a new instance of Response.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/acter/response.rb', line 5

def initialize(status, headers, body)
  @status = status
  @success = (200..299).include?(status[/\d+/].to_i)
  @headers = headers.sort.map {|a| a.join(": ") }
  @body = case body
    when String
      @body_is_json = false
      body
    else
      @body_is_json = true
      MultiJson.dump(body, pretty: true)
    end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



24
25
26
# File 'lib/acter/response.rb', line 24

def body
  @body
end

#body_is_jsonObject (readonly) Also known as: body_is_json?

Returns the value of attribute body_is_json.



24
25
26
# File 'lib/acter/response.rb', line 24

def body_is_json
  @body_is_json
end

#headersObject (readonly)

Returns the value of attribute headers.



24
25
26
# File 'lib/acter/response.rb', line 24

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



24
25
26
# File 'lib/acter/response.rb', line 24

def status
  @status
end

#successObject (readonly) Also known as: success?

Returns the value of attribute success.



24
25
26
# File 'lib/acter/response.rb', line 24

def success
  @success
end

Class Method Details

.new_from_faraday(faraday_response) ⇒ Object



19
20
21
22
# File 'lib/acter/response.rb', line 19

def self.new_from_faraday(faraday_response)
  status_string = "#{faraday_response.status} #{faraday_response.reason_phrase}"
  new(status_string, faraday_response.headers, faraday_response.body)
end