class FirebaseCloudMessenger::Error

Attributes

response[R]

Public Class Methods

from_response(response) click to toggle source
# File lib/firebase_cloud_messenger/error.rb, line 8
def self.from_response(response)
  status = response.code

  klass = case status.to_i
          when 400 then FirebaseCloudMessenger::BadRequest
          when 401 then FirebaseCloudMessenger::Unauthorized
          when 403 then FirebaseCloudMessenger::Forbidden
          when 404 then FirebaseCloudMessenger::NotFound
          else self
          end

  klass.new(response)
end
new(response = nil) click to toggle source
Calls superclass method
# File lib/firebase_cloud_messenger/error.rb, line 22
def initialize(response = nil)
  @response = response

  super(error_message)
end

Public Instance Methods

details() click to toggle source
# File lib/firebase_cloud_messenger/error.rb, line 40
def details
  parsed_response["error"]["details"]
end
parsed_response() click to toggle source
# File lib/firebase_cloud_messenger/error.rb, line 36
def parsed_response
  JSON.parse(response_body)
end
response_body() click to toggle source
# File lib/firebase_cloud_messenger/error.rb, line 32
def response_body
  response.body
end
response_status() click to toggle source
# File lib/firebase_cloud_messenger/error.rb, line 28
def response_status
  response.code.to_i
end
short_message() click to toggle source
# File lib/firebase_cloud_messenger/error.rb, line 44
def short_message
  parsed_response["error"]["message"]
end

Private Instance Methods

error_message() click to toggle source
# File lib/firebase_cloud_messenger/error.rb, line 50
    def error_message
      return nil if response.nil?

      <<-MSG


Status: #{response_status}

Message: #{short_message}

Details: #{details}
      MSG
    end