Module: CocinaDisplay::Concerns::Access

Included in:
CocinaDisplay::CocinaRecord
Defined in:
lib/cocina_display/concerns/access.rb

Overview

Methods that generate URLs to access an object.

Instance Method Summary collapse

Instance Method Details

#download_urlString

The download URL to get the entire object as a .zip file. Stacks generates the .zip for the object on request.

Examples:

record.download_url #=> "https://stacks.stanford.edu/object/bx658jh7339"

Returns:

  • (String)


55
56
57
# File 'lib/cocina_display/concerns/access.rb', line 55

def download_url
  "#{stacks_base_url}/object/#{bare_druid}"
end

#iiif_manifest_url(version: 3) ⇒ String

The IIIF manifest URL for the object. PURL generates the IIIF manifest.

Examples:

record.iiif_manifest_url #=> "https://purl.stanford.edu/bx658jh7339/iiif3/manifest"

Parameters:

  • version (Integer) (defaults to: 3)

    The IIIF presentation spec version to use (3 or 2).

Returns:

  • (String)


65
66
67
68
# File 'lib/cocina_display/concerns/access.rb', line 65

def iiif_manifest_url(version: 3)
  iiif_path = (version == 3) ? "iiif3" : "iiif"
  "#{purl_url}/#{iiif_path}/manifest"
end

#oembed_url(params: {}) ⇒ String?

The oEmbed URL for the object, optionally with additional parameters. Corresponds to the PURL environment.

Examples:

Generate an oEmbed URL for the viewer and hide the title

record.oembed_url(hide_title: true) #=> "https://purl.stanford.edu/bx658jh7339/embed.json?hide_title=true"

Parameters:

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

    Additional parameters to include in the oEmbed URL.

Returns:

  • (String)
  • (nil)

    if the object is a collection.



43
44
45
46
47
48
# File 'lib/cocina_display/concerns/access.rb', line 43

def oembed_url(params: {})
  return if collection?

  params[:url] ||= purl_url
  "#{purl_base_url}/embed.json?#{params.to_query}"
end

#purl_base_urlString

Note:

Objects accessed via UAT will still have a production PURL base URL.

The URL to the PURL environment this object is from.

Examples:

record.purl_base_url #=> "https://purl.stanford.edu"

Returns:

  • (String)


18
19
20
# File 'lib/cocina_display/concerns/access.rb', line 18

def purl_base_url
  URI(purl_url).origin
end

#purl_urlString

The PURL URL for this object.

Examples:

record.purl_url #=> "https://purl.stanford.edu/bx658jh7339"

Returns:

  • (String)


9
10
11
# File 'lib/cocina_display/concerns/access.rb', line 9

def purl_url
  cocina_doc.dig("description", "purl") || "https://purl.stanford.edu/#{bare_druid}"
end

#stacks_base_urlString

The URL to the stacks environment this object is shelved in. Corresponds to the PURL environment.

Examples:

record.stacks_base_url #=> "https://stacks.stanford.edu"

Returns:

  • (String)

See Also:



28
29
30
31
32
33
34
# File 'lib/cocina_display/concerns/access.rb', line 28

def stacks_base_url
  if purl_base_url == "https://sul-purl-stage.stanford.edu"
    "https://sul-stacks-stage.stanford.edu"
  else
    "https://stacks.stanford.edu"
  end
end