Class: ChangeHealth::Response::ResponseData
- Inherits:
-
Object
- Object
- ChangeHealth::Response::ResponseData
- Defined in:
- lib/change_health/response/response_data.rb
Direct Known Subclasses
Claim::ReportData, Claim::ReportListData, Claim::SubmissionData, EligibilityData
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #errors ⇒ Object
-
#errors? ⇒ Boolean
rubocop:enable Lint/SuppressedException.
-
#initialize(data: nil, response: nil) ⇒ ResponseData
constructor
rubocop:disable Lint/SuppressedException.
- #recommend_retry? ⇒ Boolean
- #request_body ⇒ Object
- #server_error ⇒ Object
Constructor Details
#initialize(data: nil, response: nil) ⇒ ResponseData
rubocop:disable Lint/SuppressedException
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/change_health/response/response_data.rb', line 9 def initialize(data: nil, response: nil) @response = response @raw = data begin @raw ||= response&.parsed_response rescue JSON::ParserError end @raw ||= {} end |
Instance Attribute Details
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
6 7 8 |
# File 'lib/change_health/response/response_data.rb', line 6 def raw @raw end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
6 7 8 |
# File 'lib/change_health/response/response_data.rb', line 6 def response @response end |
Instance Method Details
#errors ⇒ Object
28 29 30 31 32 |
# File 'lib/change_health/response/response_data.rb', line 28 def errors errors = @raw['errors'] || [] errors.flatten.map { |error| ChangeHealth::Response::Error.new(error) } end |
#errors? ⇒ Boolean
rubocop:enable Lint/SuppressedException
22 23 24 25 26 |
# File 'lib/change_health/response/response_data.rb', line 22 def errors? field_error = errors.is_a?(Array) && false == errors.empty? field_error || server_error.is_a?(ChangeHealthException) end |
#recommend_retry? ⇒ Boolean
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/change_health/response/response_data.rb', line 38 def recommend_retry? return false unless errors? return true if errors.any?(&:represents_down?) error_codes = errors.select(&:code?) return false if error_codes.empty? error_codes.all?(&:retryable?) end |
#request_body ⇒ Object
50 51 52 |
# File 'lib/change_health/response/response_data.rb', line 50 def request_body @response.request.[:body] unless @response&.request&..nil? end |
#server_error ⇒ Object
34 35 36 |
# File 'lib/change_health/response/response_data.rb', line 34 def server_error ChangeHealthException.from_response(@response, msg: 'Request') if @raw['error'] end |