Module: PatchRetention::Util
- Included in:
- Contacts::Delete, Contacts::Find, Contacts::FindOrCreate, Contacts::Update, Events::Create, Events::Find
- Defined in:
- lib/patch_retention/util.rb
Overview
The Util module provides utility methods used across the PatchRetention library. These methods are designed to handle common tasks such as error handling and response parsing.
Instance Method Summary collapse
-
#parse_error_message(response) ⇒ String
Extracts error message from the response.
-
#raise_error_if_present {|response| ... } ⇒ response
Raises a PatchRetention::Error if the yielded block’s response status is not 200.
Instance Method Details
#parse_error_message(response) ⇒ String
Extracts error message from the response.
23 24 25 26 27 28 29 30 31 |
# File 'lib/patch_retention/util.rb', line 23 def (response) if response.body.is_a?(Hash) && response.body["error"] response.body["error"] elsif response.status == 502 "Internal Server Error: Patch API" else "Request failed with status #{response.status}" end end |
#raise_error_if_present {|response| ... } ⇒ response
Raises a PatchRetention::Error if the yielded block’s response status is not 200.
10 11 12 13 14 15 16 17 18 |
# File 'lib/patch_retention/util.rb', line 10 def raise_error_if_present response = yield raise PatchRetention::Error, (response) unless response.status.between?(200, 206) case response.body when Hash, Array then response.body else true end end |