Sha256: f15d33e1db750158ad4ac696f900f3f4aedea3aea8103f8bc98076cf2e24bc2b

Contents?: true

Size: 1.66 KB

Versions: 22

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, 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

22 entries across 22 versions & 1 rubygems

Version Path
pact_broker-2.16.1 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.16.0 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.15.0 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.14.0 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.13.1 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.13.0 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.12.0 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.11.0 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.10.0 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.9.0 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.9.0.beta.5 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.8.0.beta.5 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.8.0.beta.4 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.7.0.beta.3 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.7.0.beta.2 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.7.0.beta.1 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.6.0 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.5.1 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.5.0 lib/pact_broker/api/resources/verifications.rb
pact_broker-2.4.2 lib/pact_broker/api/resources/verifications.rb