class BreezyPDF::Response

API HTTP Response

Public Class Methods

new(http_response) click to toggle source
# File lib/breezy_pdf/response.rb, line 6
def initialize(http_response)
  @http_response = http_response
  BreezyPDF.logger.fatal("[BreezyPDF] Network request failed: #{@http_response.body}") if failure?
end

Public Instance Methods

failure?() click to toggle source
# File lib/breezy_pdf/response.rb, line 15
def failure?
  !success?
end
method_missing(method, *_args, &_blk) click to toggle source
Calls superclass method
# File lib/breezy_pdf/response.rb, line 19
def method_missing(method, *_args, &_blk)
  if body.key?(method.to_s)
    body[method.to_s]
  else
    super
  end
end
respond_to_missing?(method, *) click to toggle source
# File lib/breezy_pdf/response.rb, line 27
def respond_to_missing?(method, *)
  body.key?(method.to_s)
end
success?() click to toggle source
# File lib/breezy_pdf/response.rb, line 11
def success?
  code >= 200 && code < 400
end

Private Instance Methods

body() click to toggle source
# File lib/breezy_pdf/response.rb, line 37
def body
  @body ||= JSON.parse(@http_response.body)
rescue JSON::ParserError => e
  BreezyPDF.logger.fatal("[BreezyPDF] Server responded with invalid JSON: #{e}")
  raise e
end
code() click to toggle source
# File lib/breezy_pdf/response.rb, line 33
def code
  @code ||= @http_response.code.to_i
end