rbook 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/COPYING +340 -0
  2. data/LICENSE +13 -0
  3. data/README +16 -0
  4. data/Rakefile +206 -0
  5. data/examples/titlepage.rb +14 -0
  6. data/examples/www/find_all.rb +23 -0
  7. data/examples/www/find_cover_from_amazon.rb +12 -0
  8. data/examples/www/find_url_from_rainbow.rb +12 -0
  9. data/examples/www/list.rb +13 -0
  10. data/lib/rbook/bisac.rb +175 -0
  11. data/lib/rbook/errors.rb +7 -0
  12. data/lib/rbook/isbn.rb +249 -0
  13. data/lib/rbook/onix.rb +68 -0
  14. data/lib/rbook/onix/contributor.rb +60 -0
  15. data/lib/rbook/onix/lists.rb +2 -0
  16. data/lib/rbook/onix/lists/contributor_role.rb +10 -0
  17. data/lib/rbook/onix/lists/product_form.rb +100 -0
  18. data/lib/rbook/onix/message.rb +101 -0
  19. data/lib/rbook/onix/product.rb +188 -0
  20. data/lib/rbook/onix/sales_restriction.rb +51 -0
  21. data/lib/rbook/onix/supply_detail.rb +68 -0
  22. data/lib/rbook/onix/xchar.rb +98 -0
  23. data/lib/rbook/titlepage.rb +96 -0
  24. data/lib/rbook/titlepage/TitleQueryClient.rb +62 -0
  25. data/lib/rbook/titlepage/titlepage_driver.rb +134 -0
  26. data/lib/rbook/titlepage/titlepage_utils.rb +374 -0
  27. data/lib/rbook/www.rb +172 -0
  28. data/lib/rbook/www/aau_scraper.rb +76 -0
  29. data/lib/rbook/www/amazon_uk_scraper.rb +44 -0
  30. data/lib/rbook/www/base.rb +87 -0
  31. data/lib/rbook/www/harper_au_scraper.rb +56 -0
  32. data/lib/rbook/www/harper_us_scraper.rb +55 -0
  33. data/lib/rbook/www/hha_scraper.rb +50 -0
  34. data/lib/rbook/www/macmillan_scraper.rb +62 -0
  35. data/lib/rbook/www/orbis_scraper.rb +48 -0
  36. data/lib/rbook/www/oup_scraper.rb +64 -0
  37. data/lib/rbook/www/paulist_scraper.rb +53 -0
  38. data/lib/rbook/www/pearson_au_scraper.rb +52 -0
  39. data/lib/rbook/www/penguin_scraper.rb +45 -0
  40. data/lib/rbook/www/random_au_scraper.rb +90 -0
  41. data/lib/rbook/www/random_us_scraper.rb +59 -0
  42. data/lib/rbook/www/sas_scraper.rb +54 -0
  43. data/lib/rbook/www/unireps_scraper.rb +58 -0
  44. data/lib/rbook/www/wiley_us_scraper.rb +54 -0
  45. data/test/data/abingdon.xml +38931 -0
  46. data/test/data/augsburg.xml +39009 -0
  47. data/test/data/chalice.xml +10851 -0
  48. data/test/data/eerdsman.xml +36942 -0
  49. data/test/data/invalid_no_product.xml +9 -0
  50. data/test/data/not_xml.csv +1 -0
  51. data/test/data/single_product.xml +50 -0
  52. data/test/data/xml_not_onix.xml +7 -0
  53. data/test/mocks/titlepage_driver.rb +107 -0
  54. data/test/unit/bisac_test.rb +57 -0
  55. data/test/unit/isbn_test.rb +149 -0
  56. data/test/unit/onix/contributor_test.rb +50 -0
  57. data/test/unit/onix/message_test.rb +119 -0
  58. data/test/unit/onix/product_test.rb +101 -0
  59. data/test/unit/onix/sales_restriction_test.rb +48 -0
  60. data/test/unit/onix/supply_detail_test.rb +53 -0
  61. data/test/unit/onix/xchar_test.rb +37 -0
  62. data/test/unit/titlepage_test.rb +127 -0
  63. metadata +130 -0
