exlibris-primo 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,7 @@ Exlibris::Primo offers a set of libraries for interacting with the ExLibris Prim
6
6
  The Exlibris::Primo::Searcher class performs a search against Primo for given parameters
7
7
  and exposes the set of holdings (availibrary elements), rsrcs, tocs, and related links (addlink elements).
8
8
 
9
- == Example of Exlibris::Primo::Searcher in action
9
+ === Example of Exlibris::Primo::Searcher in action
10
10
  setup = {
11
11
  :base_url => "http://primo.institution.edu", :vid => "VID", :institution => "INSTITUTION",
12
12
  :config => {
@@ -29,3 +29,37 @@ and exposes the set of holdings (availibrary elements), rsrcs, tocs, and related
29
29
  rsrcs = searcher.rsrcs
30
30
  tocs = searcher.tocs
31
31
  related_links = searcher.related_links
32
+
33
+ == Exlibris::Primo::Record
34
+ The Exlibris::Primo::Record class creates an object representation of a Primo record for given parameters
35
+ and exposes the record's primary attributes (format, title, author, url, openurl) and full record Xml (raw_xml)
36
+ as instance variables.
37
+
38
+ === Example of Exlibris::Primo::Record in action
39
+ setup = {
40
+ :base_url => "http://primo.institution.edu",
41
+ :resolver_base_url => "http://sfx.institution.edu",
42
+ :vid => "VID",
43
+ :institution => "DEFAULT",
44
+ :record_id => "PrimoRecordId"
45
+ }
46
+ record = Exlibris::Primo::Record.new(setup)
47
+ raw_xml = record.instance_variable_get(:@raw_xml)
48
+ record_hash = record.to_h
49
+ openurl = record_hash["openurl"]
50
+
51
+ == Exlibris::Primo::EShelf
52
+ The Exlibris::Primo::EShelf class provides methods for reading a given user's Primo eshelf and eshelf structure as well as adding and removing records.
53
+
54
+ === Example of Exlibris::Primo::EShelf in action
55
+ setup = {
56
+ :base_url => "http://primo.institution.edu",
57
+ :vid => "VID",
58
+ :resolver_base_url => "http://sfx.institution.edu"
59
+ }
60
+ eshelf = Exlibris::Primo::EShelf.new(setup, "USER_ID", "PRIMO")
61
+ records = eshelf.records
62
+ p records.first.class
63
+ record_count = eshelf.count
64
+ basket_id = eshelf.basket_id
65
+ eshelf.add_records(["PrimoRecordId","PrimoRecordId2"], basket_id)
@@ -1,5 +1,7 @@
1
- PATH = File.dirname(__FILE__) + "/exlibris/primo/"
1
+ PRIMO_PATH = File.dirname(__FILE__) + "/exlibris/primo/"
2
2
  [
3
+ 'record',
4
+ 'eshelf',
3
5
  'web_service',
4
6
  'holding',
5
7
  'related_link',
@@ -8,5 +10,5 @@ PATH = File.dirname(__FILE__) + "/exlibris/primo/"
8
10
  'searcher',
9
11
  'source/aleph'
10
12
  ].each do |library|
11
- require PATH + library
13
+ require PRIMO_PATH + library
12
14
  end
@@ -0,0 +1,80 @@
1
+ module Exlibris
2
+ module Primo
3
+ # == Overview
4
+ # Exlibris::Primo::EShelf provides access to the Primo Eshelf for a given user.
5
+ # An instance of Exlibris::Primo::EShelf can be created by passing
6
+ # in a hash with setup parameters, a user_id and an institution.
7
+ # Valid setup parameters include:
8
+ # :base_url, :resolver_base_url, :vid, :config
9
+ #
10
+ # == Examples of usage
11
+ # Exlibris::Primo::EShelf.new({ :base_url => "http://primo.institution.edu", :vid => "VID", :resolver_base_url => "http://sfx.institution.edu"} , "USER_ID", "PRIMO").count
12
+ # Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute).basket_id
13
+ class EShelf
14
+
15
+ #Namespaces
16
+ SEAR_NS = {'sear' => 'http://www.exlibrisgroup.com/xsd/jaguar/search'}
17
+ PRIM_NS = {'prim' => 'http://www.exlibris.com/primo/xsd/primoeshelffolder'}
18
+
19
+ def initialize(setup, user_id, institution)
20
+ @base_url = setup[:base_url]
21
+ raise_required_setup_parameter_error :base_url if @base_url.nil?
22
+ @resolver_base_url = setup[:resolver_base_url]
23
+ @vid = setup.fetch(:vid, "DEFAULT")
24
+ raise_required_setup_parameter_error :vid if @vid.nil?
25
+ @config = setup.fetch(:config, {})
26
+ raise_required_setup_parameter_error :config if @config.nil?
27
+ @user_id = user_id
28
+ raise_required_setup_parameter_error :user_id if @user_id.nil?
29
+ @institution = institution
30
+ raise_required_setup_parameter_error :institution if @institution.nil?
31
+ @records = []
32
+ end
33
+
34
+ # Call Web Service to get Eshelf contents and return
35
+ def eshelf
36
+ @eshelf ||= Exlibris::Primo::WebService::GetEShelf.new(@user_id, @institution, @base_url).response
37
+ end
38
+
39
+ # Call Web Service to get Eshelf structure and return
40
+ def eshelfStructure
41
+ @eshelfStructure ||= Exlibris::Primo::WebService::GetEShelfStructure.new(@user_id, @institution, @base_url).response
42
+ end
43
+
44
+ # Fetch the number of records in user's Eshelf
45
+ def count
46
+ @count ||= Integer(eshelf.at("//sear:DOCSET", SEAR_NS)["TOTALHITS"])
47
+ end
48
+
49
+ # Fetch all records from user's Eshelf as an array of Primo Record objects
50
+ def records
51
+ eshelf.search("//sear:DOC", SEAR_NS).each { |doc|
52
+ @records.push(Record.new({ :base_url => @base_url, :resolver_base_url => @resolver_base_url, :vid => @vid, :record => doc.at("//xmlns:record", doc.namespaces), :institution => @institution }))
53
+ } if @records.empty?
54
+ return @records
55
+ end
56
+
57
+ # Fetch default basket id from eshelf structure web service call
58
+ def basket_id
59
+ @basket_id ||= eshelfStructure.at(
60
+ "//prim:eshelf_folders//prim:eshelf_folder[./prim:folder_name='Basket']", PRIM_NS).
61
+ get_attribute("folder_id") unless eshelfStructure.at("//prim:eshelf_folders//prim:eshelf_folder[./prim:folder_name='Basket']", PRIM_NS).nil?
62
+ end
63
+
64
+ # Call Web Service to add records to remote Eshelf
65
+ def add_records(doc_ids, folder_id)
66
+ Exlibris::Primo::WebService::AddToEShelf.new(doc_ids, folder_id, @user_id, @institution, @base_url) unless doc_ids.empty?
67
+ end
68
+
69
+ # Call Web Service to remove records from remote EShelf
70
+ def remove_records(doc_ids, folder_id)
71
+ Exlibris::Primo::WebService::RemoveFromEShelf.new(doc_ids, folder_id, @user_id, @institution, @base_url) unless doc_ids.empty?
72
+ end
73
+
74
+ private
75
+ def raise_required_setup_parameter_error(parameter)
76
+ raise ArgumentError.new("Error in #{self.class}. Missing required setup parameter: #{parameter}.")
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,112 @@
1
+ module Exlibris
2
+ module Primo
3
+ # == Overview
4
+ # Exlibris::Primo::Record is an abstract representation of a Primo record.
5
+ # An instance of Exlibris::Primo::Record can be created by passing
6
+ # in a hash with setup parameters.
7
+ # Valid parameters include:
8
+ # :base_url, :resolver_base_url, :vid, :institution, :record_id, :record
9
+ # A URL to the native record (dlDisplay.do) and an OpenUrl are generated by default.
10
+ # If no resolver_base_url is provided, an OpenUrl querystring will be returned.
11
+ # A raw_xml attribute is generated either by the record XML passed in or by fetching it from the record_id.
12
+ # By default the raw_xml is not included in the hash representation, but can be overridden to.
13
+ #
14
+ # == Tips on Extending
15
+ # When extending the class, a few basics guidelines should be observed.
16
+ # 1. A Exlibris::Primo::Record is initialized from a Hash of parameters.
17
+ # These params are used to create instance variables of the record attributes.
18
+ #
19
+ # 2. The following methods are available for overriding:
20
+ # to_h - if a sub class creates more instance variables, these should be added to the hash
21
+ # raw - cleans up characters and spaces in raw record and wraps in <record /> tag, implementations may differ
22
+ #
23
+ # == Examples of usage
24
+ # Record.new({ :base_url => @base_url, :vid => @vid, :record => doc.at("//record") })
25
+ class Record
26
+
27
+ SEAR_NS = {'sear' => 'http://www.exlibrisgroup.com/xsd/jaguar/search'}
28
+ attr_reader :record_id, :type, :title, :url, :openurl, :creator, :raw_xml
29
+
30
+ def initialize(parameters={})
31
+ # Get base url of Primo application, required
32
+ base_url = parameters[:base_url]
33
+ raise_required_setup_parameter_error :base_url if base_url.nil?
34
+ # Get base url of link resolver, if blank openurl generates just querystring
35
+ resolver_base_url = parameters[:resolver_base_url]
36
+ # Get vid from parameters, required
37
+ vid = parameters.fetch(:vid, "DEFAULT")
38
+ raise_required_setup_parameter_error :vid if vid.nil?
39
+ # Get institution from parameters, required
40
+ institution = parameters.fetch(:institution, "PRIMO")
41
+ raise_required_setup_parameter_error :institution if institution.nil?
42
+ # Get record: either fetch record from Web Service based on DocId or use passed in record xml, required
43
+ record = (parameters[:record].nil?) ?
44
+ (parameters[:record_id].nil?) ?
45
+ nil : record_from_id(parameters.delete(:record_id), base_url, {:institution => institution, :vid => vid}) : parameters.delete(:record)
46
+ raise_required_setup_parameter_error "record or record_id" if record.nil?
47
+ # Set instance variables for record
48
+ @record_id = record.at("control/recordid",record.namespaces).inner_text unless record.at("control/recordid",record.namespaces).nil?
49
+ @type = record.at("display/type",record.namespaces).inner_text unless record.at("display/type",record.namespaces).nil?
50
+ @title = record.at("display/title",record.namespaces).inner_text unless record.at("display/title",record.namespaces).nil?
51
+ @url = construct_url(base_url, @record_id, institution, vid)
52
+ @openurl = construct_openurl(resolver_base_url, record, @record_id)
53
+ @creator = record.at("display/creator",record.namespaces).inner_text unless record.at("display/creator",record.namespaces).nil?
54
+ @raw_xml = raw(record)
55
+ end
56
+
57
+ # Return a hash representation of the primary record attributes
58
+ def to_h
59
+ return {
60
+ "format" => @type.capitalize,
61
+ "title" => @title,
62
+ "author" => @creator,
63
+ "url" => @url,
64
+ "openurl" => @openurl
65
+ }
66
+ end
67
+
68
+ # Method for cleaning up raw xml from record
69
+ def raw(record)
70
+ raw = "<record>"
71
+ # Hack to strip out spacing in record
72
+ record.children.each{|child| raw << child.to_xml.gsub(/\n\s*/, "").gsub(/\s$/, "")}
73
+ raw << "</record>"
74
+ return raw
75
+ end
76
+
77
+ private
78
+ # Method for consturcting openurl from record
79
+ def construct_openurl(resolver_base_url, record, record_id)
80
+ raise_required_setup_parameter_error :record if record.nil?
81
+ raise_required_setup_parameter_error :record_id if record_id.nil?
82
+ openurl = (resolver_base_url.nil?) ? "?" : "#{resolver_base_url}?"
83
+ record.search("addata/*",record.namespaces).each do |addata|
84
+ openurl << "rft.#{addata.name}=#{addata.inner_text}&" unless (addata.inner_text.nil? or addata.inner_text.strip.empty?)
85
+ end
86
+ openurl << "rft.primo=#{record_id}"
87
+ return openurl
88
+ end
89
+
90
+ # Method for constructing deep link url from record
91
+ def construct_url(base_url, record_id, institution, vid)
92
+ raise_required_setup_parameter_error :base_url if base_url.nil?
93
+ raise_required_setup_parameter_error :record_id if record_id.nil?
94
+ raise_required_setup_parameter_error :institution if institution.nil?
95
+ raise_required_setup_parameter_error :vid if vid.nil?
96
+ url = "#{base_url}/primo_library/libweb/action/dlDisplay.do?dym=false&onCampus=false&docId=#{record_id}&institution=#{institution}&vid=#{vid}"
97
+ return url
98
+ end
99
+
100
+ # Fetch record from Primo Web Service
101
+ def record_from_id(record_id, base_url, options={})
102
+ doc = Exlibris::Primo::WebService::GetRecord.new(record_id, base_url, options).response.at("//sear:DOC", SEAR_NS)
103
+ return doc.at("//xmlns:record",doc.namespaces)
104
+ end
105
+
106
+ # Raise error wrapper
107
+ def raise_required_setup_parameter_error(parameter)
108
+ raise ArgumentError.new("Error in #{self.class}. Missing required setup parameter: #{parameter}.")
109
+ end
110
+ end
111
+ end
112
+ end
@@ -1,5 +1,5 @@
1
1
  module Exlibris
2
2
  module Primo
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -27,10 +27,18 @@ module Exlibris
27
27
  raise "Error making call to Primo web service. Response from web service is #{@response}." if @response.nil?
28
28
  @error = []
29
29
  response.search("ERROR").each do |e|
30
- @error.push(e.attributes["MESSAGE"]) unless e.nil?
30
+ # Primo Web Service calls will return an <ERROR MESSAGE="{MESSAGE}" CODE="{CODE}" />
31
+ # tag even when it succeeds. Key off CODE == 0 which is a successful call.
32
+ #debugger
33
+ @error.push(e.attributes["MESSAGE"]) unless e.nil? or e.attributes["CODE"].value.to_i == 0
31
34
  end
32
35
  raise "Error making call to Primo web service. #{@error.inspect}" unless @error.empty?
33
36
  end
37
+
38
+ private
39
+ def tag!(name, value)
40
+ REXML::Element.new(name).add_text(value)
41
+ end
34
42
  end
35
43
 
36
44
  # Search is the base class for Search web services
@@ -108,10 +116,6 @@ module Exlibris
108
116
  def genre_query_term(genre)
109
117
  return query_term(genre, "any", "exact")
110
118
  end
111
-
112
- def tag!(name, value)
113
- REXML::Element.new(name).add_text(value)
114
- end
115
119
  end
116
120
 
117
121
  # SearchBrief does a brief result search through the Primo APIs
@@ -138,6 +142,62 @@ module Exlibris
138
142
  super("getRecord", "getRecordRequest", "fullViewRequest", primo_search_request, additional_input, base_url, options)
139
143
  end
140
144
  end
145
+
146
+ # EShelf is the base class for EShelf web services
147
+ # It can be extended but is not intended for use by itself
148
+ # Known implementations are GetEShelf, AddToEShelf, RemoveFromEShelf, GetEShelfStructure
149
+ class EShelf < WebServiceBase
150
+ def initialize(method_name, param_name, input_root, user_id, institution, additional_input, base_url, options, service_name = nil)
151
+ input = REXML::Element.new(input_root)
152
+ input.add_namespace("http://www.exlibris.com/primo/xsd/wsRequest")
153
+ input.add_element(tag!("userId", user_id)) if !user_id.nil?
154
+ input.add_element(tag!("institution", institution)) if !institution.nil?
155
+ additional_input.each do |e|
156
+ input.add_element(e)
157
+ end
158
+ service_name = "eshelf" if service_name.nil?
159
+ make_call(base_url, service_name, method_name, param_name, input)
160
+ end
161
+
162
+ private
163
+ def docs(doc_ids=[], folder_id=nil, folder_name=nil)
164
+ additional_input = []
165
+ doc_ids.each { |doc_id| additional_input.push(tag!("docId", doc_id)) }
166
+ additional_input.push(tag!("folderId", folder_id)) unless folder_id.nil?
167
+ additional_input.push(tag!("folderName", folder_name)) unless folder_name.nil?
168
+ return additional_input
169
+ end
170
+ end
171
+
172
+ # Get EShelf based on user_id and institution
173
+ class GetEShelf < EShelf
174
+ def initialize(user_id, institution, base_url, options={})
175
+ super("getEshelf", "getEshelfRequest", "getEshelfRequest", user_id, institution, [], base_url, options)
176
+ raise "Error making call to Primo web service. #{@error.inspect}" unless @error.empty? or @error.attribe
177
+ end
178
+ end
179
+
180
+ # Get EShelf structure based on user_id and institution
181
+ class GetEShelfStructure < EShelf
182
+ def initialize(user_id, institution, base_url, options={})
183
+ super("getEshelfStructure", "getEshelfStructureRequest", "getEshelfStructureRequest", user_id, institution, [tag!("includeBasketItems","false")], base_url, options, "eshelfstructure")
184
+ raise "Error making call to Primo web service. #{@error.inspect}" unless @error.empty? or @error.attribe
185
+ end
186
+ end
187
+
188
+ # Add document to EShelf based on user_id and institution
189
+ class AddToEShelf < EShelf
190
+ def initialize(doc_ids, folder_id, user_id, institution, base_url, options={})
191
+ super("addToEshelf", "addToEshelfRequest", "addToEshelfRequest", user_id, institution, docs(doc_ids, folder_id), base_url, options)
192
+ end
193
+ end
194
+
195
+ # Remove document from EShelf based on user_id and institution
196
+ class RemoveFromEShelf < EShelf
197
+ def initialize(doc_ids, folder_id, user_id, institution, base_url, options={})
198
+ super("removeFromEshelf", "removeFromEshelfRequest", "removeFromEshelfRequest", user_id, institution, docs(doc_ids, folder_id), base_url, options)
199
+ end
200
+ end
141
201
  end
142
202
  end
143
203
  end
@@ -0,0 +1,152 @@
1
+ require 'test_helper'
2
+
3
+ class EShelfTest < ActiveSupport::TestCase
4
+ PNX_NS = {'pnx' => 'http://www.exlibrisgroup.com/xsd/primo/primo_nm_bib'}
5
+ SEARCH_NS = {'search' => 'http://www.exlibrisgroup.com/xsd/jaguar/search'}
6
+ SEAR_NS = {'sear' => 'http://www.exlibrisgroup.com/xsd/jaguar/search'}
7
+ PRIM_NS = {'prim' => 'http://www.exlibris.com/primo/xsd/primoeshelffolder'}
8
+
9
+ def setup
10
+ @primo_definition = YAML.load( %{
11
+ type: PrimoService
12
+ priority: 2 # After SFX, to get SFX metadata enhancement
13
+ status: active
14
+ base_url: http://bobcat.library.nyu.edu
15
+ resolver_base_url: https://getit.library.nyu.edu/resolve
16
+ vid: NYU
17
+ institution: NYU
18
+ holding_search_institution: NYU
19
+ holding_search_text: Search for this title in BobCat.
20
+ suppress_holdings: [ !ruby/regexp '/\$\$LBWEB/', !ruby/regexp '/\$\$LNWEB/', !ruby/regexp '/\$\$LTWEB/', !ruby/regexp '/\$\$LWEB/', !ruby/regexp '/\$\$1Restricted Internet Resources/' ]
21
+ ez_proxy: !ruby/regexp '/https\:\/\/ezproxy\.library\.nyu\.edu\/login\?url=/'
22
+ service_types:
23
+ - primo_source
24
+ - holding_search
25
+ - fulltext
26
+ - table_of_contents
27
+ - referent_enhance
28
+ - cover_image
29
+ })
30
+
31
+ @base_url = @primo_definition["base_url"]
32
+ @vid = @primo_definition["vid"]
33
+ @valid_user_id = "N18158418"
34
+ @invalid_user_id = "INVALID_USER"
35
+ @eshelf_setup = {
36
+ :base_url => @base_url,
37
+ :vid => @vid,
38
+ :resolver_base_url => @primo_definition["resolver_base_url"]
39
+ }
40
+ @valid_institute = "NYU"
41
+ @invalid_institute = "INVALID_INST"
42
+ @valid_doc_ids = ["nyu_aleph000062856"]
43
+ @invalid_doc_ids = ["INVALID_DOC_ID"]
44
+ @valid_basket = "298560007"
45
+ #@valid_folder = "344619707"
46
+ @invalid_basket = "INVALID_BASKET"
47
+ end
48
+
49
+ test "new" do
50
+ eshelf = Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute)
51
+ assert_not_nil(eshelf, "#{eshelf.class} returned nil when instantiated.")
52
+
53
+ assert_equal(@base_url, eshelf.instance_variable_get(:@base_url))
54
+ assert_equal(@vid, eshelf.instance_variable_get(:@vid))
55
+ assert_equal(@valid_user_id, eshelf.instance_variable_get(:@user_id))
56
+ assert_equal(@valid_institute, eshelf.instance_variable_get(:@institution))
57
+
58
+ assert_nothing_raised{Exlibris::Primo::EShelf.new({:base_url => @base_url}, @valid_user_id, @valid_institute)}
59
+ assert_nothing_raised{Exlibris::Primo::EShelf.new({:base_url => @base_url, :vid => @vid}, @valid_user_id, @valid_institute)}
60
+
61
+ assert_raise(ArgumentError){Exlibris::Primo::EShelf.new({}, @valid_user_id, @valid_institute)}
62
+ assert_raise(ArgumentError){Exlibris::Primo::EShelf.new(@eshelf_setup, nil, nil)}
63
+ assert_raise(ArgumentError){Exlibris::Primo::EShelf.new(@eshelf_setup, nil, nil)}
64
+ assert_raise(ArgumentError){Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, nil)}
65
+
66
+ end
67
+
68
+ test "valid_eshelf" do
69
+ eshelf = nil
70
+ assert_nothing_raised{eshelf = Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute).eshelf}
71
+ assert_not_nil(eshelf)
72
+ assert_instance_of(Nokogiri::XML::Document, eshelf)
73
+ end
74
+
75
+ test "valid_eshelf_structure" do
76
+ eshelfStructure = nil
77
+ assert_nothing_raised{eshelfStructure = Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute).eshelfStructure}
78
+ assert_not_nil(eshelfStructure)
79
+ assert(eshelfStructure.is_a? Nokogiri::XML::Document)
80
+ end
81
+
82
+ test "basket_id" do
83
+ assert_equal(@valid_basket, Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute).basket_id)
84
+ end
85
+
86
+ test "invalid_user_eshelf" do
87
+ ws = nil
88
+ assert_nothing_raised(){ws = Exlibris::Primo::EShelf.new(@eshelf_setup, @invalid_user_id, @valid_institute)}
89
+ assert_not_nil(ws)
90
+ eshelf = nil
91
+ assert_nothing_raised(){eshelf = ws.eshelf}
92
+ assert_not_nil(eshelf)
93
+ assert_instance_of(Nokogiri::XML::Document, eshelf)
94
+ assert_equal(0, ws.count)
95
+ end
96
+
97
+ test "invalid_institution_eshelf" do
98
+ ws = nil
99
+ assert_nothing_raised(){ws = Exlibris::Primo::EShelf.new(@eshelf_setup, @invalid_user_id, @valid_institute)}
100
+ assert_not_nil(ws)
101
+ eshelf = nil
102
+ assert_nothing_raised(){eshelf = ws.eshelf}
103
+ assert_not_nil(eshelf)
104
+ assert_instance_of(Nokogiri::XML::Document, eshelf)
105
+ assert_equal(0, ws.count)
106
+ end
107
+
108
+ test "records" do
109
+ records = nil
110
+ assert_nothing_raised(){records = Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute).records}
111
+ assert_not_nil(records)
112
+ assert_instance_of(Array, records)
113
+ assert(!records.empty?, "Eshelf records returned empty")
114
+ end
115
+
116
+ test "cant_add_same_record_twice" do
117
+ eshelf = Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute)
118
+ assert_not_nil(eshelf)
119
+ # Add record
120
+ assert_nothing_raised(){ eshelf.add_records(@valid_doc_ids, @valid_basket) }
121
+ # Add same record again
122
+ assert_raise(RuntimeError){ eshelf.add_records(@valid_doc_ids, @valid_basket) }
123
+ # Remove record
124
+ assert_nothing_raised(){ eshelf.remove_records(@valid_doc_ids, @valid_basket) }
125
+ end
126
+
127
+ test "cant_add_invalid_records" do
128
+ eshelf = Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute)
129
+ assert_not_nil(eshelf)
130
+ # Attempt to add record
131
+ assert_raise(RuntimeError){ eshelf.add_records(@invalid_doc_ids, @valid_basket) }
132
+ # Attempt to remove record which was never added
133
+ assert_raise(RuntimeError){ eshelf.remove_records(@invalid_doc_ids, @valid_basket) }
134
+ end
135
+
136
+ test "cant_add_to_invalid_basket" do
137
+ eshelf = Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute)
138
+ assert_not_nil(eshelf)
139
+ # Attempt to add record to basket with invalid folder name
140
+ assert_raise(RuntimeError){ eshelf.add_records(@valid_doc_ids, @invalid_basket) }
141
+ end
142
+
143
+ test "can_add_to_empty_folder" do
144
+ eshelf = Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute)
145
+ assert_not_nil(eshelf)
146
+ # Add record to basket with no folder id
147
+ assert_nothing_raised(){ eshelf.add_records(@valid_doc_ids, nil) }
148
+ # Remove record from basket with no folder id
149
+ assert_nothing_raised(){ eshelf.remove_records(@valid_doc_ids, @valid_basket) }
150
+ end
151
+
152
+ end
@@ -0,0 +1,77 @@
1
+ require 'test_helper'
2
+
3
+ class RecordTest < ActiveSupport::TestCase
4
+
5
+ SEAR_NS = {'sear' => 'http://www.exlibrisgroup.com/xsd/jaguar/search'}
6
+
7
+ def setup
8
+ @record_definition = YAML.load( %{
9
+ base_url: http://bobcat.library.nyu.edu
10
+ resolver_base_url: https://getit.library.nyu.edu/resolve
11
+ vid: NYU
12
+ institution: NYU
13
+ record_id: nyu_aleph000062856
14
+ })
15
+
16
+ @base_url = @record_definition["base_url"]
17
+ @resolver_base_url = @record_definition["resolver_base_url"]
18
+ @vid = @record_definition["vid"]
19
+ @institution = @record_definition["institution"]
20
+ @valid_record_id = @record_definition["record_id"]
21
+ @invalid_record_id = "INVALID_RECORD"
22
+ @setup_args = {
23
+ :base_url => @base_url,
24
+ :resolver_base_url => @resolver_base_url,
25
+ :vid => @vid,
26
+ :institution => @institution,
27
+ :record_id => @valid_record_id
28
+ }
29
+ end
30
+
31
+ test "new" do
32
+ record = nil
33
+ assert_nothing_raised(){ record = Exlibris::Primo::Record.new(@setup_args) }
34
+ assert_not_nil(record)
35
+ assert_not_nil(record.instance_variable_get(:@record_id))
36
+ assert_not_nil(record.instance_variable_get(:@type))
37
+ assert_not_nil(record.instance_variable_get(:@title))
38
+ assert_not_nil(record.instance_variable_get(:@url))
39
+ assert_not_nil(record.instance_variable_get(:@openurl))
40
+ assert_not_nil(record.instance_variable_get(:@creator))
41
+ assert_not_nil(record.instance_variable_get(:@raw_xml))
42
+ assert_raise(ArgumentError){ Exlibris::Primo::Record.new(@setup_args.merge({:base_url => nil})) }
43
+ assert_raise(ArgumentError){ Exlibris::Primo::Record.new(@setup_args.merge({:institution => nil})) }
44
+ assert_raise(ArgumentError){ Exlibris::Primo::Record.new(@setup_args.merge({:vid => nil})) }
45
+ assert_raise(ArgumentError){ Exlibris::Primo::Record.new(@setup_args.merge({:record_id => nil})) }
46
+ assert_raise(RuntimeError){ Exlibris::Primo::Record.new(@setup_args.merge({:record_id => @invalid_record_id})) }
47
+ end
48
+
49
+ test "to_hash_function" do
50
+ record = Exlibris::Primo::Record.new(@setup_args)
51
+ assert((record.to_h.is_a? Hash), "#{record.class} was expected to be a Hash, was #{record.to_h.class}")
52
+ end
53
+
54
+ test "sub_class" do
55
+ class SubRecord < Exlibris::Primo::Record
56
+ def initialize(parameters={})
57
+ super(parameters)
58
+ end
59
+ end
60
+ record = nil
61
+ assert_nothing_raised(){ record = SubRecord.new(@setup_args) }
62
+ assert_not_nil(record)
63
+ assert_raise(ArgumentError){ record = SubRecord.new() }
64
+ end
65
+
66
+ test "raw_xml" do
67
+ record = Exlibris::Primo::Record.new(@setup_args)
68
+ raw_xml = record.instance_variable_get(:@raw_xml)
69
+ assert_not_nil(raw_xml)
70
+ assert_instance_of(String, raw_xml)
71
+ doc = nil
72
+ assert_nothing_raised(){ doc = Nokogiri::XML.parse(raw_xml) }
73
+ assert_not_nil(doc)
74
+ assert_not_empty(doc.xpath("//record", doc.namespaces))
75
+ end
76
+
77
+ end
@@ -3,6 +3,8 @@ require 'test_helper'
3
3
  class WebServiceTest < ActiveSupport::TestCase
