Module: CocinaDisplay::Concerns::UrlHelpers

Included in:
CocinaDisplay::CocinaRecord, RelatedResource
Defined in:
lib/cocina_display/concerns/url_helpers.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)


32
33
34
# File 'lib/cocina_display/concerns/url_helpers.rb', line 32

def download_url
  "#{stacks_base_url}/object/#{bare_druid}" if bare_druid.present?
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)


42
43
44
45
# File 'lib/cocina_display/concerns/url_helpers.rb', line 42

def iiif_manifest_url(version: 3)
  iiif_path = (version == 3) ? "iiif3" : "iiif"
  "#{purl_url}/#{iiif_path}/manifest" if purl_url.present?
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.



20
21
22
23
24
25
# File 'lib/cocina_display/concerns/url_helpers.rb', line 20

def oembed_url(params: {})
  return if (!is_a?(CocinaDisplay::RelatedResource) && collection?) || purl_url.blank?

  params[:url] ||= purl_url
  "#{purl_base_url}/embed.json?#{params.to_query}"
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/url_helpers.rb', line 9

def purl_url
  cocina_doc.dig("description", "purl")
end