Class: Pntfr::Session::GcmResponse

Inherits:
BaseResponse show all
Defined in:
lib/pntfr/session/gcm_response.rb

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ GcmResponse

Returns a new instance of GcmResponse.



10
11
12
13
14
15
16
17
18
19
# File 'lib/pntfr/session/gcm_response.rb', line 10

def initialize json
  @raw= json
  @status_code= @raw[:status_code]
  @response= @raw[:response]
  @body= @raw[:body]
  if success?
    @parsed_body= JSON.parse(@body)
    @body_result= @parsed_body['results'].first
  end
end

Instance Method Details

#bad_sender_account?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/pntfr/session/gcm_response.rb', line 23

def bad_sender_account?
  @status_code == 401
end

#errorObject



35
36
37
38
39
# File 'lib/pntfr/session/gcm_response.rb', line 35

def error
  if error?
    @body_result['error']
  end
end

#error?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/pntfr/session/gcm_response.rb', line 32

def error?
  success? and !msg_sent? and @body_result.has_key?('error')
end

#failureObject



40
41
42
# File 'lib/pntfr/session/gcm_response.rb', line 40

def failure
  "#{@body}->#{@response}"
end

#failure?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/pntfr/session/gcm_response.rb', line 26

def failure?
  @status_code == 400 or @status_code >= 500
end

#msg_sent?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/pntfr/session/gcm_response.rb', line 29

def msg_sent?
  success? && @parsed_body['success'] == 1
end

#success?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/pntfr/session/gcm_response.rb', line 20

def success?
  @status_code == 200
end

#to_sObject



43
44
45
# File 'lib/pntfr/session/gcm_response.rb', line 43

def to_s
  @raw.to_s
end