Sha256: 39fc02f1fdec8b9419220e96963adb4dc0a80b885cff8c140b29142251cc92cd

Contents?: true

Size: 822 Bytes

Versions: 1

Compression:

Stored size: 822 Bytes

Contents

require 'webmachine'
require 'json'

module PactBroker

  module Resources

    module PathInfo
      def identifier_from_path
        request.path_info.each_with_object({}) do | pair, hash|
          hash[pair.first] = CGI::unescape(pair.last)
        end
      end
    end

    class ErrorHandler
      def self.handle_exception e, response
        response.body = {:message => e.message, :backtrace => e.backtrace }.to_json
        response.code = 500
      end
    end

    class JsonResource < Webmachine::Resource
      def content_types_provided
        [["application/json", :to_json]]
      end

      def content_types_accepted
        [["application/json", :from_json]]
      end

      def handle_exception e
        PactBroker::Resources::ErrorHandler.handle_exception(e, response)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pact_broker-0.0.5 lib/pact_broker/resources/json_resource.rb