lib/exlibris/primo/eshelf.rb in exlibris-primo-0.1.5 vs lib/exlibris/primo/eshelf.rb in exlibris-primo-1.0.0
- old
+ new
@@ -1,81 +1,134 @@
module Exlibris
module Primo
- # == 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
+ # Manipulate a user's Primo eshelf using Exlibris::Primo::Eshelf
+ #
+ # eshelf = Eshelf.new.base_url!("http://primo.library.edu").institution!("PRIMO").user_id!("USER_ID")
+ # eshelf.records #=> Array for Primo records
+ #
class EShelf
-
- #Namespaces
- SEAR_NS = {'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'}
-
- 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 = []
+ include Config::Attributes
+ include ChainGang::Base
+ include ChainGang::User
+ include RequestAttributes
+ include WriteAttributes
+
+ attr_reader :user_id
+
+ def initialize *args
+ super
end
-
- # Call Web Service to get Eshelf contents and return
+
+ #
+ # Call web service to get Eshelf contents and return
+ #
def eshelf
- @eshelf ||= Exlibris::Primo::WebService::GetEShelf.new(@user_id, @institution, @base_url).response
+ @eshelf ||=
+ Exlibris::Primo::WebService::Request::GetEshelf.new(user_request_attributes).call
end
-
- # Call Web Service to get Eshelf structure and return
- def eshelfStructure
- @eshelfStructure ||= Exlibris::Primo::WebService::GetEShelfStructure.new(@user_id, @institution, @base_url).response
+
+ #
+ # Call web service to get Eshelf structure and return
+ #
+ def eshelf_structure
+ @eshelf_structure ||=
+ Exlibris::Primo::WebService::Request::GetEshelfStructure.new(user_request_attributes).call
end
-
- # Fetch the number of records in user's Eshelf
- def count
- @count ||= Integer(eshelf.at("//sear:DOCSET", SEAR_NS)["TOTALHITS"])
+
+ #
+ # Get the number of records in user's eshelf
+ #
+ def size
+ @size ||= eshelf.size
end
-
- # Fetch all records from user's Eshelf as an array of Primo Record objects
- 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
+
+ #
+ # Get all the records from user's eshelf as an array of Primo Record objects
+ #
+ def records
+ @records ||= eshelf.records
end
-
- # Fetch default basket id from eshelf structure web service call
+
+ #
+ # Get the default basket id from eshelf structure web service call
+ #
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?
+ @basket_id ||= eshelf_structure.basket_id
end
-
- # Call Web Service to add records to remote Eshelf
- 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?
+
+ #
+ # Get the folder id from eshelf structure web service call
+ # for the given folder name.
+ #
+ def folder_id(folder_name)
+ eshelf_structure.folder_id(folder_name)
end
- # Call Web Service to remove records from remote EShelf
- 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?
+ #
+ # Call web service to add records to eshelf
+ #
+ def add_records(record_ids, folder_id)
+ record_ids.each do |record_id|
+ add_record record_id, folder_id
+ end
+ reset_eshelf
end
-
- private
- def raise_required_setup_parameter_error(parameter)
- raise ArgumentError.new("Error in #{self.class}. Missing required setup parameter: #{parameter}.")
+
+ #
+ # Call web service to add record to eshelf
+ #
+ def add_record(record_id, folder_id)
+ Exlibris::Primo::WebService::Request::AddToEshelf.new(
+ user_request_attributes.merge :folder_id => folder_id, :doc_id => record_id).call
+ reset_eshelf
end
+
+ #
+ # Call web service to remove records from the eshelf
+ #
+ def remove_records(record_ids, folder_id)
+ record_ids.each do |record_id|
+ remove_record record_id, folder_id
+ end
+ reset_eshelf
+ end
+
+ #
+ # Call web service to remove a record from eshelf
+ #
+ def remove_record(record_id, folder_id)
+ Exlibris::Primo::WebService::Request::RemoveFromEshelf.new(
+ user_request_attributes.merge :folder_id => folder_id, :doc_id => record_id).call
+ reset_eshelf
+ end
+
+ #
+ # Call web service to add folder to eshelf
+ #
+ def add_folder(folder_name, parent_id)
+ Exlibris::Primo::WebService::Request::AddFolderToEshelf.new(
+ user_request_attributes.merge :folder_name => folder_name, :parent_folder => parent_id).call
+ reset_eshelf
+ end
+
+ #
+ # Call web service to remove folder from eshelf
+ #
+ def remove_folder(folder_id)
+ Exlibris::Primo::WebService::Request::RemoveFolderFromEshelf.new(
+ user_request_attributes.merge :folder_id => folder_id).call
+ reset_eshelf
+ end
+
+ # Reset eshelf instance variables
+ def reset_eshelf
+ @eshelf = nil
+ @eshelf_structure = nil
+ @size = nil
+ @records = nil
+ @basket_id = nil
+ end
+ private :reset_eshelf
end
end
end
\ No newline at end of file