Class: SdrClient::RedesignedClient::RequestBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/sdr_client/redesigned_client/request_builder.rb

Overview

Builds a Cocina request object from metadata. This is what we send to the server when doing a deposit.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(apo:, source_id:, **options) ⇒ RequestBuilder

Additional metadata includes access, preserve, shelve, publish, md5, sha1

Parameters:

  • apo (String)

    the object ID of the administrative policy object

  • source_id (String)

    the source ID of the object

  • options (Hash)

    optional parameters

Options Hash (**options):

  • label (String)

    the required object label

  • view (String)

    the access level for viewing the object

  • download (String)

    the access level for downloading the object

  • location (String)

    the location for location-based access

  • type (String) — default: https://cocina.sul.stanford.edu/models/object

    the required object type.

  • use_and_reproduction (String)

    the use and reproduction statement

  • copyright (String)

    the copyright statement

  • collection (String)

    the object ID of the collection object

  • catkey (String)

    the catalog key (from now unused Symphony ILS)

  • folio_instance_hrid (String)

    the instance ID from the Folio ILS

  • viewing_direction (String)

    the viewing direction (left to right, right to left)

  • embargo_release_date (Date|nil)

    when to release the embargo (or nil if none)

  • embargo_access (String)

    the access level for viewing the object after the embargo period

  • embargo_download (String)

    the access level for downloading the object after the embargo period

  • file_sets (Array<FileSet>)

    the file sets to attach.

  • files_metadata (Hash<String, Hash<String, String>>)

    file name, hash of additional file metadata



27
28
29
30
31
# File 'lib/sdr_client/redesigned_client/request_builder.rb', line 27

def initialize(apo:, source_id:, **options)
  @apo = apo
  @source_id = source_id
  @options = options
end

Instance Attribute Details

#file_sets=(value) ⇒ Object

Sets the attribute file_sets

Parameters:

  • value

    the value to set the attribute file_sets to.



65
66
67
# File 'lib/sdr_client/redesigned_client/request_builder.rb', line 65

def file_sets=(value)
  @file_sets = value
end

Instance Method Details

#for(filename) ⇒ Hash

Returns the metadata for the file.

Parameters:

  • filename (String)

Returns:

  • (Hash)

    the metadata for the file



51
52
53
54
55
56
57
58
59
# File 'lib/sdr_client/redesigned_client/request_builder.rb', line 51

def for(filename)
  
    .fetch(filename, {})
    .with_indifferent_access
    .tap do ||
    [:view] = view unless .key?(:view)
    [:download] = download unless .key?(:download)
  end
end

#to_cocinaObject



45
46
47
# File 'lib/sdr_client/redesigned_client/request_builder.rb', line 45

def to_cocina
  Cocina::Models.build_request(to_h.with_indifferent_access)
end

#to_hObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/sdr_client/redesigned_client/request_builder.rb', line 33

def to_h
  {
    access: access_struct,
    type: type,
    administrative: administrative,
    identification: identification,
    structural: structural,
    version: 1,
    label: label.nil? ? ':auto' : label
  }
end

#typeObject



61
62
63
# File 'lib/sdr_client/redesigned_client/request_builder.rb', line 61

def type
  options.fetch(:type, Cocina::Models::ObjectType.object)
end