class Sendgrid::Web::Response

Attributes

parsed_body[R]
raw_body[R]
status_code[R]

Public Class Methods

new(status_code, body) click to toggle source
# File lib/sendgrid/web/response.rb, line 5
def initialize(status_code, body)
  @status_code = status_code.to_i
  @raw_body = body.to_s
  @parsed_body = ::Oj.safe_load(raw_body)
end

Public Instance Methods

error_messages() click to toggle source

Fetches an array of error messages from the response.

@return [Array<String>] A list of any error messages.

# File lib/sendgrid/web/response.rb, line 24
def error_messages
  if errors?
    errors = Array(parsed_body['errors'])
    errors << parsed_body['error']
    errors.compact
  else
    []
  end
end
errors?() click to toggle source

Checks if the Sengrid response contained errors.

@return [bool] True if there were errors found.

# File lib/sendgrid/web/response.rb, line 14
def errors?
  !parsed_body.nil? &&
  parsed_body.is_a?(Hash) &&
  (parsed_body.has_key?('errors') ||
  parsed_body.has_key?('error'))
end