worldcatapi 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTdhZjEzN2E4YTNlZDNmYmU4YTU0NGNlNzgwZGRiOTkzMjczMzU1OQ==
4
+ MTk3OTEwOWQwZTAwMDI1ZGY4ODk2Zjg2OTU4ZDdlOTlhNmI1MzJmMQ==
5
5
  data.tar.gz: !binary |-
6
- OTdjMWVmOGRkNzk1MmNkY2QxOGQyNmE5MGY4MzZjYmI4OGY5MmM3Ng==
6
+ NTFmNjAyYjk2YWU1YWUyZGU4N2ZhMzJjYmY1ZDU0YmI3ZWE0MzMxNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OGMyOGJmNDJlZDZmOGI2NGE4Nzk4MTNhYWFiMDcwOTVlZDRiZjUwNDM3NDZk
10
- NWU5NGYzOGNmMjQ5YmJlZmM5MTU1NTkwZmYyZjhmNWExNTkwZGZmNmYwMzUy
11
- NDE3Y2IwNTAyMWY1OTAwYjcxMjI0Yjk3ODcxMGI5MTM2YWMyN2M=
9
+ N2MwNGZkMDNiMWU3MzU4OWI5NzQyY2RiZWUxOTIzNWY1NTBlZDZiZmYxZjli
10
+ Mjc0YzI5YWZjMjhiNWZhYjE5MTQ1NDIyYTBjMmUxMjlkYjQ4NDBiNjI0OThl
11
+ YTIzMDc2MTA1NzA2YWFjMDE2NjEwNThkYmMyZmUxYmQzMmE2MmI=
12
12
  data.tar.gz: !binary |-
13
- ODk5OWQ3ZGEwNGQ5ZTRiODdmZmRlZWJiM2E2ZWU5YTBhZDY5ZjRiMDg4MjA1
14
- OTRlY2U5YTMzNWRiZjE5Y2QwMWMzYTE4MTA3NWIyYmFhZTNlOTExZmRmMTNi
15
- NzZjNWRkMzc3NTVmZTAxZGFmYzMyMmQzZDY0ZTQ0MGQ1MWI3MjQ=
13
+ YzBhYzg3NTIyMmFlZDdjYTA1NzkxYTYxMWE2MDU0OGE2YjhhNDVmZGYwYTJl
14
+ Mjk2ZmM1YTViMjI0NmEzNWQ5MzBlZTFjZTJkNGRmMzhjZDVhMDQwZWJkYTA4
15
+ ODE0NjFjOGNiNzdmYTcyMzI1MDI1NTQ2ZGNhMGQzYjZlMTBjZTE=
data/Gemfile.lock CHANGED
@@ -2,6 +2,8 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  worldcatapi (1.0.0)
5
+ marc (~> 0.8.1)
6
+ nokogiri (~> 1.5.7)
5
7
 
6
8
  GEM
7
9
  remote: https://rubygems.org/
@@ -16,6 +18,7 @@ GEM
16
18
  celluloid (0.15.2)
17
19
  timers (~> 1.1.0)
18
20
  coderay (1.1.0)
21
+ ensure_valid_encoding (0.5.3)
19
22
  ffi (1.9.3)
20
23
  formatador (0.2.4)
21
24
  guard (2.2.4)
@@ -33,9 +36,13 @@ GEM
33
36
  rb-fsevent (>= 0.9.3)
34
37
  rb-inotify (>= 0.9)
35
38
  lumberjack (1.0.4)
39
+ marc (0.8.1)
40
+ ensure_valid_encoding
41
+ unf
36
42
  method_source (0.8.2)
37
43
  minitest (4.7.5)
38
44
  multi_json (1.8.2)
45
+ nokogiri (1.5.11)
39
46
  pry (0.9.12.4)
40
47
  coderay (~> 1.0)
41
48
  method_source (~> 0.8)
@@ -57,6 +64,9 @@ GEM
57
64
  atomic
58
65
  timers (1.1.0)
59
66
  tzinfo (0.3.38)
