Sha256: 345bc356dfea27b05100c78094f96300184c50b7872a2210c9d05c43d4b005b8

Contents?: true

Size: 1.29 KB

Versions: 36

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module Dor
  module Services
    class Client
      # API calls relating to files
      class Files < VersionedService
        # @param object_identifier [String] the pid for the object
        def initialize(connection:, version:, object_identifier:)
          super(connection: connection, version: version)
          @object_identifier = object_identifier
        end

        # Get the contents from the workspace
        # @param [String] filename the name of the file to retrieve
        # @return [String] the file contents from the workspace
        def retrieve(filename:)
          resp = connection.get do |req|
            req.url "#{api_version}/objects/#{object_identifier}/contents/#{filename}"
          end
          return unless resp.success?

          resp.body
        end

        # Get the list of files in the workspace
        # @return [Array<String>] the list of filenames in the workspace
        def list
          resp = connection.get do |req|
            req.url "#{api_version}/objects/#{object_identifier}/contents"
          end
          return [] unless resp.success?

          json = JSON.parse(resp.body)
          json['items'].map { |item| item['name'] }
        end

        private

        attr_reader :object_identifier
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
dor-services-client-6.7.0 lib/dor/services/client/files.rb
dor-services-client-6.6.1 lib/dor/services/client/files.rb
dor-services-client-6.6.0 lib/dor/services/client/files.rb
dor-services-client-6.5.0 lib/dor/services/client/files.rb
dor-services-client-6.4.0 lib/dor/services/client/files.rb
dor-services-client-6.3.1 lib/dor/services/client/files.rb
dor-services-client-6.3.0 lib/dor/services/client/files.rb
dor-services-client-6.2.0 lib/dor/services/client/files.rb
dor-services-client-6.1.0 lib/dor/services/client/files.rb
dor-services-client-6.0.0 lib/dor/services/client/files.rb
dor-services-client-5.2.0 lib/dor/services/client/files.rb
dor-services-client-5.1.0 lib/dor/services/client/files.rb
dor-services-client-5.0.0 lib/dor/services/client/files.rb
dor-services-client-4.20.0 lib/dor/services/client/files.rb
dor-services-client-4.19.0 lib/dor/services/client/files.rb
dor-services-client-4.18.0 lib/dor/services/client/files.rb
dor-services-client-4.17.1 lib/dor/services/client/files.rb
dor-services-client-4.17.0 lib/dor/services/client/files.rb
dor-services-client-4.16.0 lib/dor/services/client/files.rb
dor-services-client-4.15.0 lib/dor/services/client/files.rb