rbook 0.2.1 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README +2 -2
- data/Rakefile +1 -1
- data/examples/pacstream.rb +13 -0
- data/lib/rbook/pacstream.rb +55 -0
- metadata +4 -2
data/README
CHANGED
@@ -2,13 +2,13 @@ A collection of modules and classes for use in the book industry
|
|
2
2
|
|
3
3
|
= Usage
|
4
4
|
|
5
|
-
|
6
|
-
respective documentation for information on usage.
|
5
|
+
Please refer to each components documentation for information on usage.
|
7
6
|
|
8
7
|
- RBook::Bisac - Support for reading and writing BISAC files.
|
9
8
|
- RBook::GBIP - Very rudimentary support for using the globalbooksinprint.com TCP API.
|
10
9
|
- RBook::ISBN - Convenience methods for validating and converting ISBNs.
|
11
10
|
- RBook::Onix - Support for reading and writing ONIX files.
|
11
|
+
- RBook::Pacstream - Support for reading and writing ONIX files.
|
12
12
|
- RBook::TitlePage - A wrapper for the titlepage.com SOAP API.
|
13
13
|
- RBook::WWW - Screen scraping library for publisher websites.
|
14
14
|
|
data/Rakefile
CHANGED
@@ -0,0 +1,13 @@
|
|
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
|
@@ -0,0 +1,55 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + "/../")
|
2
|
+
|
3
|
+
require 'net/ftp'
|
4
|
+
|
5
|
+
module RBook
|
6
|
+
|
7
|
+
# Ruby class for sending and retrieving electronic orders
|
8
|
+
# via pacstream, a service run by the ECN GRoup
|
9
|
+
# (http://www.ecngroup.com.au/)
|
10
|
+
#
|
11
|
+
# = Basic Usage
|
12
|
+
#
|
13
|
+
# RBook::Pacstream.get(:orders, :username => "myusername", :password => "mypass") do |order|
|
14
|
+
# puts order
|
15
|
+
# end
|
16
|
+
class Pacstream
|
17
|
+
|
18
|
+
FILE_EXTENSIONS = { :orders => "ORD" }
|
19
|
+
|
20
|
+
# Iterate over each order waiting on the pacstream server, returning
|
21
|
+
# each file as a string
|
22
|
+
#
|
23
|
+
# RBook::Pacstream.get(:orders, :username => "myusername", :password => "mypass") do |order|
|
24
|
+
# puts order
|
25
|
+
# end
|
26
|
+
def self.get(type = :orders, *args, &block)
|
27
|
+
if args[0][:username].nil? && args[0][:password].nil?
|
28
|
+
raise ArgumentError, 'username and password must be specified'
|
29
|
+
end
|
30
|
+
|
31
|
+
unless FILE_EXTENSIONS.include?(type)
|
32
|
+
raise ArgumentError, 'unrecognised type'
|
33
|
+
end
|
34
|
+
|
35
|
+
server = args[0][:servername] || "pacstream.tedis.com.au"
|
36
|
+
|
37
|
+
begin
|
38
|
+
Net::FTP.open(server) do |ftp|
|
39
|
+
ftp.login(args[0][:username], args[0][:password])
|
40
|
+
ftp.chdir("outgoing/")
|
41
|
+
ftp.nlst.each do |file|
|
42
|
+
if file.match(/.*\.#{FILE_EXTENSIONS[type]}$/)
|
43
|
+
content = ""
|
44
|
+
ftp.gettextfile(file) {|line| content << line << "\n"}
|
45
|
+
yield content
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
rescue Net::FTPPermError
|
50
|
+
raise "Error loging onto pactream server"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rbook
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2006-10-
|
6
|
+
version: "0.3"
|
7
|
+
date: 2006-10-25 00:00:00 +10:00
|
8
8
|
summary: A collection of classes and modules for working with bibliographic data
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -33,6 +33,7 @@ files:
|
|
33
33
|
- examples/onix
|
34
34
|
- examples/titlepage.rb
|
35
35
|
- examples/gbip.rb
|
36
|
+
- examples/pacstream.rb
|
36
37
|
- examples/www/list.rb
|
37
38
|
- examples/www/find_cover_from_amazon.rb
|
38
39
|
- examples/www/find_url_from_rainbow.rb
|
@@ -50,6 +51,7 @@ files:
|
|
50
51
|
- lib/rbook/isbn.rb
|
51
52
|
- lib/rbook/bisac
|
52
53
|
- lib/rbook/gbip
|
54
|
+
- lib/rbook/pacstream.rb
|
53
55
|
- lib/rbook/gbip.rb
|
54
56
|
- lib/rbook/www/wiley_us_scraper.rb
|
55
57
|
- lib/rbook/www/hha_scraper.rb
|