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?

Note:

Collections and related resources do not have a download URL.

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, nil)


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

def download_url
  "#{stacks_base_url}/object/#{bare_druid}" if is_a?(CocinaDisplay::CocinaRecord) && bare_druid.present? && !collection?
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, nil)


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)


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

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, nil)


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

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

#searchworks_urlString?

Note:

This does not guarantee that the object is actually in Searchworks.

The Searchworks URL for this object. Uses the catkey (FOLIO HRID) if present, otherwise uses the druid.

Examples:

record.searchworks_url #=> "https://searchworks.stanford.edu/view/bx658jh7339"

Returns:

  • (String, nil)


53
54
55
56
# File 'lib/cocina_display/concerns/url_helpers.rb', line 53

def searchworks_url
  return "#{searchworks_base_url}/view/#{folio_hrid}" if folio_hrid.present?
  "#{searchworks_base_url}/view/#{bare_druid}" if bare_druid.present?
end