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
23 24 25 |
# File 'lib/lhc/formats/json.rb', line 23 def as_json(input) parse(input, Hash) end |
#as_open_struct(input) ⇒ Object
27 28 29 |
# File 'lib/lhc/formats/json.rb', line 27 def as_open_struct(input) parse(input, OpenStruct) end |
#format_options(options) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/lhc/formats/json.rb', line 12 def () [:headers] ||= {} no_content_type_header!() no_accept_header!() [:headers]['Content-Type'] = 'application/json; charset=utf-8' [:headers]['Accept'] = 'application/json,application/vnd.api+json' [:headers]['Accept-Charset'] = 'utf-8' end |
#to_body(input) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/lhc/formats/json.rb', line 31 def to_body(input) if input.is_a?(String) input else input.to_json end end |
#to_s ⇒ Object
39 40 41 |
# File 'lib/lhc/formats/json.rb', line 39 def to_s 'json' end |
#to_sym ⇒ Object
43 44 45 |
# File 'lib/lhc/formats/json.rb', line 43 def to_sym to_s.to_sym end |