Sha256: 675ff3fc86d9140a1b2ce5d56d9f07749f4129c72fd8bc5be58b1bee8f9dd822

Contents?: true

Size: 884 Bytes

Versions: 2

Compression:

Stored size: 884 Bytes

Contents

# -*- encoding : utf-8 -*-

module Pacto
  module Handlers
    autoload :JSONHandler, 'pacto/handlers/json_handler'
    autoload :TextHandler, 'pacto/handlers/text_handler'
    autoload :XMLHandler,  'pacto/handlers/xml_handler'
  end
  module BodyParsing
    def raw_body
      return nil if body.nil?
      return body if body.respond_to? :to_str

      body_handler.raw(body)
    end

    def parsed_body
      return nil if body.nil?

      body_handler.parse(body)
    end

    def content_type
      headers['Content-Type']
    end

    def body_handler
      case content_type
      when /\bjson$/
        Pacto::Handlers::JSONHandler
      when /\btext$/
        Pacto::Handlers::TextHandler
      # No XML support - yet
      # when /\bxml$/
      #   XMLHandler
      else
        # JSON is still the default
        Pacto::Handlers::JSONHandler
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pacto-0.4.0.rc3 lib/pacto/body_parsing.rb
pacto-0.4.0.rc2 lib/pacto/body_parsing.rb