Class: Dor::Services::Client::Files
- Inherits:
-
VersionedService
- Object
- VersionedService
- Dor::Services::Client::Files
- Defined in:
- lib/dor/services/client/files.rb
Overview
API calls relating to files
Instance Method Summary collapse
-
#list(object:) ⇒ Array<String>
Get the list of files in the workspace.
-
#preserved_content(object:, filename:, version:) ⇒ String
Get the preserved file contents.
-
#retrieve(object:, filename:) ⇒ String
Get the contents from the workspace.
Methods inherited from VersionedService
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
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
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
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 |