Class: Dor::Services::Client::Files

Inherits:
VersionedService show all
Defined in:
lib/dor/services/client/files.rb

Overview

API calls relating to files

Instance Method Summary collapse

Methods inherited from VersionedService

#initialize

Constructor Details

This class inherits a constructor from Dor::Services::Client::VersionedService

Instance Method Details

#list(object:) ⇒ Array<String>

Get the list of files in the workspace

Parameters:

  • object (String)

    the identifier for the object

Returns:

  • (Array<String>)

    the list of filenames in the workspace



38
39
40
41
42
43
44
45
46
# File 'lib/dor/services/client/files.rb', line 38

def list(object:)
  resp = connection.get do |req|
    req.url "#{api_version}/objects/#{object}/contents"
  end
  return [] unless resp.success?

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

#preserved_content(object:, filename:, version:) ⇒ String

Get the preserved file contents

Parameters:

  • object (String)

    the identifier for the object

  • filename (String)

    the name of the file to retrieve

  • version (Integer)

    the version of the file to retrieve

Returns:

  • (String)

    the file contents from the SDR



26
27
28
29
30
31
32
33
# File 'lib/dor/services/client/files.rb', line 26

def preserved_content(object:, filename:, version:)
  resp = connection.get do |req|
    req.url "#{api_version}/sdr/objects/#{object}/content/#{CGI.escape(filename)}?version=#{version}"
  end
  return unless resp.success?

  resp.body
end

#retrieve(object:, filename:) ⇒ String

Get the contents from the workspace

Parameters:

  • object (String)

    the identifier for the object

  • filename (String)

    the name of the file to retrieve

Returns:

  • (String)

    the file contents from the workspace



12
13
14
15
16
17
18
19
# File 'lib/dor/services/client/files.rb', line 12

def retrieve(object:, filename:)
  resp = connection.get do |req|
    req.url "#{api_version}/objects/#{object}/contents/#{filename}"
  end
  return unless resp.success?

  resp.body
end