rbook 0.4.3 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/Rakefile +13 -176
  2. metadata +57 -117
  3. data/COPYING +0 -340
  4. data/LICENSE +0 -13
  5. data/README +0 -17
  6. data/examples/gbip.rb +0 -12
  7. data/examples/onix/stream_reader.rb +0 -13
  8. data/examples/pacstream.rb +0 -13
  9. data/examples/titlepage.rb +0 -14
  10. data/examples/titlepage_with_proxy.rb +0 -14
  11. data/examples/titlepage_www.rb +0 -18
  12. data/examples/www/find_all.rb +0 -23
  13. data/examples/www/find_cover_from_amazon.rb +0 -16
  14. data/examples/www/find_url_from_rainbow.rb +0 -12
  15. data/examples/www/list.rb +0 -13
  16. data/lib/rbook/bisac.rb +0 -31
  17. data/lib/rbook/bisac/message.rb +0 -99
  18. data/lib/rbook/bisac/po.rb +0 -97
  19. data/lib/rbook/bisac/po_line_item.rb +0 -33
  20. data/lib/rbook/bisac/product.rb +0 -176
  21. data/lib/rbook/errors.rb +0 -8
  22. data/lib/rbook/gbip.rb +0 -21
  23. data/lib/rbook/gbip/pos.rb +0 -118
  24. data/lib/rbook/gbip/title.rb +0 -36
  25. data/lib/rbook/gbip/warehouse.rb +0 -27
  26. data/lib/rbook/isbn.rb +0 -255
  27. data/lib/rbook/onix.rb +0 -70
  28. data/lib/rbook/onix/contributor.rb +0 -60
  29. data/lib/rbook/onix/lists.rb +0 -2
  30. data/lib/rbook/onix/lists/contributor_role.rb +0 -10
  31. data/lib/rbook/onix/lists/product_form.rb +0 -100
  32. data/lib/rbook/onix/message.rb +0 -112
  33. data/lib/rbook/onix/product.rb +0 -189
  34. data/lib/rbook/onix/sales_restriction.rb +0 -51
  35. data/lib/rbook/onix/stream_reader.rb +0 -120
  36. data/lib/rbook/onix/stream_writer.rb +0 -40
  37. data/lib/rbook/onix/supply_detail.rb +0 -68
  38. data/lib/rbook/onix/xchar.rb +0 -98
  39. data/lib/rbook/pacstream.rb +0 -64
  40. data/lib/rbook/titlepage.rb +0 -37
  41. data/lib/rbook/titlepage/client.rb +0 -126
  42. data/lib/rbook/titlepage/titlepage_driver.rb +0 -137
  43. data/lib/rbook/titlepage/titlepage_utils.rb +0 -379
  44. data/lib/rbook/titlepage/wwwclient.rb +0 -96
  45. data/lib/rbook/www.rb +0 -172
  46. data/lib/rbook/www/aau_scraper.rb +0 -76
  47. data/lib/rbook/www/amazon_uk_scraper.rb +0 -44
  48. data/lib/rbook/www/ban_scraper.rb +0 -62
  49. data/lib/rbook/www/base.rb +0 -87
  50. data/lib/rbook/www/harper_au_scraper.rb +0 -56
  51. data/lib/rbook/www/harper_us_scraper.rb +0 -55
  52. data/lib/rbook/www/hha_scraper.rb +0 -50
  53. data/lib/rbook/www/macmillan_scraper.rb +0 -62
  54. data/lib/rbook/www/orbis_scraper.rb +0 -48
  55. data/lib/rbook/www/oup_scraper.rb +0 -64
  56. data/lib/rbook/www/paulist_scraper.rb +0 -53
  57. data/lib/rbook/www/pearson_au_scraper.rb +0 -52
  58. data/lib/rbook/www/penguin_scraper.rb +0 -45
  59. data/lib/rbook/www/random_au_scraper.rb +0 -90
  60. data/lib/rbook/www/random_us_scraper.rb +0 -59
  61. data/lib/rbook/www/sas_scraper.rb +0 -54
  62. data/lib/rbook/www/unireps_scraper.rb +0 -58
  63. data/lib/rbook/www/wiley_us_scraper.rb +0 -54
  64. data/test/data/abingdon.xml +0 -38931
  65. data/test/data/augsburg.xml +0 -39009
  66. data/test/data/bisac_po.txt +0 -112
  67. data/test/data/chalice.xml +0 -10851
  68. data/test/data/eerdsman.xml +0 -36942
  69. data/test/data/invalid_no_product.xml +0 -9
  70. data/test/data/not_xml.csv +0 -1
  71. data/test/data/single_product.xml +0 -50
  72. data/test/data/valid_bisac.txt +0 -213
  73. data/test/data/xml_not_onix.xml +0 -7
  74. data/test/mocks/titlepage_driver.rb +0 -111
  75. data/test/unit/bisac/bisac_test.rb +0 -96
  76. data/test/unit/bisac/po_line_item_test.rb +0 -38
  77. data/test/unit/bisac/po_test.rb +0 -82
  78. data/test/unit/isbn_test.rb +0 -153
  79. data/test/unit/onix/contributor_test.rb +0 -50
  80. data/test/unit/onix/message_test.rb +0 -119
  81. data/test/unit/onix/product_test.rb +0 -101
  82. data/test/unit/onix/sales_restriction_test.rb +0 -48
  83. data/test/unit/onix/stream_reader_test.rb +0 -22
  84. data/test/unit/onix/stream_writer_test.rb +0 -32
  85. data/test/unit/onix/supply_detail_test.rb +0 -53
  86. data/test/unit/onix/xchar_test.rb +0 -37
  87. data/test/unit/titlepage_test.rb +0 -140
