Class: BerkeleyLibrary::Location::WorldCat::LibrariesRequest

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/berkeley_library/location/world_cat/libraries_request.rb

Overview

Constant Summary collapse

XPATH_INST_ID_VALS =
'/holdings/holding/institutionIdentifier/value'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(oclc_number, symbols: Symbols::ALL) ⇒ LibrariesRequest

Returns a new instance of LibrariesRequest.



17
18
19
20
# File 'lib/berkeley_library/location/world_cat/libraries_request.rb', line 17

def initialize(oclc_number, symbols: Symbols::ALL)
  @oclc_number = OCLCNumber.ensure_oclc_number!(oclc_number)
  @symbols = Symbols.ensure_valid!(symbols)
end

Instance Attribute Details

#oclc_numberObject (readonly)

Returns the value of attribute oclc_number.



15
16
17
# File 'lib/berkeley_library/location/world_cat/libraries_request.rb', line 15

def oclc_number
  @oclc_number
end

#symbolsObject (readonly)

Returns the value of attribute symbols.



15
16
17
# File 'lib/berkeley_library/location/world_cat/libraries_request.rb', line 15

def symbols
  @symbols
end

Instance Method Details

#executeObject



37
38
39
40
41
# File 'lib/berkeley_library/location/world_cat/libraries_request.rb', line 37

def execute
  response_body = URIs.get(uri, params:, log: false)
  inst_symbols = inst_symbols_from(response_body)
  inst_symbols.select { |sym| symbols.include?(sym) } # just in case
end

#paramsObject

TODO: Check that this works w/more than 10 results

See https://developer.api.oclc.org/wcv1#/Holdings


28
29
30
31
32
33
34
35
# File 'lib/berkeley_library/location/world_cat/libraries_request.rb', line 28

def params
  @params ||= {
    'oclcsymbol' => symbols.join(','),
    'servicelevel' => 'full',
    'frbrGrouping' => 'off',
    'wskey' => Config.api_key
  }
end

#uriObject



22
23
24
# File 'lib/berkeley_library/location/world_cat/libraries_request.rb', line 22

def uri
  @uri ||= URIs.append(libraries_base_uri, URIs.path_escape(oclc_number))
end