gbip 0.7 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -19,7 +19,7 @@ puts gbip.find(:first, "0732282721").to_yaml
19
19
 
20
20
  = Disclaimer
21
21
 
22
- I am in no way affiliated with Bowker, ther operators of globalbooksinprint.com.
22
+ I am in no way affiliated with Bowker, the operators of globalbooksinprint.com.
23
23
  Please contact them with questions about the service and how to obtain an account.
24
24
 
25
25
  = Contact
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.7"
8
+ PKG_VERSION = "0.7.1"
9
9
  PKG_NAME = "gbip"
10
10
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
11
11
  RUBYFORGE_PROJECT = 'rbook'
@@ -23,7 +23,7 @@ module GBIP
23
23
 
24
24
  # search for the specified ISBN on globalbooksinprint.com.
25
25
  # Accepts both ISBN10 and ISBN13's.
26
- #
26
+ #
27
27
  # Supported options:
28
28
  # :markets => only search the specified markets. comma sperated list
29
29
  # :timeout => amount of time in seconds to wait for a reponse from the server before timing out. Defaults to 10.
@@ -36,8 +36,7 @@ module GBIP
36
36
 
37
37
  options = {:timeout => 10}.merge(options)
38
38
 
39
- # global only accepts ISBNs as 10 digits at this stage
40
- isbn = RBook::ISBN.convert_to_isbn10(isbn.to_s)
39
+ isbn = RBook::ISBN.convert_to_isbn13(isbn.to_s) || isbn.to_s
41
40
  return default_return if isbn.nil?
42
41
 
43
42
  request_format = "POS"
@@ -61,25 +60,34 @@ module GBIP
61
60
  request_string << "#{version}\t#{supplier}\t#{request}\t#{filters}\t#{records}\t#{sort_order}\t"
62
61
  request_string << "#{markets}\t"
63
62
 
64
- gbip = @socket_class.new(POS_SERVER, POS_PORT)
65
- gbip.print request_string
66
- response = Timeout::timeout(options[:timeout]) { gbip.gets(nil) }
67
- response = response.split("#")
68
- gbip.close
69
-
70
- header = nil
71
- titles_arr = []
72
- response.each do |arr|
73
- if header.nil?
74
- header = arr.split("\t")
63
+ sock = @socket_class.new(POS_SERVER, POS_PORT)
64
+ sock.print request_string
65
+ response = Timeout::timeout(options[:timeout]) { sock.gets(nil) }
66
+ sock.close
67
+
68
+ # split the response into header/body
69
+ idx = response.index("#")
70
+ if idx.nil?
71
+ header = response.split("\t")
72
+ else
73
+ header = response[0, idx - 1]
74
+ body = response[idx, response.size - idx].split("\t")
75
+ body.shift
76
+ end
77
+
78
+ titles_arr = [[]]
79
+ body.each do |element|
80
+ if element == "#" && titles_arr.last.size > 15
81
+ titles_arr << []
75
82
  else
76
- titles_arr << arr.split("\t")
77
- titles_arr[-1] = titles_arr.last[1,titles_arr.last.size-1]
83
+ titles_arr.last << element
78
84
  end
85
+ #titles_arr << arr.split("\t")
86
+ #titles_arr[-1] = titles_arr.last[1,titles_arr.last.size-1]
79
87
  end
80
88
 
81
89
  # raise an exception if incorrect login details were provided
82
- if header.first.eql?("66")
90
+ if header.first.eql?("66")
83
91
  raise GBIP::InvalidLoginError, "Invalid username or password"
84
92
  end
85
93
 
@@ -8,7 +8,7 @@ class MockTCPSocket
8
8
  query = query.to_s.split("\t")
9
9
  @username = query[3]
10
10
  @password = query[4]
11
- m, @isbn = *query[7].match(/bn=(\d\d\d\d\d\d\d\d\d[\dXx])/)
11
+ m, @isbn = *query[7].match(/bn=(\d\d\d\d\d\d\d\d\d\d\d\d\d)/)
12
12
  end
13
13
 
14
14
  def gets(placeholder)
@@ -19,21 +19,23 @@ class MockTCPSocket
19
19
  end
20
20
 
21
21
  # if the requested isbn isn't an isbn10
22
- unless RBook::ISBN.valid_isbn10?(@isbn)
22
+ unless RBook::ISBN.valid_isbn13?(@isbn)
23
23
  return File.read(File.dirname(__FILE__) + "/responses/no_result.txt").strip