67
+ unf (0.1.3)
68
+ unf_ext
69
+ unf_ext (0.0.6)
60
70
 
61
71
  PLATFORMS
62
72
  ruby
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- worldcat-api
1
+ worldcatapi
2
2
  ============
3
3
 
4
4
  The RUBY API to access WorldCat.org webservices. Inspired by original wcapi implementation
@@ -6,7 +6,7 @@ The RUBY API to access WorldCat.org webservices. Inspired by original wcapi impl
6
6
 
7
7
  # Worldcatapi
8
8
 
9
- Forked from RubyForge WCAPI project.
9
+ Forked from RubyForge WCAPI project. It now lives on rubygems.org for easy installation and usage.
10
10
 
11
11
  ## Installation
12
12
 
@@ -24,7 +24,24 @@ Or install it yourself as:
24
24
 
25
25
  ## Usage
26
26
 
27
- TODO: Write usage instructions here
27
+ Clone this project and look at example.rb file.
28
+
29
+ It outlines all of the available operations.
30
+
31
+ require 'worldcatapi'
32
+
33
+ client = WORLDCATAPI::Client.new key: YOUR_KEY
34
+ response = client.OpenSearch(q: 'Ruby Development', format: 'atom', start: 1, count: 20, cformat: "all")
35
+
36
+ puts "Total Results #{response.header["totalResults"]
37
+ response.records.each do |record|
38
+ puts "title: #{record[:title]}\n"
39
+ puts "url: #{record[:link]}\n"
40
+ puts "authors: #{record[:author].join(", "}\n"
41
+ puts "description: #{record[:summary]}\n"
42
+ end
43
+
44
+ More examples available in example.rb
28
45
 
29
46
  ## Contributing
30
47
 
@@ -1,3 +1,6 @@
1
+ require 'ostruct'
2
+ require 'marc'
3
+
1
4
  module WORLDCATAPI
2
5
  class GetRecordResponse
3
6
 
@@ -20,43 +23,27 @@ module WORLDCATAPI
20
23
  _xml = xml
21
24
  _rechash = {}
22
25
  _x = 0
23
-
24
- doc = Nokogiri::XML(xml)
25
- doc.remove_namespaces!
26
- nodes = doc.xpath("/record")
27
- puts "NODE Count: " + nodes.length.to_s
28
- nodes.each { |item |
29
- _title = item.xpath("datafield[@tag='245']/subfield[@code='a'][position()=1]").text
30
-
31
- if item.xpath("datafield[@tag='1*']") != nil
32
- item.xpath("datafield[@tag='1*']").each {|i|
33
- _author.push(i.xpath("subfield[@code='a']").text)
34
- }
35
- end
36
-
37
- if item.xpath("datafield[@tag='7*']") != nil
38
- item.xpath("datafield[@tag='7*']").each {|i|
39
- _author.push(i.xpath("subfield[@code='a']").text)
40
- }
41
- end
42
-
43
- if item.xpath("controlfield[@tag='001']") != nil
44
- _id = item.xpath("controlfield[@tag='001']").text
45
- _link = 'http://www.worldcat.org/oclc/' + _id.to_s
46
- end
47
-
48
- if item.xpath("datafield[@tag='520']") != nil
49
- _summary = item.xpath("datafield[@tag='520']/subfield[@code='a'][position()=1]").text
50
- else
51
- if item.xpath("datafield[@tag='500']") != nil
52
- _summary = item.xpath("datafield[@tag='500']/subfield[@code='a'][position()=1]").text
53
- end
54
- end
26
+
27
+
28
+ reader = MARC::XMLReader.new(StringIO.new(xml))
29
+
30
+ for r in reader
31
+ @record = OpenStruct.new
32
+ @record.id = r["001"].value
33
+ @record.title = r['245']['a']
34
+ @record.author = Array.new.push r['100']['a']
35
+ @record.summary = r['500']['a']
36
+ @record.link = "http://www.worldcat.org/oclc/#{@record.id}"
37
+ @record.isbn = r['020']['a']
38
+ @record.publisher = r['260'].value
39
+ @record.edition = r['250']['a'] if r['250']
40
+ @record.physical_description = r['300'].value
41
+
42
+ end
43
+
44
+ @record.xml = xml
55
45
 
56
- _rechash = {:title => _title, :author => _author, :link => _link, :id => _id, :citation => _citation,
57
- :summary => _summary, :xml => item.to_s}
58
- }
59
- @record = _rechash
46
+ @record
60
47
  end
