Class: Exlibris::Primo::EShelf

Inherits:
Object
  • Object
show all
Defined in:
lib/exlibris/primo/eshelf.rb

Overview

Overview

Exlibris::Primo::EShelf provides access to the Primo Eshelf for a given user. An instance of Exlibris::Primo::EShelf can be created by passing in a hash with setup parameters, a user_id and an institution. Valid setup parameters include:

:base_url, :resolver_base_url, :vid, :config

Examples of usage

Exlibris::Primo::EShelf.new({ :base_url => "http://primo.institution.edu", :vid => "VID", :resolver_base_url => "http://resolver.institution.edu"} , "USER_ID", "PRIMO").count
Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute).basket_id

Constant Summary collapse

SEAR_NS =

Namespaces

{'sear' => 'http://www.exlibrisgroup.com/xsd/jaguar/search'}
PRIM_NS =
{'prim' => 'http://www.exlibris.com/primo/xsd/primoeshelffolder'}
PRIM_BIB_NS =
{'bib' => 'http://www.exlibrisgroup.com/xsd/primo/primo_nm_bib'}

Instance Method Summary collapse

Constructor Details

#initialize(setup, user_id, institution) ⇒ EShelf

Returns a new instance of EShelf.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/exlibris/primo/eshelf.rb', line 20

def initialize(setup, user_id, institution)
  @base_url = setup[:base_url]
  raise_required_setup_parameter_error :base_url if @base_url.nil?
  @resolver_base_url = setup[:resolver_base_url]
  @vid = setup.fetch(:vid, "DEFAULT")
  raise_required_setup_parameter_error :vid if @vid.nil?
  @config = setup.fetch(:config, {})
  raise_required_setup_parameter_error :config if @config.nil?
  @user_id = user_id
  raise_required_setup_parameter_error :user_id if @user_id.nil?
  @institution = institution
  raise_required_setup_parameter_error :institution if @institution.nil?
  @records = []
end

Instance Method Details

#add_records(doc_ids, folder_id) ⇒ Object

Call Web Service to add records to remote Eshelf



66
67
68
# File 'lib/exlibris/primo/eshelf.rb', line 66

def add_records(doc_ids, folder_id)
  Exlibris::Primo::WebService::AddToEShelf.new(doc_ids, folder_id, @user_id, @institution, @base_url) unless doc_ids.empty?
end

#basket_idObject

Fetch default basket id from eshelf structure web service call



59
60
61
62
63
# File 'lib/exlibris/primo/eshelf.rb', line 59

def basket_id
  @basket_id ||= eshelfStructure.at(
    "//prim:eshelf_folders//prim:eshelf_folder[./prim:folder_name='Basket']", PRIM_NS).
    get_attribute("folder_id") unless eshelfStructure.at("//prim:eshelf_folders//prim:eshelf_folder[./prim:folder_name='Basket']", PRIM_NS).nil?
end

#countObject

Fetch the number of records in user’s Eshelf



46
47
48
# File 'lib/exlibris/primo/eshelf.rb', line 46

def count
  @count ||= Integer(eshelf.at("//sear:DOCSET", SEAR_NS)["TOTALHITS"])
end

#eshelfObject

Call Web Service to get Eshelf contents and return



36
37
38
# File 'lib/exlibris/primo/eshelf.rb', line 36

def eshelf
  @eshelf ||= Exlibris::Primo::WebService::GetEShelf.new(@user_id, @institution, @base_url).response
end

#eshelfStructureObject

Call Web Service to get Eshelf structure and return



41
42
43
# File 'lib/exlibris/primo/eshelf.rb', line 41

def eshelfStructure
  @eshelfStructure ||= Exlibris::Primo::WebService::GetEShelfStructure.new(@user_id, @institution, @base_url).response
end

#recordsObject

Fetch all records from user’s Eshelf as an array of Primo Record objects



51
52
53
54
55
56
# File 'lib/exlibris/primo/eshelf.rb', line 51

def records    
  eshelf.search("//sear:DOC", SEAR_NS).each { |doc|
    @records.push(Record.new({ :base_url => @base_url, :resolver_base_url => @resolver_base_url, :vid => @vid, :record => doc.at("//bib:record", PRIM_BIB_NS), :institution => @institution }))
  } if @records.empty?
  return @records
end

#remove_records(doc_ids, folder_id) ⇒ Object

Call Web Service to remove records from remote EShelf



71
72
73
# File 'lib/exlibris/primo/eshelf.rb', line 71

def remove_records(doc_ids, folder_id)
  Exlibris::Primo::WebService::RemoveFromEShelf.new(doc_ids, folder_id, @user_id, @institution, @base_url) unless doc_ids.empty?
end