24
24
  end
25
25
 
26
26
  # if the isbn10 is one we have available
27
- if @isbn.eql?("1741146712")
27
+ if @isbn.eql?("9781741146714")
28
28
  return File.read(File.dirname(__FILE__) + "/responses/single_result.txt").strip
29
- elsif @isbn.eql?("0732282721")
29
+ elsif @isbn.eql?("9781590599358")
30
+ return File.read(File.dirname(__FILE__) + "/responses/single_result2.txt").strip
31
+ elsif @isbn.eql?("9780732282721")
30
32
  return File.read(File.dirname(__FILE__) + "/responses/no_warehouses.txt").strip
31
33
  else
32
34
  return File.read(File.dirname(__FILE__) + "/responses/no_result.txt").strip
33
35
  end
34
36
  @username = nil
35
37
  @password = nil
36
- @isbn = nil
38
+ isbn = nil
37
39
  end
38
40
 
39
41
  def close
@@ -12,6 +12,7 @@ context "A new POS object" do
12
12
  @invalid_password = "word"
13
13
  @valid_isbn10 = "1741146712"
14
14
  @valid_isbn13 = "9781741146714"
15
+ @valid_isbn13_hash = "9781590599358"
15
16
  @notfound_isbn10 = "0571228526"
16
17
  @notfound_isbn13 = "9780571228522"
17
18
  @valid_isbn10_with_no_warehouses = "0732282721"
@@ -37,6 +38,20 @@ context "A new POS object" do
37
38
  result.should be_a_kind_of(GBIP::Title)
38
39
  end
39
40
 
41
+ specify "should return a GBIP::Title object when the response contains an extra #" do
42
+ pos = GBIP::POS.new(@valid_username, @valid_password, MockTCPSocket)
43
+ result = pos.find(:first, @valid_isbn13_hash)
44
+ result.should be_a_kind_of(GBIP::Title)
45
+ result.title.should eql("Pro EDI in BizTalk Server 2006 R2:Electronic Document Interchange Solutions")
46
+ end
47
+
48
+ specify "should return a GBIP::Title object when querying for a single valid ISBN10 that has no warehouse data" do
49
+ pos = GBIP::POS.new(@valid_username, @valid_password, MockTCPSocket)
50
+ result = pos.find(:first, @valid_isbn10_with_no_warehouses)
51
+ result.should be_a_kind_of(GBIP::Title)
52
+ result.warehouses.should be_empty
53
+ end
54
+
40
55
  specify "should return a GBIP::Title object when querying for a single valid ISBN10 that has no warehouse data" do
41
56
  pos = GBIP::POS.new(@valid_username, @valid_password, MockTCPSocket)
42
57
  result = pos.find(:first, @valid_isbn10_with_no_warehouses)
@@ -0,0 +1 @@
1
+ 3 rainbowbook 2 # 66797534 1 GBR Pro EDI in BizTalk Server 2006 R2:Electronic Document Interchange Solutions 978-1-59059-935-8 Trade Paper Active Record Deshev, Hristo Apress L. P. 112007 33.99 UNITED STATES 152887 # DATA TRANSMISSION SYSTEMS COMPUTERS / Data Transmission Systems / General COMPUTER NETWORKING & COMMUNICATIONS BLK,BNT,CLD,ING,POL 8 Blackwell, Lake Oswego, OR In stock 0 10/07/2008 Baker & Taylor Books, Bridgewater, NJ 0 10/12/2008 Baker & Taylor Books, Commerce, GA 5 0 10/12/2008 Baker & Taylor Books, Momence, IL 2 4 10/12/2008 Baker & Taylor Books, Reno, NV 0 10/12/2008 Cromland, Allentown, PA Available for order 0 10/10/2008 Ingram Book Company, La Vergne, TN Available for order 0 10/12/2008 Powells.com, Portland, OR In stock 0 02/01/2008
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gbip
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.7"
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Healy
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-10-02 00:00:00 +10:00
12
+ date: 2008-10-14 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -47,6 +47,7 @@ files:
47
47
  - specs/responses/no_result.txt
48
48
  - specs/responses/no_warehouses.txt
49
49
  - specs/responses/single_result.txt
50
+ - specs/responses/single_result2.txt
50
51
  - specs/timeout_tcpsocket.rb
51
52
  - Rakefile
52
53
  - CHANGELOG