61
48
 
62
49
  end
@@ -2,7 +2,7 @@ module WORLDCATAPI
2
2
 
3
3
  class Record
4
4
 
5
- attr_accessor :title, :author, :link, :id, :citation, :summary, :xml
5
+ attr_accessor :title, :author, :link, :id, :citation, :summary, :xml, :isbn
6
6
 
7
7
  def initialize(pxml)
8
8
  #Setup a document
@@ -1,3 +1,3 @@
1
1
  module WORLDCATAPI
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ class GetRecordResponseTest < Test::Unit::TestCase
4
+
5
+ setup do
6
+ @response_xml = "<record>\n <leader>00000cam a2200000Ia 4500</leader>\n <controlfield tag=\"001\">671660984</controlfield>\n <controlfield tag=\"008\">101025s2008 nz o 000 d eng d</controlfield>\n <datafield ind1=\" \" ind2=\" \" tag=\"020\">\n <subfield code=\"a\">9781775413158 (electronic bk.)</subfield>\n </datafield>\n <datafield ind1=\" \" ind2=\" \" tag=\"020\">\n <subfield code=\"a\">1775413152 (electronic bk.)</subfield>\n </datafield>\n <datafield ind1=\"1\" ind2=\" \" tag=\"100\">\n <subfield code=\"a\">Shakespeare, William,</subfield>\n <subfield code=\"d\">1564-1616.</subfield>\n </datafield>\n <datafield ind1=\"1\" ind2=\"0\" tag=\"245\">\n <subfield code=\"a\">Julius Caesar</subfield>\n <subfield code=\"h\">[electronic resource] /</subfield>\n <subfield code=\"c\">William Shakespeare.</subfield>\n </datafield>\n <datafield ind1=\" \" ind2=\" \" tag=\"260\">\n <subfield code=\"a\">[Waiheke Island] :</subfield>\n <subfield code=\"b\">Floating Press,</subfield>\n <subfield code=\"c\">c2008.</subfield>\n </datafield>\n <datafield ind1=\" \" ind2=\" \" tag=\"300\">\n <subfield code=\"a\">1 online resource (182 p.)</subfield>\n </datafield>\n <datafield ind1=\" \" ind2=\" \" tag=\"500\">\n <subfield code=\"a\">Title from PDF title page (viewed Oct. 25, 2010).</subfield>\n </datafield>\n <datafield ind1=\"1\" ind2=\"0\" tag=\"600\">\n <subfield code=\"a\">Caesar, Julius</subfield>\n <subfield code=\"x\">Assassination</subfield>\n <subfield code=\"v\">Drama.</subfield>\n </datafield>\n <datafield ind1=\"1\" ind2=\"0\" tag=\"600\">\n <subfield code=\"a\">Brutus, Marcus Junius,</subfield>\n <subfield code=\"d\">85 B.C.?-42 B.C.</subfield>\n <subfield code=\"v\">Drama.</subfield>\n </datafield>\n <datafield ind1=\" \" ind2=\"0\" tag=\"651\">\n <subfield code=\"a\">Rome</subfield>\n <subfield code=\"x\">History</subfield>\n <subfield code=\"y\">Civil War, 43-31 B.C.</subfield>\n <subfield code=\"v\">Drama.</subfield>\n </datafield>\n <datafield ind1=\" \" ind2=\"0\" tag=\"650\">\n <subfield code=\"a\">Conspiracies</subfield>\n <subfield code=\"v\">Drama.</subfield>\n </datafield>\n <datafield ind1=\" \" ind2=\"0\" tag=\"650\">\n <subfield code=\"a\">Assassins</subfield>\n <subfield code=\"v\">Drama.</subfield>\n </datafield>\n <datafield ind1=\" \" ind2=\"4\" tag=\"655\">\n <subfield code=\"a\">Electronic books.</subfield>\n </datafield>\n <datafield ind1=\"4\" ind2=\"0\" tag=\"856\">\n <subfield code=\"3\">EBSCOhost</subfield>\n <subfield code=\"u\">http://search.ebscohost.com/login.aspx?direct=true&amp;scope=site&amp;db=nlebk&amp;db=nlabk&amp;AN=313629</subfield>\n </datafield>\n </record>"
7
+ end
8
+
9
+
10
+ should "parse the response and put it into a proper record" do
11
+ response = WORLDCATAPI::GetRecordResponse.new(@response_xml)
12
+ assert_not_nil response.record, "Record was created"
13
+
14
+ record = response.record
15
+ assert_equal "Julius Caesar", record.title, "Title must match"
16
+ assert_equal "671660984", record.id, "Id must match"
17
+
18
+ assert_equal 1, record.author.size, "Only one author"
19
+ assert_equal "Shakespeare, William,", record.author.first, "Author must match"
20
+ assert_equal "9781775413158 (electronic bk.)", record.isbn, "ISBN must match"
21
+ assert_equal "[Waiheke Island] :Floating Press,c2008.", record.publisher, "Publisher must match"
22
+ assert_equal "1 online resource (182 p.)", record.physical_description, "PhysDesc must match"
23
+ assert_equal "Title from PDF title page (viewed Oct. 25, 2010).", record.summary, "Summary must match"
24
+
25
+ assert_not_nil record.xml, "Should copy xml"
26
+ end
27
+ end
@@ -1,7 +1,7 @@
1
1
  require "test_helper"
