Sha256: 1252bdae9b296bdf343b6fa774b85d24c5dae92f55f3113629073272873c0a39
Contents?: true
Size: 917 Bytes
Versions: 1
Compression:
Stored size: 917 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) when /^text\/.*?(plain|html)/i object.to_s 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
restfully-0.5.3 | lib/restfully/parsing.rb |