Sha256: 3ae022bdceb1d06c1deb7976242f0ab2e7bf3fb16ee9b3f92234462d5caffed7

Contents?: true

Size: 889 Bytes

Versions: 5

Compression:

Stored size: 889 Bytes

Contents

require 'cgi'
require 'pact_broker/api/resources/base_resource'

module PactBroker::Api

  module Resources

    class Pact < BaseResource

      def content_types_provided
        [["application/json", :to_json]]
      end

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

      def allowed_methods
        ["GET", "PUT"]
      end

      def resource_exists?
        @pact = pact_service.find_pact(identifier_from_path)
        @pact != nil
      end

      def from_json
        @pact, created = pact_service.create_or_update_pact(identifier_from_path.merge(:json_content => pact_content))
        response.headers["Location"] = pact_url(resource_url, @pact) if created
        response.body = to_json
      end

      def to_json
        @pact.json_content
      end

      def pact_content
        request.body.to_s
      end

    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pact_broker-1.0.0 lib/pact_broker/api/resources/pact.rb
pact_broker-1.0.0.alpha3 lib/pact_broker/api/resources/pact.rb
pact_broker-1.0.0.alpha2 lib/pact_broker/api/resources/pact.rb
pact_broker-1.0.0.alpha1 lib/pact_broker/api/resources/pact.rb
pact_broker-0.0.10 lib/pact_broker/api/resources/pact.rb