Class: LHC::Formats::JSON

Inherits:
LHC::Format show all
Includes:
BasicMethodsConcern
Defined in:
lib/lhc/formats/json.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.request(options) ⇒ Object



7
8
9
10
# File 'lib/lhc/formats/json.rb', line 7

def self.request(options)
  options[:format] = new
  super(options)
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 format_options(options)
  options[:headers] ||= {}
  no_content_type_header!(options)
  options[:headers]['Content-Type'] = 'application/json; charset=utf-8'
  no_accept_header!(options)
  options[:headers]['Accept'] = 'application/json; charset=utf-8'
  options
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_sObject



37
38
39
# File 'lib/lhc/formats/json.rb', line 37

def to_s
  'json'
end

#to_symObject



41
42
43
# File 'lib/lhc/formats/json.rb', line 41

def to_sym
  to_s.to_sym
end