data/LICENSE DELETED
@@ -1,13 +0,0 @@
1
- = License Terms
2
-
3
- Distributed by James Healy under the user's choice* of the
4
- {GPL version 2}[http://www.gnu.org/copyleft/gpl.html] (see COPYING for details)
5
- or the {Ruby software license}[http://www.ruby-lang.org/en/LICENSE.txt].
6
-
7
- Please email James[mailto:jimmy_AT_deefa.com] with any questions.
8
-
9
- *Note: This license refers specifically to GPLv2.
10
- Distributing under other versions of the GPL require explicit permission from
11
- James Healy. Though we will most likely adopt the GPLv3 when the final draft
12
- is published, we want to be able to make that decision for ourselves.
13
-
data/README DELETED
@@ -1,17 +0,0 @@
1
- A collection of modules and classes for use in the book industry
2
-
3
- = Usage
4
-
5
- Please refer to each components documentation for information on usage.
6
-
7
- - RBook::Bisac - Support for reading and writing BISAC files.
8
- - RBook::GBIP - Very rudimentary support for using the globalbooksinprint.com TCP API.
9
- - RBook::ISBN - Convenience methods for validating and converting ISBNs.
10
- - RBook::Onix - Support for reading and writing ONIX files.
11
- - RBook::Pacstream - Support for reading and writing ONIX files.
12
- - RBook::TitlePage - A wrapper for the titlepage.com SOAP API.
13
- - RBook::WWW - Screen scraping library for publisher websites.
14
-
15
- This library is still quite young and I expect the API to fluctuate
16
- a little as it gets a good shakedown in the real world. If you use it
17
- via rubygems, I recommend pinning your require to a particular version.
@@ -1,12 +0,0 @@
1
- # assuming you have rbook installed via rubygems,
2
- # in a regular script, replace the following require
3
- # line with these 2 lines:
4
- # require 'rubygems'
5
- # require 'rbook/gbip'
6
- require File.dirname(__FILE__) + '/../lib/rbook/gbip'
7
-
8
- gbip = RBook::GBIP::POS.new("username", "password")
9
-
10
- #puts gbip.find("0091835135").inspect
11
- puts gbip.find("1741146712").inspect
12
-
@@ -1,13 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
-
3
- require 'rbook/onix'
4
-
5
- reader = RBook::Onix::StreamReader.new(File.dirname(__FILE__)+"/../../test/data/chalice.xml")
6
- counter = 0
7
-
8
- reader.each do |product|
9
- puts product.product_identifier
10
- counter += 1
11
- end
12
-
13
- puts "total of ##{counter.to_s} products"
@@ -1,13 +0,0 @@
1
- # assuming you have rbook installed via rubygems,
2
- # in a regular script you should replace the following require
3
- # line with these 2 lines:
4
- # require 'rubygems'
5
- # require 'rbook/pacstream'
6
- require File.dirname(__FILE__) + '/../lib/rbook/pacstream'
7
-
8
- counter = 0
9
-
10
- RBook::Pacstream.get(:orders, :username => "myusername", :password => "mypass") do |order|
11
- File.open("#{counter.to_s}.ord", "w") { |f| f.puts order }
12
- counter += 1
13
- end
@@ -1,14 +0,0 @@
1
- # assuming you have rbook installed via rubygems,
2
- # in a regular script, replace the following require
3
- # line with these 2 lines:
4
- # require 'rubygems'
5
- # require 'rbook/titlepage'
6
- require File.dirname(__FILE__) + '/../lib/rbook/titlepage'
7
-
8
- RBook::TitlePage::Client.open("username", "password") do |tp|
9
-
10
- puts tp.find("0091835135").inspect
11
- sleep 3
12
- puts tp.find("1741146712").inspect
13
-
14
- end
@@ -1,14 +0,0 @@
1
- # assuming you have rbook installed via rubygems,
2
- # in a regular script, replace the following require
3
- # line with these 2 lines:
4
- # require 'rubygems'
5
- # require 'rbook/titlepage'
6
- require File.dirname(__FILE__) + '/../lib/rbook/titlepage'
7
-
8
- RBook::TitlePage::Client.use_proxy("druby://127.0.0.1:61676")
9
-
10
- RBook::TitlePage::Client.open("username", "password") do |tp|
11
-
12
- puts tp.find("0091835135").product.title.titleText
13
-
14
- end
@@ -1,18 +0,0 @@
1
- # assuming you have rbook installed via rubygems,
2
- # in a regular script, replace the following require
3
- # line with these 2 lines:
4
- # require 'rubygems'
5
- # require 'rbook/titlepage'
6
- require File.dirname(__FILE__) + '/../lib/rbook/titlepage'
7
- require File.dirname(__FILE__) + '/../lib/rbook/onix'
8
-
9
- client = RBook::TitlePage::WWWClient.new
10
-
11
- client.login("username", "password")
12
-
13
- text = client.get_onix_file("9780060000707")
14
- #msg = RBook::Onix::Message.load_from_string(text)
15
- #puts msg.to_s
16
- puts text
17
-
18
- client.logout
@@ -1,23 +0,0 @@
1
- #!/usr/bin/ruby1.8
2
-
3
- # assuming you have rbook installed via rubygems,
4
- # in a regular script, replace the following require
5
- # line with these 2 lines:
6
- # require 'rubygems'
7
- # require 'rbook/www'
8
- require File.dirname(__FILE__) + '/../../lib/rbook/www'
9
-
10
- results = RBook::WWW.find_info(:all, ARGV[0], :rba)
11
-
12
- if results.nil?
13
- puts "No matches found"
14
- else
15
- results.each do |result|
16
- puts
17
- result.each do |key, value|
18
- puts key.to_s + " : " + value.to_s
19
- end
20
- end
21
- end
22
-
23
- puts
@@ -1,16 +0,0 @@
1
- #!/usr/bin/ruby1.8
2
-
3
- # assuming you have rbook installed via rubygems,
4
- # in a regular script, replace the following require
5
- # line with these 2 lines:
6
- # require 'rubygems'
7
- # require 'rbook/www'
8
- require File.dirname(__FILE__) + '/../../lib/rbook/www'
9
-
10
-
11
- result = RBook::WWW.find_cover(:first, ARGV[0], :amazon_uk)
12
-
13
- unless result.nil?
14
- File.open("cover.jpg","w") { |of| of.write result[:data]}
15
- end
16
-
@@ -1,12 +0,0 @@
1
- #!/usr/bin/ruby1.8
2
-
3
- # assuming you have rbook installed via rubygems,
4
- # in a regular script, replace the following require
5
- # line with these 2 lines:
6
- # require 'rubygems'
7
- # require 'rbook/www'
8
- require File.dirname(__FILE__) + '/../../lib/rbook/www'
9
-
10
-
11
- puts RBook::WWW.find_url(ARGV[0], :rba).inspect
12
-
@@ -1,13 +0,0 @@
1
- #!/usr/bin/ruby1.8
2
-
3
- # assuming you have rbook installed via rubygems,
4
- # in a regular script, replace the following require
5
- # line with these 2 lines:
6
- # require 'rubygems'
7
- # require 'rbook/www'
8
- require File.dirname(__FILE__) + '/../../lib/rbook/www'
9
-
10
- RBook::WWW.scrapers.each do |scraper|
11
- puts scraper::SCRAPER_NAME + " @ " + scraper::SCRAPER_SITE
12
- end
13
-
@@ -1,31 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__) + "/../")
2
-
3
- require 'rbook/bisac/message'
4
- require 'rbook/bisac/product'
5
- require 'rbook/bisac/po'
6
- require 'rbook/bisac/po_line_item'
7
- require 'rbook/isbn'
8
-
9
- module RBook
10
-
11
- # Ruby module for reading and writing BISAC files.
12
- # BISAC is a really bad format for electronic exchange of data - ONIX should be
13
- # used where possible. Here be dragons.
14
- #
15
- # = Basic Usage
16
- # require 'rubygems'
17
- # require 'rbook/bisac'
18
- # include Rbook
19
- # msg = Bisac::Message.new('Company', '1234567', '111111', '1'))
20
- # item = Bisac::Product.new('0123456789')
21
- # item.title = "A Book"
22
- # item.author = "Healy, James"
23
- # item.price = "1995"
24
- # item.binding = "PB"
25
- # item.status = "AVL"
26
- # msg << item
27
- # puts msg.to_s
28
- module Bisac
29
-
30
- end
31
- end
@@ -1,99 +0,0 @@
1
-
2
-
3
- module RBook
4
- module Bisac
5
-
6
- # Represents a single Bisac File. See RBook::Bisac for a basic
7
- # usage example.
8
- class Message
9
-
10
- attr_accessor :company, :san, :batch, :code, :products
11
-
12
- # creates a new bisac file in memory
13
- # params:
14
- # - company = company name (10 chars)
15
- # - san = company SAN number (12 chars)
16
- # - batch = batch name for this file (6 chars)
17
- # - code = 1 for new titles, 2 for updated titles (1 char)
18
- def initialize(company, san, batch, code)
19
- @company = company
20
- @san = san
21
- @batch = batch
22
- @code = code
23
- @products = []
24
- end
25
-
26
- # loads the requested BISAC file into memory.
27
- # returns a Message object or nil if the file is not
28
- # a BISAC file
29
- def self.load(filename)
30
- msg = self.new(nil,nil,nil,nil)
31
-
32
- File.open(filename, "r") do |f|
33
- f.each_line do |l|
34
- if l[0,10].eql?("**HEADER**")
35
- msg.company = l[16,10].strip
36
- msg.san = l[26,12].strip
37
- msg.batch = l[38,6].strip
38
- msg.code = l[44,1].strip
39
- elsif !l[0,11].eql?("**TRAILER**")
40
- product = RBook::Bisac::Product.from_string(l)
41
- msg << product unless product.nil?
42
- end
43
- end
44
- end
45
-
46
- if msg.company.nil? || msg.san.nil? || msg.batch.nil? || msg.code.nil?
47
- return nil
48
- else
49
- return msg
50
- end
51
- end
52
-
53
- # adds a new title to the bisic file. Expects a Rbook::Bisac::Product object.
54
- def << (item)
55
- unless item.class == RBook::Bisac::Product
56
- raise ArgumentError, 'item must be a RBook::Bisac::Product object'
57
- end
58
- @products << item
59
- end
60
-
61
- # converts this bisac file into a string
62
- def to_s
63
- # File Header
64
- content = "**HEADER**"
65
- content << Time.now.strftime("%y%m%d")
66
- content << @company[0,10].ljust(10)
67
- content << @san[0,12].ljust(12)
68
- content << @batch[0,6].ljust(6)
69
- content << @code[0,1].ljust(1)
70
- content << "**PUBSTAT*"
71
- content << "040"
72
- content << "".ljust(201)
73
- content << "\n"
74
-
75
- # File Content
76
- counter = 0
77
- @products.each do |item|
78
- content << item.to_s + "\n"
79
- counter = counter + 1
80
- end
81
-
82
- # File Footer
83
- content << "**TRAILER*"
84
- content << Time.now.strftime("%y%m%d")
85
- content << @batch[0,6].ljust(6)
86
- content << counter.to_s[0,6].ljust(6)
87
- content << "**PUBSTAT*"
88
- content << "".ljust(221)
89
-
90
- return content
91
- end
92
-
93
- # writes the content of this bisac file out to the specified file
94
- def write(filename)
95
- File.open(filename, "w") { |f| f.puts to_s }
96
- end
97
- end
98
- end
99
- end
@@ -1,97 +0,0 @@
1
- require File.dirname(__FILE__) + '/po_line_item'
2
- require File.dirname(__FILE__) + '/../errors'
3
-
4
- module RBook
5
- module Bisac
6
-
7
- # Represents a single BISAC purchase order
8
- class PO
9
-
10
- attr_accessor :source_san, :source_suffix, :source_name
11
- attr_accessor :date, :filename, :format_version
12
- attr_accessor :destination_san, :destination_suffix
13
- attr_accessor :po_number, :cancellation_date, :backorder
14
- attr_accessor :do_not_exceed_action, :do_not_exceed_amount
15
- attr_accessor :invoice_copies, :special_instructions
16
- attr_accessor :do_not_ship_before
17
- attr_accessor :items
18
-
19
- # creates a new RBook::Bisac::PO object
20
- def initialize
21
- @items = []
22
- end
23
-
24
- # reads a bisac text file into memory. input should be a string
25
- # that specifies the file path
26
- def self.load_from_file(input)
27
- raise RBook::InvalidFileError, 'Invalid file' unless File.exist?(input)
28
- data = []
29
- File.open(input) do |f|
30
- f.each_line { |l| data << l }
31
- end
32
- return self.build_message(data)
33
- end
34
-
35
- # creates a RBook::Bisac::PO object from a string. Input should
36
- # be a complete bisac file as a string
37
- def self.load_from_string(input)
38
- data = input.split("\n")
39
- return self.build_message(data)
40
- end
41
-
42
- private
43
-
44
- def self.build_message(data)
45
- raise Rbook::InvalidFileError, 'File appears to be too short' unless data.size >= 3
46
- raise RBook::InvalidFileError, 'Missing header information' unless data[0][0,2].eql?("00")
47
- raise RBook::InvalidFileError, 'Missing footer information' unless data[-1][0,2].eql?("90")
48
-
49
- msg = PO.new
50
-
51
- data.each do |line|
52
-
53
- case line[0,2]
54
- when "00" # first header
55
- msg.source_san = line[7,7].strip
56
- msg.source_suffix = line[14,5].strip
57
- msg.source_name = line[19,13].strip
58
- msg.date = line[32,6].strip
59
- msg.filename = line[38,20].strip
60
- msg.format_version = line[60,3].strip
61
- msg.destination_san = line[63,7].strip
62
- msg.destination_suffix = line[70,5].strip
63
- when "10" # second header
64
- msg.po_number = line[7, 12].strip
65
- msg.cancellation_date = line[50,6].strip
66
- msg.backorder = line[56,1].eql?("Y") ? true : false
67
- msg.do_not_exceed_action = line[57,1].strip
68
- msg.do_not_exceed_amount = line[58,7].strip
69
- msg.invoice_copies = line[65,2].strip
70
- msg.special_instructions = line[67,1].eql?("Y") ? true : false
71
- msg.do_not_ship_before = line[73,6].strip
72
- when "40" # line item
73
- # load each lineitem into the message
74
- item = RBook::Bisac::POLineItem.load_from_string(line)
75
- msg.items << item
76
- when "41"
77
- if line.length > 21
78
- title = line[21, line.length - 21]
79
- msg.items.last.title = title.strip unless title.nil?
80
- end
81
- when "42"
82
- if line.length > 21
83
- author = line[21, line.length - 21]
84
- msg.items.last.author = author.strip unless author.nil?
85
- end
86
- when "90" # footer
87
- # check the built objects match the file
88
- end
89
-
90
- end
91
-
92
- # return the results
93
- return msg
94
- end
95
- end
96
- end
97
- end
@@ -1,33 +0,0 @@
1
- require 'bigdecimal'
2
-
3
- module RBook
4
- module Bisac
5
-
6
- # represents a single line on the purchase order. Has attributes like
7
- # price, qty and description
8
- class POLineItem
9
-
10
- attr_accessor :sequence_number, :po_number, :line_item_number
11
- attr_accessor :isbn, :qty, :catalogue_code, :price
12
- attr_accessor :author, :title
13
-
14
- # returns a new RBook::Bisac::POLineItem object using the data passed in as a string
15
- # refer to the bisac spec for the expected format of the string
16
- def self.load_from_string(data)
17
- item = self.new
18
-
19
- item.sequence_number = data[2,5].to_i
20
- item.po_number = data[7,13].strip
21
- item.line_item_number = data[21,10].strip
22
- item.isbn = data[31,10].strip
23
- item.qty = data[41,5].to_i
24
- item.catalogue_code = data[46,1].strip
25
- item.price = BigDecimal.new(data[47,6])
26
-
27
- return item
28
- end
29
-
30
- end
31
- end
32
-
33
- end