rbook-gbip 0.5 → 0.6

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/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rake/testtask'
5
5
  require "rake/gempackagetask"
6
6
  require 'spec/rake/spectask'
7
7
 
8
- PKG_VERSION = "0.5"
8
+ PKG_VERSION = "0.6"
9
9
  PKG_NAME = "rbook-gbip"
10
10
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
11
11
  RUBYFORGE_PROJECT = 'rbook'
@@ -1,5 +1,6 @@
1
1
  require 'socket'
2
2
  require 'enumerator'
3
+ require 'timeout'
3
4
 
4
5
  module RBook
5
6
 
@@ -24,15 +25,18 @@ module RBook
24
25
 
25
26
  # search for the specified ISBN on globalbooksinprint.com.
26
27
  # Accepts both ISBN10 and ISBN13's.
28
+ #
29
+ # Supported options:
30
+ # :markets => only search the specified markets. comma sperated list
31
+ # :timeout => amount of time in seconds to wait for a reponse from the server before timing out. Defaults to 10.
27
32
  def find(type, isbn, options = {})
28
33
  case type
29
34
  when :first then default_return = nil
30
35
  when :all then default_return = []
31
36
  else raise ArgumentError, 'type must by :first or :all'
32
37
  end
33
- #unless [:first, :all].include?(type)
34
- # raise ArgumentError, 'type must by :first or :all'
35
- #end
38
+
39
+ options = {:timeout => 10}.merge(options)
36
40
 
37
41
  # global only accepts ISBNs as 10 digits at this stage
38
42
  isbn = RBook::ISBN.convert_to_isbn10(isbn.to_s)
@@ -61,7 +65,8 @@ module RBook
61
65
 
62
66
  gbip = @socket_class.new(POS_SERVER, POS_PORT)
63
67
  gbip.print request_string
64
- response = gbip.gets(nil).split("#")
68
+ response = Timeout::timeout(options[:timeout]) { gbip.gets(nil) }
69
+ response = response.split("#")
65
70
  gbip.close
66
71
 
67
72
  header = nil
@@ -2,6 +2,7 @@ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
2
2
 
3
3
  require 'rbook/gbip'
4
4
  require File.dirname(__FILE__) + "/mock_tcpsocket"
5
+ require File.dirname(__FILE__) + "/timeout_tcpsocket"
5
6
 
6
7
  include RBook
7
8
 
@@ -71,10 +72,15 @@ context "A new POS object" do
71
72
 
72
73
  specify "should perform a successful query if the ISBN is provided as a number" do
73
74
  pos = GBIP::POS.new(@valid_username, @valid_password, MockTCPSocket)
74
- result = pos.find(:first, 1741146712)
75
+ result = pos.find(:first, @valid_isbn13)
75
76
  result.should be_a_kind_of(RBook::GBIP::Title)
76
77
  end
77
78
 
79
+ specify "should raise an exception if no reponse is received in a certain amount of time" do
80
+ pos = GBIP::POS.new(@valid_username, @valid_password, TimeoutTCPSocket)
81
+ lambda { pos.find(:first, @valid_isbn13, :timeout => 2) }.should raise_error(Timeout::Error)
82
+ end
83
+
78
84
  #####################
79
85
  # :all searches
80
86
  #####################
@@ -0,0 +1,19 @@
1
+ class TimeoutTCPSocket
2
+
3
+ def initialize(host,port)
4
+ # do nothing
5
+ end
6
+
7
+ def print(query)
8
+ # do nothing
9
+ end
10
+
11
+ def gets(placeholder)
12
+ sleep 5
13
+ ""
14
+ end
15
+
16
+ def close
17
+ # do nothing
18
+ end
19
+ end
metadata CHANGED
@@ -1,33 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: rbook-gbip
5
3
  version: !ruby/object:Gem::Version
6
- version: "0.5"
7
- date: 2007-07-03 00:00:00 +10:00
8
- summary: A library for access the globalbooksinprint.com API
9
- require_paths:
10
- - lib
11
- email: jimmy@deefa.com
12
- homepage: http://rbook.rubyforge.org/
13
- rubyforge_project: rbook
14
- description: gbip is a small library to interact with the globalbooksinprint.com API. The API is based on raw TCP sockets.
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.6"
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-06-06 00:00:00 +10: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: gbip is a small library to interact with the globalbooksinprint.com API. The API is based on raw TCP sockets.
25
+ email: jimmy@deefa.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README
32
+ - COPYING
33
+ - LICENSE
31
34
  files:
32
35
  - examples/gbip.rb
33
36
  - lib/rbook
@@ -44,36 +47,42 @@ files:
44
47
  - specs/responses/no_warehouses.txt
45
48
  - specs/mock_tcpsocket.rb
46
49
  - specs/pos_class_spec.rb
50
+ - specs/timeout_tcpsocket.rb
47
51
  - Rakefile
48
52
  - README
49
53
  - COPYING
50
54
  - LICENSE
51
- test_files:
52
- - specs/mock_tcpsocket.rb
53
- - specs/pos_class_spec.rb
55
+ has_rdoc: true
56
+ homepage: http://rbook.rubyforge.org/
57
+ post_install_message:
54
58
  rdoc_options:
55
59
  - --title
56
60
  - gbip Documentation
57
61
  - --main
58
62
  - README
59
63
  - -q
60
- extra_rdoc_files:
61
- - README
62
- - COPYING
63
- - LICENSE
64
- executables: []
65
-
66
- extensions: []
67
-
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
68
78
  requirements: []
69
79
 
70
- dependencies:
71
- - !ruby/object:Gem::Dependency
72
- name: rbook-isbn
73
- version_requirement:
74
- version_requirements: !ruby/object:Gem::Version::Requirement
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- version: "1.0"
79
- version:
80
+ rubyforge_project: rbook
81
+ rubygems_version: 1.1.1
82
+ signing_key:
83
+ specification_version: 2
84
+ summary: A library for access the globalbooksinprint.com API
85
+ test_files:
86
+ - specs/mock_tcpsocket.rb
87
+ - specs/pos_class_spec.rb
88
+ - specs/timeout_tcpsocket.rb