Sha256: ab296e3f163f5f14310d1279aedf6d36af229017956f52a98a1a1e9b84df9d34

Contents?: true

Size: 1.66 KB

Versions: 18

Compression:

Stored size: 1.66 KB

Contents

require 'pact_broker/api/resources/base_resource'
require 'pact_broker/configuration'
require 'pact_broker/domain/verification'
require 'pact_broker/api/contracts/verification_contract'
require 'pact_broker/api/decorators/verification_decorator'

module PactBroker
  module Api
    module Resources

      class Verifications < BaseResource

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

        def allowed_methods
          ["POST"]
        end

        def post_is_create?
          true
        end

        def resource_exists?
          !!pact
        end

        def malformed_request?
          if request.post?
            return true if invalid_json?
            errors = verification_service.errors(params)
            if !errors.empty?
              set_json_validation_error_messages(errors.messages)
              return true
            end
          end
          false
        end

        def create_path
          new_verification_url(pact_params, next_verification_number, base_url)
        end

        def from_json
          verification = verification_service.create(next_verification_number, params_with_string_keys, pact)
          response.body = decorator_for(verification).to_json(user_options: {base_url: base_url})
          true
        end

        private

        def pact
          @pact ||= pact_service.find_pact(pact_params)
        end

        def next_verification_number
          @next_verification_number ||= verification_service.next_number_for(pact)
        end

        def decorator_for model
          PactBroker::Api::Decorators::VerificationDecorator.new(model)
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
pact_broker-2.3.0 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.2.0 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.1.1 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.1.0 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.0.5 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.0.4 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.0.3 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.0.2 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.0.1 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.0.0 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.0.0.beta.8 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.0.0.beta.7 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.0.0.beta.6 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.0.0.beta.5 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.0.0.beta.4 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.0.0.beta.3 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.0.0.beta.2 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.0.0.beta.1 lib/pact_broker/api/resources/verifications.rb