Sha256: cddef7deae69471b9b4b2caa5680acd6cd5d97195f4793091cf5386740e88221

Contents?: true

Size: 963 Bytes

Versions: 4

Compression:

Stored size: 963 Bytes

Contents

require 'flipper/exporters/json/export'
require 'flipper/api/action'
require 'flipper/api/v1/decorators/feature'

module Flipper
  module Api
    module V1
      module Actions
        class Import < Api::Action
          route %r{\A/import/?\Z}

          def post
            # Rack 3 changed the requirement to rewind the body, so we can't assume it is rewound,
            # so rewind before under Rack 3+ and after under Rack 2.
            request.body.rewind if Gem::Version.new(Rack.release) >= Gem::Version.new('3.0.0')
            body = request.body.read
            request.body.rewind if Gem::Version.new(Rack.release) < Gem::Version.new('3.0.0')
            export = Flipper::Exporters::Json::Export.new(contents: body)
            flipper.import(export)
            json_response({}, 204)
          rescue Flipper::Exporters::Json::InvalidError
            json_error_response(:import_invalid)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
flipper-api-1.3.2 lib/flipper/api/v1/actions/import.rb
flipper-api-1.3.1 lib/flipper/api/v1/actions/import.rb
flipper-api-1.3.0 lib/flipper/api/v1/actions/import.rb
flipper-api-1.3.0.pre lib/flipper/api/v1/actions/import.rb