4
4
  PNX_NS = {'pnx' => 'http://www.exlibrisgroup.com/xsd/primo/primo_nm_bib'}
5
5
  SEARCH_NS = {'search' => 'http://www.exlibrisgroup.com/xsd/jaguar/search'}
6
+ SEAR_NS = {'sear' => 'http://www.exlibrisgroup.com/xsd/jaguar/search'}
7
+ PRIM_NS = {'prim' => 'http://www.exlibris.com/primo/xsd/primoeshelffolder'}
6
8
 
7
9
  def setup
8
10
  @primo_definition = YAML.load( %{
@@ -25,6 +27,9 @@ class WebServiceTest < ActiveSupport::TestCase
25
27
  - cover_image
26
28
  })
27
29
 
30
+ @valid_user_id = "N18158418"
31
+ @invalid_user_id = "INVALID_USER"
32
+ @default_institution = "NYU"
28
33
  @base_url = @primo_definition["base_url"]
29
34
  @bogus_404_url = "http://library.nyu.edu/bogus"
30
35
  @bogus_200_url = "http://library.nyu.edu"
@@ -121,4 +126,21 @@ class WebServiceTest < ActiveSupport::TestCase
121
126
  assert_instance_of( Nokogiri::XML::Document, ws.response, "#{ws.class} response is an unexpected object: #{ws.response.class}")
