Sha256: 4725bc6988d0f7a63a20257ab9a4a89cc80be2ee25a9f40c453c5e8ec6866ae7
Contents?: true
Size: 651 Bytes
Versions: 6
Compression:
Stored size: 651 Bytes
Contents
require 'oj' require 'ox' require 'dagger/ox_extension' class Parsers def initialize(response) @body = response.body @normalized = response.content_type.to_s.split(';').first.gsub(/[^a-z]/, '_') end def process send(@normalized, @body) if respond_to?(@normalized) end def application_json(body) Oj.load(body) rescue Oj::ParseError nil end alias_method :text_javascript, :application_json alias_method :application_x_javascript, :application_json def text_xml(body) if res = Ox.parse(body) res.to_hash end rescue Ox::ParseError nil end alias_method :application_xml, :text_xml end
Version data entries
6 entries across 6 versions & 1 rubygems