Class: Maia::FCM::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/maia/fcm/response.rb

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.


4
5
6
# File 'lib/maia/fcm/response.rb', line 4

def initialize(response)
  @response = response
end

Instance Method Details

#bodyObject


8
9
10
# File 'lib/maia/fcm/response.rb', line 8

def body
  @response.body
end

#errorObject


24
25
26
27
28
29
30
31
# File 'lib/maia/fcm/response.rb', line 24

def error
  case json.dig('error', 'status')
  when 'UNREGISTERED'
    Maia::Error::Unregistered.new
  else
    Maia::Error::Generic.new json.dig('error', 'message')
  end
end

#fail?Boolean

Returns:

  • (Boolean)

20
21
22
# File 'lib/maia/fcm/response.rb', line 20

def fail?
  !success?
end

#statusObject


12
13
14
# File 'lib/maia/fcm/response.rb', line 12

def status
  @response.code.to_i
end

#success?Boolean

Returns:

  • (Boolean)

16
17
18
# File 'lib/maia/fcm/response.rb', line 16

def success?
  (200..399).cover? status
end