122
127
  assert_equal([], ws.error, "#{ws.class} encountered errors: #{ws.error}")
123
128
  end
129
+
130
+ test "get_new_eshelf" do
131
+ ws = Exlibris::Primo::WebService::GetEShelf.new(@valid_user_id, @default_institution, @base_url)
132
+ assert_not_nil(ws, "#{ws.class} returned nil when instantiated.")
133
+ assert_instance_of( Nokogiri::XML::Document, ws.response, "#{ws.class} response is an unexpected object: #{ws.response.class}")
134
+ assert_equal([], ws.error, "#{ws.class} encountered errors: #{ws.error}")
135
+ assert_not_nil(ws.response.at("//sear:DOC", SEAR_NS), "#{ws.class} response returned a nil document")
136
+ end
137
+
138
+ test "get_new_eshelf_structure" do
139
+ ws = Exlibris::Primo::WebService::GetEShelfStructure.new(@valid_user_id, @default_institution, @base_url)
140
+ assert_not_nil(ws, "#{ws.class} returned nil when instantiated.")
141
+ assert_instance_of( Nokogiri::XML::Document, ws.response, "#{ws.class} response is an unexpected object: #{ws.response.class}")
142
+ assert_equal([], ws.error, "#{ws.class} encountered errors: #{ws.error}")
143
+ assert_not_nil(ws.response.at("//prim:eshelf_folders", PRIM_NS), "#{ws.class} response returned a nil document")
144
+ end
145
+
124
146
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exlibris-primo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-30 00:00:00.000000000 Z
12
+ date: 2012-04-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &2152708140 !ruby/object:Gem::Requirement
16
+ requirement: &2152674040 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152708140
24
+ version_requirements: *2152674040
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: nokogiri
27
- requirement: &2152707580 !ruby/object:Gem::Requirement
27
+ requirement: &2152673580 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2152707580
35
+ version_requirements: *2152673580
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: soap4r-ruby1.9
38
- requirement: &2152706900 !ruby/object:Gem::Requirement
38
+ requirement: &2152672900 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2152706900
46
+ version_requirements: *2152672900
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sqlite3
49
- requirement: &2152706260 !ruby/object:Gem::Requirement
49
+ requirement: &2152672320 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2152706260
57
+ version_requirements: *2152672320
58
58
  description: Library to work with Exlibris' Primo discovery system.
