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

Version Path
restfully-0.5.2 lib/restfully/parsing.rb
restfully-0.5.1 lib/restfully/parsing.rb
restfully-0.5.0 lib/restfully/parsing.rb
restfully-0.4.1 lib/restfully/parsing.rb
restfully-0.4.0 lib/restfully/parsing.rb
restfully-0.3.2 lib/restfully/parsing.rb
restfully-0.3.1 lib/restfully/parsing.rb
restfully-0.3.0 lib/restfully/parsing.rb