class Paperdrive::Response

Wrapper class of the Faraday::Response.

Attributes

body[RW]
header[RW]
ratelimit[RW]
status_code[RW]
status_phrase[RW]

Public Class Methods

new(response) click to toggle source

build instance from Faraday::Response

@param [Faraday::Response] response

# 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

Public Instance Methods

success?() click to toggle source

return whether the request was successfully processed or not

@param [boolean]

# File lib/paperdrive/response.rb, line 25
def success?
  !!@body['success']
end

Private Instance Methods

build_ratelimit(header) click to toggle source

build Struct of rate limit information from Faraday::Utils::Headers

@param [Faraday::Utils::Headers] header response header @return [Struct<integer>] which has :limit :remain :reset

# File lib/paperdrive/response.rb, line 35
def build_ratelimit(header)
  Struct.new(:limit, :remain, :reset)
        .new(header['x-ratelimit-limit'].to_i,
             header['x-ratelimit-remaining'].to_i,
             header['x-ratelimit-reset'].to_i)
end