class TwitterAds::Error

Constants

ERRORS

Attributes

code[R]
details[R]
headers[R]
response[R]

Public Class Methods

from_response(object) click to toggle source

Returns an appropriately typed Error object based from an API response.

@param object [Hash] The parsed JSON API response.

@return [Error] The error object instance.

@since 0.1.0 @api private

# File lib/twitter-ads/error.rb, line 51
def from_response(object)
  return class_eval(ERRORS[object.code]).new(object) if ERRORS.key?(object.code)
  new(object) # fallback, unknown error
end
new(*args) click to toggle source
# File lib/twitter-ads/error.rb, line 10
def initialize(*args)
  if args.size == 1 && args[0].respond_to?(:body) && args[0].respond_to?(:code)
    @response = args[0]
    @code     = args[0].code
    @details  = args[0].body[:errors] if args[0].body.is_a?(Hash) && args[0].body[:errors]
  elsif args.size == 3
    @response = args[0]
    @details  = args[1]
    @code     = args[2]
  end
  self
end

Public Instance Methods

inspect() click to toggle source
# File lib/twitter-ads/error.rb, line 23
def inspect
  str = +"#<#{self.class.name}:0x#{object_id}"
  str << " code=#{@code}" if @code
  str << " details=\"#{@details}\"" if @details
  str << '>'
end
Also aliased as: to_s
to_s()
Alias for: inspect