2
2
 
3
3
 
4
- class TestWorldcatApi < Test::Unit::TestCase
4
+ class WorldcatapiTest < Test::Unit::TestCase
5
5
 
6
6
  should "test worlcatapi settings" do
7
7
  assert true, "Something happens"
data/test/test_helper.rb CHANGED
@@ -1,3 +1,3 @@
1
- require "WOLDCATAPI"
1
+ require "worldcatapi"
2
2
  require "test/unit"
3
3
  require "shoulda"
data/worldcatapi.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
 
22
22
  spec.add_runtime_dependency "nokogiri", "~>1.5.7"
23
+ spec.add_runtime_dependency "marc", "~>0.8.1"
23
24
 
24
25
  spec.add_development_dependency "bundler", "~> 1.3"
25
26
  spec.add_development_dependency "rake"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: worldcatapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taras Danylak
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-21 00:00:00.000000000 Z
12
+ date: 2014-02-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -25,6 +25,20 @@ dependencies:
25
25
  - - ~>
26
26
  - !ruby/object:Gem::Version
27
27
  version: 1.5.7
28
+ - !ruby/object:Gem::Dependency
29
+ name: marc
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 0.8.1
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: 0.8.1
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: bundler
30
44
  requirement: !ruby/object:Gem::Requirement
@@ -77,6 +91,7 @@ files:
77
91
  - lib/worldcatapi/record.rb
78
92
  - lib/worldcatapi/sru_search_response.rb
79
93
  - lib/worldcatapi/version.rb
94
+ - test/lib/get_record_response_test.rb
80
95
  - test/lib/worldcatapi_test.rb
81
96
  - test/test_helper.rb
82
97
  - worldcatapi.gemspec
@@ -105,5 +120,6 @@ signing_key:
105
120
  specification_version: 4
106
121
  summary: Ruby API to access WorldCat Open Search webserbice. Based on WCAPI Gem.
107
122
  test_files:
123
+ - test/lib/get_record_response_test.rb
108
124
  - test/lib/worldcatapi_test.rb
109
125
  - test/test_helper.rb