Class: MiniHarvest::MiniHarvest
- Inherits:
-
Object
- Object
- MiniHarvest::MiniHarvest
- Defined in:
- lib/miniharvest.rb
Constant Summary collapse
- @@marc_collection =
Nokogiri::XML('<collection xmlns="http://www.loc.gov/MARC21/slim">')
Instance Attribute Summary collapse
-
#from ⇒ Object
Returns the value of attribute from.
-
#oai_base_uri ⇒ Object
Returns the value of attribute oai_base_uri.
-
#set ⇒ Object
Returns the value of attribute set.
Instance Method Summary collapse
- #append_to_collection(records) ⇒ Object
- #get_records(token) ⇒ Object
- #initial_request ⇒ Object
- #oai_request(uri, params) ⇒ Object
- #process_request(res) ⇒ Object
Instance Attribute Details
#from ⇒ Object
Returns the value of attribute from.
12 13 14 |
# File 'lib/miniharvest.rb', line 12 def from @from end |
#oai_base_uri ⇒ Object
Returns the value of attribute oai_base_uri.
12 13 14 |
# File 'lib/miniharvest.rb', line 12 def oai_base_uri @oai_base_uri end |
#set ⇒ Object
Returns the value of attribute set.
12 13 14 |
# File 'lib/miniharvest.rb', line 12 def set @set end |
Instance Method Details
#append_to_collection(records) ⇒ Object
14 15 16 |
# File 'lib/miniharvest.rb', line 14 def append_to_collection(records) @@marc_collection.at('collection').add_child(records) end |
#get_records(token) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/miniharvest.rb', line 40 def get_records(token) params = { :verb => 'ListRecords', :resumptionToken => token } res = oai_request(self.oai_base_uri,params) resumption_token = process_request(res) if resumption_token != "" get_records(resumption_token) else puts @@marc_collection.to_s return end end |
#initial_request ⇒ Object
34 35 36 37 38 |
# File 'lib/miniharvest.rb', line 34 def initial_request params = { :verb => 'ListRecords', :set => self.set, :metadataPrefix => 'marc21', :from => self.from } res = oai_request(self.oai_base_uri,params) get_records(process_request(res)) end |
#oai_request(uri, params) ⇒ Object
18 19 20 21 22 |
# File 'lib/miniharvest.rb', line 18 def oai_request(uri,params) oai_uri = URI(uri) oai_uri.query = URI.encode_www_form(params) return Net::HTTP.get_response(oai_uri) end |
#process_request(res) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/miniharvest.rb', line 24 def process_request(res) doc = Nokogiri::XML(res.body) doc.remove_namespaces! records = doc.xpath('//record') append_to_collection(records) resumption_token = doc.xpath('//resumptionToken') return resumption_token.text end |