Class: Firebase::Messaging::Response
- Inherits:
-
Object
- Object
- Firebase::Messaging::Response
show all
- Defined in:
- lib/firebase/messaging/response.rb,
lib/firebase/messaging/response/topic_message.rb,
lib/firebase/messaging/response/down_stream_http_message.rb
Defined Under Namespace
Classes: DownStreamHttpMessage, TopicMessage
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(status: nil, body: nil, headers: nil) ⇒ Response
Returns a new instance of Response.
12
13
14
15
16
|
# File 'lib/firebase/messaging/response.rb', line 12
def initialize(status: nil, body: nil, headers: nil)
@status = status.to_i
@body = body
=
end
|
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
10
11
12
|
# File 'lib/firebase/messaging/response.rb', line 10
def body
@body
end
|
Returns the value of attribute headers.
10
11
12
|
# File 'lib/firebase/messaging/response.rb', line 10
def
end
|
#status ⇒ Object
Returns the value of attribute status.
10
11
12
|
# File 'lib/firebase/messaging/response.rb', line 10
def status
@status
end
|
Class Method Details
.bind(type, status: nil, body: nil, headers: nil) ⇒ Object
46
47
48
49
50
51
52
53
|
# File 'lib/firebase/messaging/response.rb', line 46
def bind(type, status: nil, body: nil, headers: nil)
if json?(body)
"Firebase::Messaging::Response::#{type.to_s.classify}".constantize.new(status: status, body: body, headers: )
else
Firebase::Messaging.logger.error("Unexpected response. status: #{status}, body: #{body}")
raise Firebase::Messaging::UnexpectedResponseError, { status: status, body: body, headers: }.to_s
end
end
|
.json?(json) ⇒ Boolean
39
40
41
42
43
44
|
# File 'lib/firebase/messaging/response.rb', line 39
def json?(json)
JSON.parse(json)
true
rescue JSON::ParserError
false
end
|
Instance Method Details
#errors ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/firebase/messaging/response.rb', line 26
def errors
if parsed_body.key? :error
[{ error: parsed_body[:error] }]
else
[]
end
end
|
#failure? ⇒ Boolean
22
23
24
|
# File 'lib/firebase/messaging/response.rb', line 22
def failure?
!success?
end
|
#parsed_body ⇒ Object
34
35
36
|
# File 'lib/firebase/messaging/response.rb', line 34
def parsed_body
@parsed_body ||= JSON.parse(body, symbolize_names: true)
end
|
#success? ⇒ Boolean
18
19
20
|
# File 'lib/firebase/messaging/response.rb', line 18
def success?
status >= 200 && status < 400
end
|