Class: Duracloud::Manifest

Inherits:
Object
  • Object
show all
Includes:
TSV
Defined in:
lib/duracloud/manifest.rb

Constant Summary collapse

TSV_FORMAT =
"TSV"
BAGIT_FORMAT =
"BAGIT"
MAX_TRIES =
120
RETRY_SLEEP =
10

Constants included from TSV

TSV::CHUNK_SIZE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TSV

#csv, #load_tsv, #load_tsv_file, #rows, #table, #to_s, #tsv_source, #tsv_source?

Constructor Details

#initialize(space_id, store_id = nil) ⇒ Manifest

Returns a new instance of Manifest.



24
25
26
27
# File 'lib/duracloud/manifest.rb', line 24

def initialize(space_id, store_id = nil)
  @space_id = space_id
  @store_id = store_id
end

Instance Attribute Details

#space_idObject (readonly)

Returns the value of attribute space_id.



14
15
16
# File 'lib/duracloud/manifest.rb', line 14

def space_id
  @space_id
end

#store_idObject (readonly)

Returns the value of attribute store_id.



14
15
16
# File 'lib/duracloud/manifest.rb', line 14

def store_id
  @store_id
end

Class Method Details

.download(*args, **kwargs, &block) ⇒ Object



16
17
18
# File 'lib/duracloud/manifest.rb', line 16

def self.download(*args, **kwargs, &block)
  new(*args).download(**kwargs, &block)
end

.download_generated(*args, **kwargs, &block) ⇒ Object



20
21
22
# File 'lib/duracloud/manifest.rb', line 20

def self.download_generated(*args, **kwargs, &block)
  new(*args).download_generated(**kwargs, &block)
end

Instance Method Details

#bagit {|String| ... } ⇒ Duracloud::Response

Downloads the manifest in BAGIT format.

Yields:

  • (String)

    chunk of the manifest, if block given.

Returns:

Raises:



43
44
45
# File 'lib/duracloud/manifest.rb', line 43

def bagit(&block)
  download(BAGIT_FORMAT, &block)
end

#download(format: TSV_FORMAT) {|String| ... } ⇒ Duracloud::Response, String

Note:

format parameter changed from positional to keyword argument in v0.5.0.

Downloads the manifest

Parameters:

  • format (Symbol, String) (defaults to: TSV_FORMAT)

    the format of the manifest. Defaults to “TSV”.

Yields:

  • (String)

    chunk of the manifest, if block given.

Returns:

  • (Duracloud::Response, String)

    the response, if block given, or the manifest content, if no block.

Raises:



92
93
94
95
96
97
98
99
# File 'lib/duracloud/manifest.rb', line 92

def download(format: TSV_FORMAT, &block)
  fmt = format.to_s.upcase
  if block_given?
    get_response(fmt, &block)
  else
    get_response(fmt).body
  end
end

#download_generated(format: TSV_FORMAT, max_tries: MAX_TRIES, retry_sleep: RETRY_SLEEP) {|String| ... } ⇒ Object

Downloads the generated manifest

Parameters:

  • format (Symbol, String) (defaults to: TSV_FORMAT)

    the format of the manifest. Defaults to “TSV”.

  • max_tries (Integer) (defaults to: MAX_TRIES)

    max number of times to check the generated URL.

  • retry_sleep (Integer) (defaults to: RETRY_SLEEP)

    number of seconds between re-checks of the generated URL.

Yields:

  • (String)

    chunk of the manifest

Raises:



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/duracloud/manifest.rb', line 68

def download_generated(format: TSV_FORMAT, max_tries: MAX_TRIES, retry_sleep: RETRY_SLEEP, &block)
  url = generate(format: format)
  check_generated(url, max_tries, retry_sleep)
  Tempfile.open(["download", ".gz"], encoding: "ascii-8bit") do |gz_file|
    client.execute(Request, :get, url) do |chunk|
      gz_file.write(chunk)
    end
    gz_file.close
    Zlib::GzipReader.open(gz_file.path) do |unzipped|
      unzipped.each { |line| yield(line) }
    end
  end
  url
end

#generate(format: TSV_FORMAT) ⇒ String

Note:

format parameter changed from positional to keyword argument in v0.5.0.

Request the manifest for the space to be generated.

Parameters:

  • format (Symbol, String) (defaults to: TSV_FORMAT)

    the format of the manifest. Defaults to “TSV”.

Returns:

  • (String)

    the URL of the generated manifest when available.

Raises:



54
55
56
57
58
# File 'lib/duracloud/manifest.rb', line 54

def generate(format: TSV_FORMAT)
  fmt = format.to_s.upcase
  response = Client.generate_manifest(space_id, query(fmt))
  response.header["Location"].first
end

#tsv {|String| ... } ⇒ Duracloud::Response, ...

Returns the manifest in TSV format,

downloading from DuraCloud is not pre-loaded.

Yields:

  • (String)

    chunk of the manifest, if block given.

Returns:

Raises:



35
36
37
# File 'lib/duracloud/manifest.rb', line 35

def tsv(&block)
  tsv_source? ? super : download(TSV_FORMAT, &block)
end