Class: BerkeleyLibrary::AV::Config

Inherits:
Object
  • Object
show all
Extended by:
Util
Defined in:
lib/berkeley_library/av/config.rb

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

REQUIRED_SETTINGS =
%i[
  avplayer_base_uri
  alma_sru_host
  alma_primo_host
  alma_institution_code
  alma_permalink_key
  tind_base_uri
  wowza_base_uri
].freeze

Class Method Summary collapse

Class Method Details

.alma_institution_codeObject

Alma institution code, e.g. UC Berkeley = 01UCS_BER



27
28
29
# File 'lib/berkeley_library/av/config.rb', line 27

def alma_institution_code
  @alma_institution_code ||= value_from_rails_config(:alma_institution_code)
end

.alma_institution_code=(inst_code) ⇒ String

Sets the Alma SRU institution code

Parameters:

  • inst_code (String)

    the institution code

Returns:

  • (String)

    the institution code

Raises:

  • ArgumentError if the institution code is nil or empty

  • URI::InvalidURIError if the resulting SRU URI cannot be parsed



109
110
111
112
113
114
# File 'lib/berkeley_library/av/config.rb', line 109

def alma_institution_code=(inst_code)
  raise ArgumentError, "Invalid institution code: #{inst_code.inspect}" if inst_code.nil? || inst_code.empty?

  sru_uri = sru_base_uri_for('example.org', inst_code) # Catch bad URIs early
  @alma_institution_code = sru_uri.path.split('/').last
end


50
51
52
53
54
# File 'lib/berkeley_library/av/config.rb', line 50

def alma_permalink_base_uri
  ensure_configured(:alma_primo_host, :alma_institution_code, :alma_permalink_key)

  primo_permalink_base_uri_for(alma_primo_host, alma_institution_code, alma_permalink_key)
end

