Sha256: 7015b95ccd5e6a9d1954ab7a23705d9e65a4f941018e1b33c4dc135f8fad2f81

Contents?: true

Size: 1.23 KB

Versions: 5

Compression:

Stored size: 1.23 KB

Contents

require 'pact_broker/api/resources/base_resource'

module PactBroker
  module Api
    module Resources
      class Tag < BaseResource

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

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

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

        def from_json
          unless tag
            @tag = tag_service.create identifier_from_path
            # Make it return a 201 by setting the Location header
            response.headers["Location"] = tag_url(base_url, tag)
            matrix_service.refresh_tags(identifier_from_path)
          end
          response.body = to_json
        end

        def resource_exists?
          tag
        end

        def to_json
          PactBroker::Api::Decorators::TagDecorator.new(tag).to_json(user_options: { base_url: base_url })
        end

        def tag
          @tag ||= tag_service.find identifier_from_path
        end

        def delete_resource
          matrix_service.refresh_tags(identifier_from_path) do
            tag_service.delete identifier_from_path
          end
          true
        end
      end
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pact_broker-2.24.0 lib/pact_broker/api/resources/tag.rb
pact_broker-2.23.4 lib/pact_broker/api/resources/tag.rb
pact_broker-2.23.3 lib/pact_broker/api/resources/tag.rb
pact_broker-2.23.2 lib/pact_broker/api/resources/tag.rb
pact_broker-2.23.1 lib/pact_broker/api/resources/tag.rb