Class: ExpoNotifier::Response

Inherits:
Object
  • Object
show all
Extended by:
T::Generic
Defined in:
lib/expo_notifier/response.rb

Constant Summary collapse

Body =
type_member(:out) { { upper: Mapper::Base } }

Instance Attribute Summary collapse

Instance Method Summary collapse

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_errorObject (readonly)

: Faraday::Error?



23
24
25
# File 'lib/expo_notifier/response.rb', line 23

def communication_error
  @communication_error
end

#durationObject (readonly)

: Float



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

def duration
  @duration
end

#headersObject (readonly)

: Hash[(String | Symbol), String]?



14
15
16
# File 'lib/expo_notifier/response.rb', line 14

def headers
  @headers
end

#raw_bodyObject (readonly)

: String?



17
18
19
# File 'lib/expo_notifier/response.rb', line 17

def raw_body
  @raw_body
end

#status_codeObject (readonly)

: Integer?



11
12
13
# File 'lib/expo_notifier/response.rb', line 11

def status_code
  @status_code
end

Instance Method Details

#bodyObject

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

Returns:



70
71
72
# File 'lib/expo_notifier/response.rb', line 70

def communication_error?
  !!communication_error
end

#communication_error_messageObject

: -> String?



43
44
45
46
47
# File 'lib/expo_notifier/response.rb', line 43

def communication_error_message
  return unless communication_error

  "[#{communication_error.class}] => #{T.must(communication_error).message}"
end

#malformed_request_error?Boolean

: -> bool

Returns:



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

Returns:



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

Returns:



50
51
52
# File 'lib/expo_notifier/response.rb', line 50

def success?
  @status_code == 200
end

#too_many_requests_error?Boolean

: -> bool

Returns:



55
56
57
# File 'lib/expo_notifier/response.rb', line 55

def too_many_requests_error?
  @status_code == 429
end