@@ -0,0 +1,101 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+
3
+ require 'test/unit'
4
+ require 'rexml/document'
5
+ require 'date'
6
+ require 'rbook/onix'
7
+
8
+ class ProductTest < Test::Unit::TestCase
9
+
10
+ def test_load_from_element
11
+
12
+ file = File.open(File.dirname(__FILE__)+"/../../data/single_product.xml", "r")
13
+ doc = REXML::Document.new(file)
14
+ product = RBook::Onix::Product.load_from_element(REXML::XPath.first(doc, '/ONIXMessage/Product'))
15
+
16
+ file.close
17
+
18
+ #check header elements
19
+ assert_equal('03', product.notification_type)
20
+ assert_equal('0827200528', product.record_reference)
21
+ assert_equal('BA', product.form)
22
+ assert_equal('0', product.pages)
23
+ assert_equal('YFH', product.bicmainsubject)
24
+ assert_equal('And Their Eyes Are Opened', product.title)
25
+ assert_equal('Story Sermons Embracing the World', product.subtitle)
26
+ assert_equal('Chalice', product.publisher)
27
+ assert Date.civil(2005, 3, 3) === product.publication_date
28
+
29
+ assert_equal(1, product.contributors.size, 'Product should contain 1 contributor')
30
+ assert_equal(1, product.supply_details.size, 'Product should contain 1 supply detail')
31
+
32
+ end
33
+
34
+ def test_load_from_element_not_product
35
+
36
+ element = REXML::Element.new('NonProduct')
37
+ element.add_element('NonContributor').text = 'blah'
38
+
39
+ assert_raise(LoadError) {
40
+ product = RBook::Onix::Product.load_from_element(element)
41
+ }
42
+
43
+ end
44
+
45
+ # ensure product information is output to xml correctly
46
+ # TODO: test more than just IDValue and TitleText
47
+ def test_to_element
48
+
49
+ product = RBook::Onix::Product.new
50
+ product.product_identifier = '0977616606'
51
+ product.title = 'This is a title'
52
+ product.publisher = 'Chalice'
53
+
54
+ contributor = RBook::Onix::Contributor.new
55
+ contributor.sequence_number = '0'
56
+ contributor.name_inverted = 'Healy, James'
57
+ contributor.role = 'A01'
58
+ product.add_contributor(contributor)
59
+
60
+ supply_detail = RBook::Onix::SupplyDetail.new
61
+ supply_detail.supplier_name = 'Walker'
62
+ supply_detail.availability_code = 'CS'
63
+ supply_detail.price = 29.95
64
+ product.add_supply_detail(supply_detail)
65
+
66
+ doc = product.to_element
67
+
68
+ assert_not_equal(nil,REXML::XPath.first(doc, '/ProductIdentifier/IDValue'))
69
+ assert_equal("0977616606", REXML::XPath.first(doc, '/ProductIdentifier/IDValue').text)
70
+ assert_not_equal(nil,REXML::XPath.first(doc, '/Title/TitleText'), 'TitleText must not be nil')
71
+ assert_equal("This is a title", REXML::XPath.first(doc, '/Title/TitleText').text)
72
+ assert_not_equal(nil, REXML::XPath.first(doc, '/Contributor'), 'Expected product element to contain a contributor')
73
+ assert_not_equal(nil, REXML::XPath.first(doc, '/Publisher/PublisherName'), 'Expected publisher name element to contain a contributor')
74
+ assert_equal("Chalice", REXML::XPath.first(doc, '/Publisher/PublisherName').text)
75
+ assert_not_equal(nil, REXML::XPath.first(doc, '/SupplyDetail'), 'Expected product element to contain a supply detail')
76
+ end
77
+
78
+ def test_to_s_valid_utf8_charset
79
+
80
+ # create an Onix::Product fragment
81
+ product = RBook::Onix::Product.new
82
+ product.product_identifier = "0977616606"
83
+ product.title = "Test Title\x11"
84
+ product.subtitle = "Test Subtitle\x11"
85
+ product.website = "http://www.google.com\x11"
86
+ product.form = "BA\x11"
87
+ product.bicmainsubject = "FGD\x11"
88
+ product.description = "This is a sample description\x11"
89
+ product.publisher = "Publisher\x11"
90
+
91
+ fragment = product.to_s
92
+
93
+ # loop over each byte in the product element and check it's
94
+ # a valid UTF-8 character
95
+ fragment.each_byte do |c|
96
+ n = XChar::CP1252[c] || c
97
+ n = nil unless XChar::VALID.find {|range| range.include? n}
98
+ assert_not_equal nil, n, "Non valid UTF8 char detected (code: #{n.to_s})"
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,48 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+
3
+ require 'test/unit'
4
+ require 'rexml/document'
5
+ require 'rbook/onix'
6
+
7
+ class SalesRestrictionTest < Test::Unit::TestCase
8
+
9
+ def test_load_from_element
10
+
11
+ file = File.open(File.dirname(__FILE__)+"/../../data/single_product.xml", "r")
12
+ doc = REXML::Document.new(file)
13
+ restriction = RBook::Onix::SalesRestriction.load_from_element(REXML::XPath.first(doc, '/ONIXMessage/Product/SalesRestriction'))
14
+
15
+ file.close
16
+
17
+ assert_equal('00', restriction.type)
18
+ assert_equal('Unknown', restriction.detail)
19
+ end
20
+
21
+ def test_load_from_element_not_sales_restriction
22
+
23
+ element = REXML::Element.new('NonRestriction')
24
+ element.add_element('Type').text = 'blah'
25
+
26
+ assert_raise(LoadError) {
27
+ product = RBook::Onix::SalesRestriction.load_from_element(element)
28
+ }
29
+
30
+ end
31
+
32
+ # ensure product information is output to xml correctly
33
+ def test_to_element
34
+
35
+ restriction = RBook::Onix::SalesRestriction.new
36
+ restriction.type = '00'
37
+ restriction.detail = 'Unknown'
38
+
39
+ doc = restriction.to_element
40
+
41
+ assert_not_equal(nil,REXML::XPath.first(doc, '/SalesRestrictionType'), 'Sales Restriction Type must not be nil')
42
+ assert_equal("00", REXML::XPath.first(doc, '/SalesRestrictionType').text)
43
+ assert_not_equal(nil,REXML::XPath.first(doc, '/SalesRestrictionDetail'), 'Sales Restriction Detail must not be nil')
44
+ assert_equal("Unknown", REXML::XPath.first(doc, '/SalesRestrictionDetail').text)
45
+
46
+ end
47
+
48
+ end
@@ -0,0 +1,53 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+
3
+ require 'test/unit'
4
+ require 'rexml/document'
5
+ require 'rbook/onix'
6
+
7
+ class SupplyDetailTest < Test::Unit::TestCase
8
+
9
+ def test_load_from_element
10
+
11
+ file = File.open(File.dirname(__FILE__)+"/../../data/single_product.xml", "r")
12
+ doc = REXML::Document.new(file)
13
+ supply_detail = RBook::Onix::SupplyDetail.load_from_element(REXML::XPath.first(doc, '/ONIXMessage/Product/SupplyDetail'))
14
+
15
+ file.close
16
+
17
+ assert_equal('Chalice', supply_detail.supplier_name)
18
+ assert_equal('CS', supply_detail.availability_code)
19
+ assert_equal('99', supply_detail.intermediary_availability_code)
20
+ assert_equal(29.95, supply_detail.price)
21
+ end
22
+
23
+ def test_load_from_element_not_supply_detail
24
+
25
+ element = REXML::Element.new('NonSupplyDetail')
26
+ element.add_element('SupplierName').text = 'blah'
27
+
28
+ assert_raise(LoadError) {
29
+ supply_detail = RBook::Onix::SupplyDetail.load_from_element(element)
30
+ }
31
+
32
+ end
33
+
34
+ # ensure product information is output to xml correctly
35
+ def test_to_element
36
+
37
+ supply_detail = RBook::Onix::SupplyDetail.new
38
+ supply_detail.supplier_name = 'Walker'
39
+ supply_detail.availability_code = 'CS'
40
+ supply_detail.price = 38.05
41
+
42
+ doc = supply_detail.to_element
43
+
44
+ assert_not_equal(nil,REXML::XPath.first(doc, '/SupplierName'), 'Supplier Name must not be nil')
45
+ assert_equal("Walker", REXML::XPath.first(doc, '/SupplierName').text)
46
+ assert_not_equal(nil,REXML::XPath.first(doc, '/AvailabilityCode'), 'Availability Code must not be nil')
47
+ assert_equal("CS", REXML::XPath.first(doc, '/AvailabilityCode').text)
48
+ assert_not_equal(nil,REXML::XPath.first(doc, '/Price/PriceAmount'), 'Price Amount must not be nil')
49
+ assert_equal("38.05", REXML::XPath.first(doc, '/Price/PriceAmount').text)
50
+
51
+ end
52
+
53
+ end
@@ -0,0 +1,37 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+
3
+ require 'test/unit'
4
+ require 'rbook/onix'
5
+
6
+ class TestXmlEscaping < Test::Unit::TestCase
7
+ def test_ascii
8
+ assert_equal 'abc', 'abc'.to_xs
9
+ end
10
+
11
+ def test_predefined
12
+ assert_equal '&amp;', '&'.to_xs # ampersand
13
+ assert_equal '&lt;', '<'.to_xs # left angle bracket
14
+ assert_equal '&gt;', '>'.to_xs # right angle bracket
15
+ end
16
+
17
+ def test_invalid
18
+ assert_equal '*', "\x00".to_xs # null
19
+ assert_equal '*', "\x0C".to_xs # form feed
20
+ assert_equal '*', "\xEF\xBF\xBF".to_xs # U+FFFF
21
+ end
22
+
23
+ def test_iso_8859_1
24
+ assert_equal '&#231;', "\xE7".to_xs # small c cedilla
25
+ assert_equal '&#169;', "\xA9".to_xs # copyright symbol
26
+ end
27
+
28
+ def test_win_1252
29
+ assert_equal '&#8217;', "\x92".to_xs # smart quote
30
+ assert_equal '&#8364;', "\x80".to_xs # euro
31
+ end
32
+
33
+ def test_utf8
34
+ assert_equal '&#8217;', "\xE2\x80\x99".to_xs # right single quote
35
+ assert_equal '&#169;', "\xC2\xA9".to_xs # copy
36
+ end
37
+ end
@@ -0,0 +1,127 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+
3
+ require 'test/unit'
4
+ require 'rbook/titlepage'
5
+ require File.dirname(__FILE__) + '/../mocks/titlepage_driver'
6
+
7
+ class TitlePageTest < Test::Unit::TestCase
8
+
9
+ def setup
10
+ @tp = RBook::TitlePage.new(MockTitlePageDriver.new)
11
+ end
12
+
13
+ # ensure a SOAP exception is raised if incorrect login details are provided
14
+ def test_bad_login
15
+ unless RUBY_VERSION >= "1.8.3"
16
+ warn "Ruby version >= 1.8.3 required to use the titlepage library. Skipping unit test"
17
+ return
18
+ end
19
+
20
+ assert_raise(SOAP::FaultError) {
21
+ @tp.login("bad","login")
22
+ }
23
+ end
24
+
25
+ # ensure searching for a title using the open method works
26
+ def test_search_using_block
27
+ unless RUBY_VERSION >= "1.8.3"
28
+ warn "Ruby version >= 1.8.3 required to use the titlepage library. Skipping unit test"
29
+ return
30
+ end
31
+
32
+ RBook::TitlePage.open("test","apa", MockTitlePageDriver.new) do |tp|
33
+
34
+ result = tp.find("9780091835132")
35
+
36
+ assert_kind_of SearchResults, result
37
+ assert_not_equal nil, result.Product
38
+
39
+ end
40
+ end
41
+
42
+ # ensure searching for a title that is in stock returns a SearchResults object
43
+ def test_title_in_stock
44
+
45
+ unless RUBY_VERSION >= "1.8.3"
46
+ warn "Ruby version >= 1.8.3 required to use the titlepage library. Skipping unit test"
47
+ return
48
+ end
49
+
50
+ @tp.login("test","apa")
51
+ result = @tp.find("9780091835132")
52
+
53
+ assert_kind_of SearchResults, result
54
+ assert_not_equal nil, result.Product
55
+
56
+ @tp.logout
57
+ end
58
+
59
+ # ensure searching for a title that is out of stock returns a SearchResults object
60
+ def test_title_no_stock
61
+
62
+ unless RUBY_VERSION >= "1.8.3"
63
+ warn "Ruby version >= 1.8.3 required to use the titlepage library. Skipping unit test"
64
+ return
65
+ end
66
+
67
+ @tp.login("test","apa")
68
+ result = @tp.find("9780672327568")
69
+
70
+ assert_kind_of SearchResults, result
71
+ assert_not_equal nil, result.Product
72
+
73
+ @tp.logout
74
+ end
75
+
76
+ # ensure searching for a title that isn't listed on titlepage returns nil
77
+ def test_title_not_found
78
+
79
+ unless RUBY_VERSION >= "1.8.3"
80
+ warn "Ruby version >= 1.8.3 required to use the titlepage library. Skipping unit test"
81
+ return
82
+ end
83
+
84
+ @tp.login("test","apa")
85
+ result = @tp.find("9780522848670")
86
+
87
+ assert_equal nil, result
88
+
89
+ @tp.logout
90
+ end
91
+
92
+ # ensure searching for whack ISBNs returns nil
93
+ def test_boundaries
94
+
95
+ unless RUBY_VERSION >= "1.8.3"
96
+ warn "Ruby version >= 1.8.3 required to use the titlepage library. Skipping unit test"
97
+ return
98
+ end
99
+
100
+ @tp.login("test","apa")
101
+
102
+ assert_equal nil, @tp.find("978052284867")
103
+ assert_equal nil, @tp.find("978-0522-84867")
104
+ assert_equal nil, @tp.find(nil)
105
+ assert_equal nil, @tp.find(:test)
106
+ assert_equal nil, @tp.find(Array.new)
107
+ assert_equal nil, @tp.find(-1)
108
+
109
+ @tp.logout
110
+ end
111
+
112
+ # ensure logging out works
113
+ def test_logout
114
+
115
+ unless RUBY_VERSION >= "1.8.3"
116
+ warn "Ruby version >= 1.8.3 required to use the titlepage library. Skipping unit test"
117
+ return
118
+ end
119
+
120
+ @tp.login("test","apa")
121
+ result = @tp.find("9780522848670")
122
+
123
+ assert @tp.logout
124
+ end
125
+ end
126
+
127
+
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: rbook
5
+ version: !ruby/object:Gem::Version
6
+ version: "0.1"
7
+ date: 2006-09-26 00:00:00 +10:00
8
+ summary: A collection of classes and modules for working with bibliographic data
9
+ require_paths:
10
+ - lib
11
+ email: jimmy@deefa.com
12
+ homepage: http://rbook.rubyforge.org/
13
+ rubyforge_project: rbook
14
+ description: rbook is a collection of classes and modules for working with bibliographic data. It currently supports converting and validating isbns, and converting to and from both ONIX and BISAC
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ authors:
29
+ - James Healy
30
+ files:
31
+ - examples/www
32
+ - examples/titlepage.rb
33
+ - examples/www/find_all.rb
34
+ - examples/www/list.rb
35
+ - examples/www/find_cover_from_amazon.rb
36
+ - examples/www/find_url_from_rainbow.rb
37
+ - lib/rbook
38
+ - lib/rbook/errors.rb
39
+ - lib/rbook/bisac.rb
40
+ - lib/rbook/titlepage.rb
41
+ - lib/rbook/isbn.rb
42
+ - lib/rbook/onix.rb
43
+ - lib/rbook/onix
44
+ - lib/rbook/www.rb
45
+ - lib/rbook/titlepage
46
+ - lib/rbook/www
47
+ - lib/rbook/onix/lists
48
+ - lib/rbook/onix/sales_restriction.rb
49
+ - lib/rbook/onix/supply_detail.rb
50
+ - lib/rbook/onix/product.rb
51
+ - lib/rbook/onix/lists.rb
52
+ - lib/rbook/onix/contributor.rb
53
+ - lib/rbook/onix/message.rb
54
+ - lib/rbook/onix/xchar.rb
55
+ - lib/rbook/onix/lists/contributor_role.rb
56
+ - lib/rbook/onix/lists/product_form.rb
57
+ - lib/rbook/titlepage/titlepage_driver.rb
58
+ - lib/rbook/titlepage/titlepage_utils.rb
59
+ - lib/rbook/titlepage/TitleQueryClient.rb
60
+ - lib/rbook/www/base.rb
61
+ - lib/rbook/www/pearson_au_scraper.rb
62
+ - lib/rbook/www/wiley_us_scraper.rb
63
+ - lib/rbook/www/hha_scraper.rb
64
+ - lib/rbook/www/random_au_scraper.rb
65
+ - lib/rbook/www/oup_scraper.rb
66
+ - lib/rbook/www/penguin_scraper.rb
67
+ - lib/rbook/www/harper_au_scraper.rb
68
+ - lib/rbook/www/aau_scraper.rb
69
+ - lib/rbook/www/orbis_scraper.rb
70
+ - lib/rbook/www/paulist_scraper.rb
71
+ - lib/rbook/www/amazon_uk_scraper.rb
72
+ - lib/rbook/www/unireps_scraper.rb
73
+ - lib/rbook/www/sas_scraper.rb
74
+ - lib/rbook/www/random_us_scraper.rb
75
+ - lib/rbook/www/harper_us_scraper.rb
76
+ - lib/rbook/www/macmillan_scraper.rb
77
+ - test/unit
78
+ - test/data
79
+ - test/mocks
80
+ - test/unit/onix
81
+ - test/unit/titlepage_test.rb
82
+ - test/unit/bisac_test.rb
83
+ - test/unit/isbn_test.rb
84
+ - test/unit/onix/sales_restriction_test.rb
85
+ - test/unit/onix/supply_detail_test.rb
86
+ - test/unit/onix/product_test.rb
87
+ - test/unit/onix/message_test.rb
88
+ - test/unit/onix/xchar_test.rb
89
+ - test/unit/onix/contributor_test.rb
90
+ - test/data/single_product.xml
91
+ - test/data/xml_not_onix.xml
92
+ - test/data/abingdon.xml
93
+ - test/data/invalid_no_product.xml
94
+ - test/data/chalice.xml
95
+ - test/data/not_xml.csv
96
+ - test/data/eerdsman.xml
97
+ - test/data/augsburg.xml
98
+ - test/mocks/titlepage_driver.rb
99
+ - Rakefile
100
+ - README
101
+ - COPYING
102
+ - LICENSE
103
+ test_files: []
104
+
105
+ rdoc_options:
106
+ - --title
107
+ - rbook Documentation
108
+ - --main
109
+ - README
110
+ - -q
111
+ extra_rdoc_files:
112
+ - README
113
+ - COPYING
114
+ - LICENSE
115
+ executables: []
116
+
117
+ extensions: []
118
+
119
+ requirements: []
120
+
121
+ dependencies:
122
+ - !ruby/object:Gem::Dependency
123
+ name: scrapi
124
+ version_requirement:
125
+ version_requirements: !ruby/object:Gem::Version::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: 1.2.0
130
+ version: