Class: ExpoNotifier::Response
- Inherits:
-
Object
- Object
- ExpoNotifier::Response
- Extended by:
- T::Generic
- Defined in:
- lib/expo_notifier/response.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#communication_error ⇒ Object
readonly
: Faraday::Error?.
-
#duration ⇒ Object
readonly
: Float.
-
#headers ⇒ Object
readonly
: Hash[(String | Symbol), String]?.
-
#raw_body ⇒ Object
readonly
: String?.
-
#status_code ⇒ Object
readonly
: Integer?.
Instance Method Summary collapse
-
#body ⇒ Object
Response body mapped to Ruby objects.
-
#communication_error? ⇒ Boolean
: -> bool.
-
#communication_error_message ⇒ Object
: -> String?.
-
#initialize(body_class, duration, faraday_response) ⇒ Response
constructor
: (singleton(Mapper::Base), Float, (Faraday::Response | Faraday::Error)) -> void.
-
#malformed_request_error? ⇒ Boolean
: -> bool.
-
#server_error? ⇒ Boolean
: -> bool.
-
#success? ⇒ Boolean
: -> bool.
-
#too_many_requests_error? ⇒ Boolean
: -> bool.
Constructor Details
#initialize(body_class, duration, faraday_response) ⇒ Response
: (singleton(Mapper::Base), Float, (Faraday::Response | Faraday::Error)) -> void
26 27 28 29 30 31 32 33 34 |
# File 'lib/expo_notifier/response.rb', line 26 def initialize(body_class, duration, faraday_response) if faraday_response.is_a?(Faraday::Response) initialize_with_faraday_response(faraday_response) elsif faraday_response.is_a?(Faraday::Error) @communication_error = faraday_response #: Faraday::Error? end @body_class = body_class @duration = duration end |
Instance Attribute Details
#communication_error ⇒ Object (readonly)
: Faraday::Error?
23 24 25 |
# File 'lib/expo_notifier/response.rb', line 23 def communication_error @communication_error end |
#duration ⇒ Object (readonly)
: Float
20 21 22 |
# File 'lib/expo_notifier/response.rb', line 20 def duration @duration end |
#headers ⇒ Object (readonly)
: Hash[(String | Symbol), String]?
14 15 16 |
# File 'lib/expo_notifier/response.rb', line 14 def headers @headers end |
#raw_body ⇒ Object (readonly)
: String?
17 18 19 |
# File 'lib/expo_notifier/response.rb', line 17 def raw_body @raw_body end |
#status_code ⇒ Object (readonly)
: Integer?
11 12 13 |
# File 'lib/expo_notifier/response.rb', line 11 def status_code @status_code end |
Instance Method Details
#body ⇒ Object
Response body mapped to Ruby objects. : -> Body?
38 39 40 |
# File 'lib/expo_notifier/response.rb', line 38 def body @body ||= parse_response_body #: Body? end |
#communication_error? ⇒ Boolean
: -> bool
70 71 72 |
# File 'lib/expo_notifier/response.rb', line 70 def communication_error? !!communication_error end |
#communication_error_message ⇒ Object
: -> String?
43 44 45 46 47 |
# File 'lib/expo_notifier/response.rb', line 43 def return unless communication_error "[#{communication_error.class}] => #{T.must(communication_error).}" end |
#malformed_request_error? ⇒ Boolean
: -> bool
60 61 62 |
# File 'lib/expo_notifier/response.rb', line 60 def malformed_request_error? @status_code.to_s.start_with?('4') && !too_many_requests_error? end |
#server_error? ⇒ Boolean
: -> bool
65 66 67 |
# File 'lib/expo_notifier/response.rb', line 65 def server_error? @status_code.to_s.start_with?('5') end |
#success? ⇒ Boolean
: -> bool
50 51 52 |
# File 'lib/expo_notifier/response.rb', line 50 def success? @status_code == 200 end |
#too_many_requests_error? ⇒ Boolean
: -> bool
55 56 57 |
# File 'lib/expo_notifier/response.rb', line 55 def too_many_requests_error? @status_code == 429 end |