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



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 format_options(options)
  options[:headers] ||= {}
  no_content_type_header!(options)
  no_accept_header!(options)

  options[:headers]['Content-Type'] = 'application/json; charset=utf-8'
  options[:headers]['Accept'] = 'application/json,application/vnd.api+json'
  options[:headers]['Accept-Charset'] = 'utf-8'
  options
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_sObject



39
40
41
# File 'lib/lhc/formats/json.rb', line 39

def to_s
  'json'
end

#to_symObject



43
44
45
# File 'lib/lhc/formats/json.rb', line 43

def to_sym
  to_s.to_sym
end