Module: Zenodo::DSL::DepositionFiles

Included in:
Zenodo::DSL
Defined in:
lib/zenodo/dsl/deposition_files.rb

Instance Method Summary collapse

Instance Method Details

#create_deposition_file(options = {}) ⇒ Zenodo::Resources::DepositionFile

Create (upload) POST deposit/depositions/:id/files Upload a new file. Note the upload will fail if the filename already exists.

Parameters:

  • options (Hash) (defaults to: {})

    The options to create a deposition file with.

Options Hash (options):

  • :id (String, Fixnum)

    A deposition’s ID.

  • file_or_io (String, IO)

    The file or already open IO to upload.

  • filename (String)

    The name of the file (optional except when an IO).

  • content_type (String)

    The content type of the file (optional except when an IO).

Returns:

Raises:

  • (ArgumentError)

    If the :id or :file_or_io arguments are blank.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/zenodo/dsl/deposition_files.rb', line 26

def create_deposition_file(options={})
  id = options[:id] || raise(ArgumentError, "Must supply :id")
  file_or_io = options[:file_or_io] || raise(ArgumentError, "Must supply :file_or_io")
  filename = options[:filename]
  content_type = options[:content_type]

  content_type = MIME::Types.type_for(file_or_io).first.content_type if content_type.blank?
  io = Faraday::UploadIO.new(file_or_io, content_type, filename)
  filename = File.basename(file_or_io) if filename.blank?
  Resources::DepositionFile.parse(
    request(:post, "deposit/depositions/#{id}/files", { name: filename, file: io },
      "Content-Type" => "multipart/form-data")
  )
end

#delete_deposition_file(options = {}) ⇒ Faraday::Response

Delete DELETE deposit/depositions/:id/files/:file_id Delete an existing deposition file resource. Note, only deposition files for unpublished depositions may be deleted.

Parameters:

  • options (Hash) (defaults to: {})

    The options to delete a deposition’s file with.

Returns:

  • (Faraday::Response)

    .

Raises:

  • (ArgumentError)

    If the :id or :file_id arguments are blank.



91
92
93
94
95
# File 'lib/zenodo/dsl/deposition_files.rb', line 91

def delete_deposition_file(options={})
  id = options[:id] || raise(ArgumentError, "Must supply :id")
  file_id = options[:file_id] || raise(ArgumentError, "Must supply :file_id")
  request(:delete, "deposit/depositions/#{id}/files/#{file_id}", nil, nil)
end

#get_deposition_file(options = {}) ⇒ Zenodo::Resources::DepositionFile

Retrieve GET deposit/depositions/:id/files/:file_id Retrieve a single deposition file.

Parameters:

  • options (Hash) (defaults to: {})

    The options to get a deposition’s file with.

Options Hash (options):

  • :id (String, Fixnum)

    A deposition’s ID.

  • :file_id (String)

    A deposition file ID.

Returns:

Raises:

  • (ArgumentError)

    If :id or :file_id arguments are blank.



61
62
63
64
65
# File 'lib/zenodo/dsl/deposition_files.rb', line 61

def get_deposition_file(options={})
  id = options[:id] || raise(ArgumentError, "Must supply :id")
  file_id = options[:file_id] || raise(ArgumentError, "Must supply :file_id")
  Resources::DepositionFile.parse(request(:get, "deposit/depositions/#{id}/files/#{file_id}", nil))
end

#get_deposition_files(options = {}) ⇒ Array?

List GET deposit/depositions/:id/files List all deposition files for a given deposition.

Parameters:

  • options (Hash) (defaults to: {})

    The options to get a deposition with.

Options Hash (options):

  • :id (String, Fixnum)

    A deposition’s ID.

Returns:

  • (Array, nil)

    .

Raises:

  • (ArgumentError)

    If the given :id is blank.



11
12
13
14
# File 'lib/zenodo/dsl/deposition_files.rb', line 11

def get_deposition_files(options={})
  id = options[:id] || raise(ArgumentError, "Must supply :id")
  Resources::DepositionFile.parse(request(:get, "deposit/depositions/#{id}/files", nil))
end

#sort_deposition_files(options = {}) ⇒ Array?

Sort PUT deposit/depositions/:id/files Sort the files for a deposition. By default, the first file is shown in the file preview.

Parameters:

  • options (Hash) (defaults to: {})

    The options to sort a deposition’s files with.

Options Hash (options):

  • :id (String, Fixnum)

    A deposition’s ID.

  • :deposition_files (Array)

    The deposition files to sort.

Returns:

  • (Array, nil)

    .

Raises:

  • (ArgumentError)

    If :id or :deposition_files arguments are blank.



48
49
50
51
52
# File 'lib/zenodo/dsl/deposition_files.rb', line 48

def sort_deposition_files(options={})
  id = options[:id] || raise(ArgumentError, "Must supply :id")
  deposition_files = options[:deposition_files] || raise(ArgumentError, "Must supply :deposition_files")
  Resources::DepositionFile.parse(request(:put, "deposit/depositions/#{id}/files", deposition_files))
end

#update_deposition_file(options = {}) ⇒ Zenodo::Resources::DepositionFile

Update PUT deposit/depositions/:id/files/:file_id Update a deposition file resource. Currently the only use is renaming an already uploaded file. If you one to replace the actual file, please delete the file and upload a new file.

Parameters:

  • options (Hash) (defaults to: {})

    The options to update a deposition’s file with.

Returns:

Raises:

  • (ArgumentError)

    If the :id, :file_id, or :deposition_file arguments are blank.



76
77
78
79
80
81
# File 'lib/zenodo/dsl/deposition_files.rb', line 76

def update_deposition_file(options={})
  id = options[:id] || raise(ArgumentError, "Must supply :id")
  file_id = options[:file_id] || raise(ArgumentError, "Must supply :file_id")
  deposition_file = options[:deposition_file] || raise(ArgumentError, "Must supply :deposition_file")
  Resources::DepositionFile.parse(request(:put, "deposit/depositions/#{id}/files/#{file_id}", deposition_file))
end