rbook-pacstream 0.7.1 → 0.8

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.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ v0.8
2
+ - Added support for listing files on the pacstream server without actually downloading them
3
+
1
4
  v0.7.1
2
5
  - wrap the quit call in a rescue block. Sometimes the remote server closes the connection so quickly, Net::FTP freaks out when the socket closes, and we don't really care.
3
6
 
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require 'rake/testtask'
6
6
  require "rake/gempackagetask"
7
7
  require 'spec/rake/spectask'
8
8
 
9
- PKG_VERSION = "0.7.1"
9
+ PKG_VERSION = "0.8"
10
10
  PKG_NAME = "rbook-pacstream"
11
11
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
12
12
  RUBYFORGE_PROJECT = 'rbook'
@@ -0,0 +1,15 @@
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.open(:username => "myusername", :password => "mypass") do |pac|
11
+ pac.get(:orders) do |order|
12
+ File.open("#{counter.to_s}.ord", "w") { |f| f.puts order }
13
+ counter += 1
14
+ end
15
+ end
@@ -7,7 +7,6 @@ require File.dirname(__FILE__) + '/../lib/rbook/pacstream'
7
7
 
8
8
  counter = 0
9
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
10
+ RBook::Pacstream.open(:username => "username", :password => "pass") do |pac|
11
+ puts pac.list(:orders).inspect
13
12
  end
@@ -48,7 +48,7 @@ module RBook
48
48
  raise ArgumentError, 'username and password must be specified'
49
49
  end
50
50
 
51
- @server = args[0][:servername].to_s || "pacstream.tedis.com.au"
51
+ @server = (args[0][:servername] || "pacstream.tedis.com.au").to_s
52
52
  @username = args[0][:username].to_s
53
53
  @password = args[0][:password].to_s
54
54
  end
@@ -85,6 +85,30 @@ module RBook
85
85
  @ftp.chdir("..")
86
86
  end
87
87
 
88
+ # list all documents of a particular type available on the pacstream server
89
+ #
90
+ # pac.list(:orders) do |order|
91
+ # puts order
92
+ # end
93
+ def list(type, &block)
94
+ raise PacstreamCommandError, "No current session open" unless @ftp
95
+ raise ArgumentError, 'unrecognised type' unless FILE_EXTENSIONS.include?(type.to_sym)
96
+
97
+ ret = []
98
+
99
+ # determine the filename pattern we're searching for
100
+ file_regexp = Regexp.new(".*\.#{FILE_EXTENSIONS[type.to_sym]}$", Regexp::IGNORECASE)
101
+ @ftp.chdir("outgoing/")
102
+
103
+ # loop over each file in the outgoing dir and check if it matches the file type we're after
104
+ @ftp.nlst.each do |file|
105
+ ret << file if file.match(file_regexp)
106
+ end
107
+
108
+ @ftp.chdir("..")
109
+ return ret
110
+ end
111
+
88
112
  # logs into to the pacstream server. Can raise several exceptions
89
113
  # RBook::PacstreamConnectionError - Can't connect to server
90
114
  # RBook::PacstreamAuthError - Invalid username or password
@@ -76,6 +76,24 @@ context "The pacstream class" do
76
76
  ftp.should have_received(:getbinaryfile).once
77
77
  end
78
78
 
79
+ specify "should return an array of waiting files on request, and not attempt to download them" do
80
+ # prevent a real ftp session from being opened. If the lib attempts to open
81
+ # a connection, just return a stubbed class
82
+ # this stub will allow the user to call chdir, and pretends that there are two orders available
83
+ # for download
84
+ ftp = Net::FTP.stub_instance(:login => true, :chdir => true, :nlst => ["1.ORD","2.ORD"], :getbinaryfile => true, :quit => true)
85
+ Net::FTP.stub_method(:new => ftp, :open => ftp)
86
+
87
+ pac = RBook::Pacstream.new(@options)
88
+ pac.login
89
+ pac.list(:orders).should eql(["1.ORD","2.ORD"])
90
+ pac.quit
91
+
92
+ ftp.should have_received(:chdir).twice
93
+ ftp.should have_received(:nlst).once.without_args
94
+ ftp.should_not have_received(:getbinaryfile)
95
+ end
96
+
79
97
  specify "should return the contents of a POA when looping over all available poa's" do
80
98
  # prevent a real ftp session from being opened. If the lib attempts to open
81
99
  # a connection, just return a stubbed class
metadata CHANGED
@@ -1,35 +1,40 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: rbook-pacstream
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.7.1
7
- date: 2007-10-24 00:00:00 +10:00
8
- summary: A library for interaction with the PACSTREAM service
9
- require_paths:
10
- - lib
11
- email: jimmy@deefa.com
12
- homepage: http://rbook.rubyforge.org/
13
- rubyforge_project: rbook
14
- description: This library is designed to assist with using the PACSTREAM electronic ordering service used by the book industry in Australia.
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:
4
+ version: "0.8"
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - James Healy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-03-26 00:00:00 +11:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rbook-isbn
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "1.0"
23
+ version:
24
+ description: This library is designed to assist with using the PACSTREAM electronic ordering service used by the book industry in Australia.
25
+ email: jimmy@deefa.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README
32
+ - COPYING
33
+ - LICENSE
34
+ - CHANGELOG
31
35
  files:
32
- - examples/pacstream.rb
36
+ - examples/list.rb
37
+ - examples/get.rb
33
38
  - lib/rbook
34
39
  - lib/rbook/pacstream.rb
35
40
  - specs/pacstream_spec.rb
@@ -38,32 +43,35 @@ files:
38
43
  - COPYING
39
44
  - README
40
45
  - LICENSE
41
- test_files:
42
- - specs/pacstream_spec.rb
46
+ has_rdoc: true
47
+ homepage: http://rbook.rubyforge.org/
48
+ post_install_message:
43
49
  rdoc_options:
44
50
  - --title
45
51
  - pacstream Documentation
46
52
  - --main
47
53
  - README
48
54
  - -q
49
- extra_rdoc_files:
50
- - README
51
- - COPYING
52
- - LICENSE
53
- - CHANGELOG
54
- executables: []
55
-
56
- extensions: []
57
-
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
58
69
  requirements: []
59
70
 
60
- dependencies:
61
- - !ruby/object:Gem::Dependency
62
- name: rbook-isbn
63
- version_requirement:
64
- version_requirements: !ruby/object:Gem::Version::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: "1.0"
69
- version:
71
+ rubyforge_project: rbook
72
+ rubygems_version: 1.0.1
73
+ signing_key:
74
+ specification_version: 2
75
+ summary: A library for interaction with the PACSTREAM service
76
+ test_files:
77
+ - specs/pacstream_spec.rb