View state key to use when generating Alma permalinks, e.g. ‘iqob43`; see knowledge.exlibrisgroup.com/Primo/Knowledge_Articles/What_is_the_key_in_short_permalinks%3F

Note that despite the name ‘key’, this is not a secret.



40
41
42
# File 'lib/berkeley_library/av/config.rb', line 40

def alma_permalink_key
  @alma_permalink_key ||= value_from_rails_config(:alma_permalink_key)
end

Sets the Alma permalink key

Parameters:

  • permalink_key (String)

    the permalink key

Returns:

  • (String)

    the permalink key

Raises:

  • ArgumentError if the permalink key is nil or empty

  • URI::InvalidURIError if the resulting Primo permalink URI cannot be parsed



122
123
124
125
126
127
# File 'lib/berkeley_library/av/config.rb', line 122

def alma_permalink_key=(permalink_key)
  raise ArgumentError, "Invalid permalink key: #{permalink_key.inspect}" if permalink_key.nil? || permalink_key.empty?

  sru_uri = primo_permalink_base_uri_for('example.org', 'XXX', permalink_key) # Catch bad URIs early
  @alma_permalink_key = sru_uri.path.split('/').last
end

.alma_primo_hostObject

Alma Primo host, e.g. UC Berkeley = search.library.berkeley.edu



32
33
34
# File 'lib/berkeley_library/av/config.rb', line 32

def alma_primo_host
  @alma_primo_host ||= value_from_rails_config(:alma_primo_host)
end

.alma_primo_host=(hostname) ⇒ String

Sets the Alma Primo hostname

Parameters:

  • hostname (String)

    the hostname

Returns:

  • (String)

    the hostname

Raises:

  • ArgumentError if the hostname is nil or empty

  • URI::InvalidURIError if the resulting Primo permalink URI cannot be parsed



96
97
98
99
100
101
# File 'lib/berkeley_library/av/config.rb', line 96

def alma_primo_host=(hostname)
  raise ArgumentError, "Invalid hostname: #{hostname.inspect}" if hostname.nil? || hostname.empty?

  primo_uri = primo_permalink_base_uri_for(hostname, 'XXX', 'abc123') # Catch bad URIs early
  @alma_primo_host = primo_uri.host
end

.alma_sru_base_uriObject



44
45
46
47
48
# File 'lib/berkeley_library/av/config.rb', line 44

def alma_sru_base_uri
  ensure_configured(:alma_sru_host, :alma_institution_code)

  sru_base_uri_for(alma_sru_host, alma_institution_code)
end

.alma_sru_hostObject

Alma SRU hostname, e.g. UC Berkeley = berkeley.alma.exlibrisgroup.com



22
23
24
# File 'lib/berkeley_library/av/config.rb', line 22

def alma_sru_host
  @alma_sru_host ||= value_from_rails_config(:alma_sru_host)
end

.alma_sru_host=(hostname) ⇒ String

Sets the Alma SRU hostname

Parameters:

  • hostname (String)

    the hostname

Returns:

  • (String)

    the hostname

Raises:

  • ArgumentError if the hostname is nil or empty

  • URI::InvalidURIError if the resulting SRU URI cannot be parsed



83
84
85
86
87
88
# File 'lib/berkeley_library/av/config.rb', line 83

def alma_sru_host=(hostname)
  raise ArgumentError, "Invalid hostname: #{hostname.inspect}" if hostname.nil? || hostname.empty?

  sru_uri = sru_base_uri_for(hostname, '') # Catch bad URIs early
  @alma_sru_host = sru_uri.host
end

.avplayer_base_uriObject



56
57
58
# File 'lib/berkeley_library/av/config.rb', line 56

def avplayer_base_uri
  @avplayer_base_uri ||= uri_from_rails_config(:avplayer_base_uri)
end

.avplayer_base_uri=(uri) ⇒ URI

Sets the AV Player base URI

Parameters:

  • uri (URI, String)

    the base URI

Returns:

  • (URI)

    the URI

Raises:

  • URI::InvalidURIError if the URI cannot be parsed, or is not HTTP/HTTPS



73
74
75
# File 'lib/berkeley_library/av/config.rb', line 73

def avplayer_base_uri=(uri)
  @avplayer_base_uri = clean_uri(uri)
end

.ensure_configured(*settings) ⇒ Object

Raises:

  • (ArgumentError)


158
159
160
161
162
# File 'lib/berkeley_library/av/config.rb', line 158

def ensure_configured(*settings)
  return if (missing_settings = missing(*settings)).empty?

  raise ArgumentError, "Missing AV configuration settings: #{missing_settings.join(', ')}"
end

.log_settings!(to_logger: BerkeleyLibrary::Logging.logger) ⇒ Object

Logs settings to the specified logger, or to the default logger.

Parameters:

  • to_logger (defaults to: BerkeleyLibrary::Logging.logger)

    The logger to log to, if not the default.



166
167
168
169
# File 'lib/berkeley_library/av/config.rb', line 166

def log_settings!(to_logger: BerkeleyLibrary::Logging.logger)
  settings = REQUIRED_SETTINGS.to_h { |attr| [attr, loggable_value(send(attr))] }
  to_logger.info("#{name} settings:", settings:)
end

.missing(*settings) ⇒ Array<Symbol>

Returns the list of missing required settings.

Returns:

  • (Array<Symbol>)

    the missing settings.



149
150
151
152
153
154
155
156
# File 'lib/berkeley_library/av/config.rb', line 149

def missing(*settings)
  settings = REQUIRED_SETTINGS if settings.empty?
  [].tap do |unset|
    settings.each do |setting|
      unset << setting unless set?(setting)
    end
  end
end

.tind_base_uriObject



60
61
62
# File 'lib/berkeley_library/av/config.rb', line 60

def tind_base_uri
  @tind_base_uri ||= uri_from_rails_config(:tind_base_uri)
end

.tind_base_uri=(uri) ⇒ URI

Sets the TIND base URI

Parameters:

  • uri (URI, String)

    the base URI

Returns:

  • (URI)

    the URI

Raises:

  • URI::InvalidURIError if the URI cannot be parsed, or is not HTTP/HTTPS



134
135
136
# File 'lib/berkeley_library/av/config.rb', line 134

def tind_base_uri=(uri)
  @tind_base_uri = clean_uri(uri)
end

.wowza_base_uriObject



64
65
66
# File 'lib/berkeley_library/av/config.rb', line 64

def wowza_base_uri
  @wowza_base_uri ||= uri_from_rails_config(:wowza_base_uri)
end

.wowza_base_uri=(uri) ⇒ URI

Sets the Wowza base URI

Parameters:

  • uri (URI, String)

    the base URI

Returns:

  • (URI)

    the URI

Raises:

  • URI::InvalidURIError if the URI cannot be parsed, or is not HTTP/HTTPS



143
144
145
# File 'lib/berkeley_library/av/config.rb', line 143

def wowza_base_uri=(uri)
  @wowza_base_uri = clean_uri(uri)
end