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
-
#initialize(connection:, version:, object_identifier:) ⇒ Files
constructor
A new instance of Files.
-
#list ⇒ Array<String>
Get the list of files in the workspace.
-
#preserved_content(filename:, version:) ⇒ String
Get the preserved file contents.
-
#retrieve(filename:) ⇒ String
Get the contents from the workspace.
Constructor Details
#initialize(connection:, version:, object_identifier:) ⇒ Files
Returns a new instance of Files.
9 10 11 12 |
# File 'lib/dor/services/client/files.rb', line 9 def initialize(connection:, version:, object_identifier:) super(connection: connection, version: version) @object_identifier = object_identifier end |
Instance Method Details
#list ⇒ Array<String>
Get the list of files in the workspace
41 42 43 44 45 46 47 48 49 |
# File 'lib/dor/services/client/files.rb', line 41 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 |
#preserved_content(filename:, version:) ⇒ String
Get the preserved file contents
30 31 32 33 34 35 36 37 |
# File 'lib/dor/services/client/files.rb', line 30 def preserved_content(filename:, version:) resp = connection.get do |req| req.url "#{api_version}/sdr/objects/#{object_identifier}/content/#{CGI.escape(filename)}?version=#{version}" end return unless resp.success? resp.body end |
#retrieve(filename:) ⇒ String
Get the contents from the workspace
17 18 19 20 21 22 23 24 |
# File 'lib/dor/services/client/files.rb', line 17 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 |