Class: Ace::Support::Models::Atoms::JsonParser
- Inherits:
-
Object
- Object
- Ace::Support::Models::Atoms::JsonParser
- Defined in:
- lib/ace/support/models/atoms/json_parser.rb
Overview
Parses JSON responses from the API
Class Method Summary collapse
-
.parse(json_string) ⇒ Hash
Parse JSON string.
-
.to_json(data, pretty: false) ⇒ String
Convert hash to JSON string.
Class Method Details
.parse(json_string) ⇒ Hash
Parse JSON string
16 17 18 19 20 |
# File 'lib/ace/support/models/atoms/json_parser.rb', line 16 def parse(json_string) JSON.parse(json_string) rescue JSON::ParserError => e raise ApiError, "Failed to parse JSON: #{e.}" end |
.to_json(data, pretty: false) ⇒ String
Convert hash to JSON string
26 27 28 29 30 31 32 |
# File 'lib/ace/support/models/atoms/json_parser.rb', line 26 def to_json(data, pretty: false) if pretty JSON.pretty_generate(data) else JSON.generate(data) end end |