Sha256: 492c8158446cfc5f2e7e5ca7945971d7b19a2c05bd03a39af380b9cc9e1e4466
Contents?: true
Size: 1.08 KB
Versions: 46
Compression:
Stored size: 1.08 KB
Contents
# frozen_string_literal: true module LHC::Formats class JSON < LHC::Format include LHC::BasicMethodsConcern def self.request(options) options[:format] = new super(options) end 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 def as_json(input) parse(input, Hash) end def as_open_struct(input) parse(input, OpenStruct) end def to_body(input) if input.is_a?(String) input else input.to_json end end def to_s 'json' end def to_sym to_s.to_sym end private def parse(input, object_class) ::JSON.parse(input, object_class: object_class) rescue ::JSON::ParserError => e raise LHC::ParserError.new(e.message, input) end end end
Version data entries
46 entries across 46 versions & 1 rubygems