59
59
  email:
60
60
  - scotdalton@gmail.com
@@ -62,7 +62,9 @@ executables: []
62
62
  extensions: []
63
63
  extra_rdoc_files: []
64
64
  files:
65
+ - lib/exlibris/primo/eshelf.rb
65
66
  - lib/exlibris/primo/holding.rb
67
+ - lib/exlibris/primo/record.rb
66
68
  - lib/exlibris/primo/related_link.rb
67
69
  - lib/exlibris/primo/rsrc.rb
68
70
  - lib/exlibris/primo/searcher.rb
@@ -108,6 +110,8 @@ files:
108
110
  - test/dummy/script/rails
109
111
  - test/exlibris-primo_test.rb
110
112
  - test/test_helper.rb
113
+ - test/unit/eshelf_test.rb
114
+ - test/unit/record_test.rb
111
115
  - test/unit/searcher_benchmarks.rb
112
116
  - test/unit/searcher_test.rb
113
117
  - test/unit/web_service_benchmarks.rb
@@ -170,6 +174,8 @@ test_files:
170
174
  - test/dummy/script/rails
171
175
  - test/exlibris-primo_test.rb
172
176
  - test/test_helper.rb
177
+ - test/unit/eshelf_test.rb
178
+ - test/unit/record_test.rb
173
179
  - test/unit/searcher_benchmarks.rb
174
180
  - test/unit/searcher_test.rb
175
181
  - test/unit/web_service_benchmarks.rb