Class: LHC::Formats::JSON
- Inherits:
-
LHC::Format
- Object
- LHC::Format
- LHC::Formats::JSON
- Includes:
- BasicMethodsConcern
- Defined in:
- lib/lhc/formats/json.rb
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(input) ⇒ Object
- #as_open_struct(input) ⇒ Object
- #format_options(options) ⇒ Object
- #to_body(input) ⇒ Object
- #to_s ⇒ Object
- #to_sym ⇒ Object
Class Method Details
.request(options) ⇒ Object
7 8 9 10 |
# File 'lib/lhc/formats/json.rb', line 7 def self.request() [:format] = new super() end |
Instance Method Details
#as_json(input) ⇒ Object
21 22 23 |
# File 'lib/lhc/formats/json.rb', line 21 def as_json(input) parse(input, Hash) end |
#as_open_struct(input) ⇒ Object
25 26 27 |
# File 'lib/lhc/formats/json.rb', line 25 def as_open_struct(input) parse(input, OpenStruct) end |
#format_options(options) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/lhc/formats/json.rb', line 12 def () [:headers] ||= {} no_content_type_header!() [:headers]['Content-Type'] = 'application/json; charset=utf-8' no_accept_header!() [:headers]['Accept'] = 'application/json; charset=utf-8' end |
#to_body(input) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/lhc/formats/json.rb', line 29 def to_body(input) if input.is_a?(String) input else input.to_json end end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/lhc/formats/json.rb', line 37 def to_s 'json' end |
#to_sym ⇒ Object
41 42 43 |
# File 'lib/lhc/formats/json.rb', line 41 def to_sym to_s.to_sym end |