Sha256: 94d874fcfe08f8ed2dae4e1696c3ca54bc9bc0c989f636e39b45a7cef194c32a
Contents?: true
Size: 860 Bytes
Versions: 8
Compression:
Stored size: 860 Bytes
Contents
require 'json' module Restfully module Parsing class ParserNotFound < Restfully::Error; end def unserialize(object, options = {}) content_type = options[:content_type] content_type ||= object.headers['Content-Type'] if object.respond_to?(:headers) case content_type when /^application\/.*?json/i JSON.parse(object) else raise ParserNotFound.new("Content-Type '#{content_type}' is not supported. Cannot parse the given object.") end end def serialize(object, options = {}) content_type = options[:content_type] content_type ||= object.headers['Content-Type'] if object.respond_to?(:headers) case content_type when /^application\/.*?json/i JSON.dump(object) else raise ParserNotFound, [object, content_type] end end end end
Version data entries
8 entries across 8 versions & 1 rubygems