Class: Paperdrive::Response

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

Overview

Wrapper class of the Faraday::Response.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

build instance from Faraday::Response

Parameters:

  • response (Faraday::Response)


13
14
15
16
17
18
19
20
# File 'lib/paperdrive/response.rb', line 13

def initialize(response)
  Paperdrive::Error.raise_from(response)
  @header = response.headers.to_h
  @ratelimit = build_ratelimit(@header)
  @body = JSON.parse(response.body)
  @status_code = response.status
  @status_phrase = response.reason_phrase
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



8
9
10
# File 'lib/paperdrive/response.rb', line 8

def body
  @body
end

#headerObject

Returns the value of attribute header.



8
9
10
# File 'lib/paperdrive/response.rb', line 8

def header
  @header
end

#ratelimitObject

Returns the value of attribute ratelimit.



8
9
10
# File 'lib/paperdrive/response.rb', line 8

def ratelimit
  @ratelimit
end

#status_codeObject

Returns the value of attribute status_code.



8
9
10
# File 'lib/paperdrive/response.rb', line 8

def status_code
  @status_code
end

#status_phraseObject

Returns the value of attribute status_phrase.



8
9
10
# File 'lib/paperdrive/response.rb', line 8

def status_phrase
  @status_phrase
end

Instance Method Details

#success?Boolean

return whether the request was successfully processed or not

Parameters:

  • (boolean)

Returns:

  • (Boolean)


25
26
27
# File 'lib/paperdrive/response.rb', line 25

def success?
  !!@body['success']
end