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
-
#initialize(data: nil, response: nil) ⇒ ResponseData
constructor
A new instance of ResponseData.
- #recommend_retry? ⇒ Boolean
- #server_error ⇒ Object
Constructor Details
#initialize(data: nil, response: nil) ⇒ ResponseData
Returns a new instance of ResponseData.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/change_health/response/response_data.rb', line 6 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.
4 5 6 |
# File 'lib/change_health/response/response_data.rb', line 4 def raw @raw end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
4 5 6 |
# File 'lib/change_health/response/response_data.rb', line 4 def response @response end |
Instance Method Details
#errors ⇒ Object
24 25 26 27 28 |
# File 'lib/change_health/response/response_data.rb', line 24 def errors errors = @raw.dig('errors') || [] errors.flatten.map { |error| ChangeHealth::Response::Error.new(error) } end |
#errors? ⇒ Boolean
18 19 20 21 22 |
# File 'lib/change_health/response/response_data.rb', line 18 def errors? field_error = errors.is_a?(Array) && false == errors.empty? field_error || server_error.is_a?(ChangeHealthException) end |
#recommend_retry? ⇒ Boolean
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/change_health/response/response_data.rb', line 34 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 |
#server_error ⇒ Object
30 31 32 |
# File 'lib/change_health/response/response_data.rb', line 30 def server_error ChangeHealthException.from_response(@response, msg: 'Request') if @raw.dig('error') end |