titlepage 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Rakefile +2 -2
  2. data/lib/titlepage.rb +2 -11
  3. data/lib/titlepage/utils.rb +10 -69
  4. metadata +9 -9
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 = "1.2.1"
9
+ PKG_VERSION = "1.3.0"
10
10
  PKG_NAME = "titlepage"
11
11
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
12
12
  RUBYFORGE_PROJECT = 'rbook'
@@ -71,7 +71,7 @@ spec = Gem::Specification.new do |spec|
71
71
  spec.rdoc_options << '--title' << 'titlepage Documentation' << '--main' << 'README' << '-q'
72
72
  spec.add_dependency('rbook-isbn', '>= 1.0')
73
73
  spec.add_dependency('andand', '1.3.1')
74
- spec.add_dependency('troelskn-handsoap', '0.2.7')
74
+ spec.add_dependency('handsoap', '>= 1.0')
75
75
  spec.author = "James Healy"
76
76
  spec.email = "jimmy@deefa.com"
77
77
  spec.rubyforge_project = "rbook"
@@ -1,18 +1,9 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'bigdecimal'
4
- require 'net/http'
5
- require 'rubygems'
6
- gem 'troelskn-handsoap', '0.2.7'
7
- gem 'andand', '1.3.1'
3
+ require "bigdecimal"
8
4
  require "handsoap"
9
5
  require "andand"
10
-
11
- require 'rbook/isbn'
12
-
13
- if RUBY_VERSION < "1.9"
14
- require 'iconv'
15
- end
6
+ require "rbook/isbn"
16
7
 
17
8
  # a convenience module for accessing the SOAP API for http://www.titlepage.com.
18
9
  # Uses boilerplate code generated by soap4r.
@@ -10,32 +10,6 @@ module TitlePage
10
10
 
11
11
  class Response
12
12
 
13
- private
14
-
15
- # ensure all specified attributes are encoded as UTF-8. At this stage the
16
- # Titlepage API is encoded in ISO-8859-1, but this *should* continue to
17
- # work if they change that.
18
- #
19
- def normalise_attrib_encodings!(current_enc, attributes)
20
- return if current_enc.downcase == "utf-8"
21
-
22
- if RUBY_VERSION < "1.9"
23
- attributes.each do |attrib|
24
- if self.__send__(attrib)
25
- new_val = Iconv.conv("utf-8",current_enc, self.__send__(attrib))
26
- self.__send__("#{attrib}=", new_val)
27
- end
28
- end
29
- else
30
- current_enc = Encoding.find(current_enc)
31
- attributes.each do |attrib|
32
- if self.__send__(attrib)
33
- self.__send__(attrib).force_encoding(current_enc)
34
- self.__send__(attrib).encode!("utf-8")
35
- end
36
- end
37
- end
38
- end
39
13
  end
40
14
 
41
15
  class ProductIdentifier < TitlePage::Response
@@ -55,7 +29,6 @@ module TitlePage
55
29
  id = self.new
56
30
  id.product_id_type = node.xpath("//item/ProductIDType/text()").to_s
57
31
  id.id_value = node.xpath("//item/IDValue/text()").to_s
58
- id.normalise_encodings!(node.document.encoding)
59
32
  id
60
33
  end
61
34
 
@@ -63,7 +36,6 @@ module TitlePage
63
36
  #
64
37
  def normalise_encodings!(current_enc)
65
38
  attribs = [:product_id_type, :id_value]
66
- normalise_attrib_encodings!(current_enc, attribs)
67
39
  end
68
40
  end
69
41
 
@@ -89,18 +61,9 @@ module TitlePage
89
61
  title.title_without_prefix = node.xpath("//Title/TitleWithoutPrefix/text()").first.andand.to_s
90
62
  title.subtitle = node.xpath("//Title/Subtitle/text()").first.andand.to_s
91
63
 
92
- # normalise encodings to utf-8
93
- title.normalise_encodings!(node.document.encoding)
94
64
  title
95
65
  end
96
66
 
97
- # ensure all string attributes are UTF-8 encoded
98
- #
99
- def normalise_encodings!(current_enc)
100
- attribs = [:title_type, :title_text, :title_prefix, :title_without_prefix, :subtitle]
101
- normalise_attrib_encodings!(current_enc, attribs)
102
- end
103
-
104
67
  end
105
68
 
106
69
  class Contributor < TitlePage::Response
@@ -129,17 +92,9 @@ module TitlePage
129
92
  contrib.person_name_inverted = node.xpath("//item/PersonNameInverted/text()").first.andand.to_s
130
93
  contrib.titles_before_names = node.xpath("//item/TitlesBeforeNames/text()").first.andand.to_s
131
94
  contrib.key_names = node.xpath("//item/KeyNames/text()").first.andand.to_s
132
- contrib.normalise_encodings!(node.document.encoding)
133
95
  contrib
134
96
  end
135
97
 
136
- # ensure all string attributes are UTF-8 encoded
137
- #
138
- def normalise_encodings!(current_enc)
139
- attribs = [:contributor_role, :person_name, :person_name_inverted, :titles_before_names, :key_names]
140
- normalise_attrib_encodings!(current_enc, attribs)
141
- end
142
-
143
98
  end
144
99
 
145
100
  class Stock < TitlePage::Response
@@ -157,16 +112,9 @@ module TitlePage
157
112
  stock = self.new
158
113
  stock.on_hand = node.xpath("//Stock/OnHand/text()").first.andand.to_s
159
114
  stock.on_order = node.xpath("//Stock/OnOrder/text()").first.andand.to_s
160
- stock.normalise_encodings!(node.document.encoding)
161
115
  stock
162
116
  end
163
117
 
164
- # ensure all string attributes are UTF-8 encoded
165
- #
166
- def normalise_encodings!(current_enc)
167
- attribs = [:on_hand, :on_order]
168
- normalise_attrib_encodings!(current_enc, attribs)
169
- end
170
118
  end
171
119
 
172
120
  class Price < TitlePage::Response
@@ -184,16 +132,9 @@ module TitlePage
184
132
  price.price_type_code = node.xpath("//Price/PriceTypeCode/text()").first.andand.to_s
185
133
  val = node.xpath("//Price/PriceAmount/text()").first.andand.to_s
186
134
  price.price_amount = BigDecimal.new(val) if val.size > 0
187
- price.normalise_encodings!(node.document.encoding)
188
135
  price
189
136
  end
190
137
 
191
- # ensure all string attributes are UTF-8 encoded
192
- #
193
- def normalise_encodings!(current_enc)
194
- attribs = [:price_type_code]
195
- normalise_attrib_encodings!(current_enc, attribs)
196
- end
197
138
  end
198
139
 
199
140
  class SupplyDetail < TitlePage::Response
@@ -230,16 +171,9 @@ module TitlePage
230
171
  sd.stock = TitlePage::Stock.from_xml(node.xpath("//SupplyDetail/Stock").first)
231
172
  sd.pack_quantity = node.xpath("//SupplyDetail/PackQuantity/text()").first.andand.to_s.andand.to_i
232
173
  sd.price = TitlePage::Price.from_xml(node.xpath("//SupplyDetail/Price").first)
233
- sd.normalise_encodings!(node.document.encoding)
234
174
  sd
235
175
  end
236
176
 
237
- # ensure all string attributes are UTF-8 encoded
238
- #
239
- def normalise_encodings!(current_enc)
240
- attribs = [:supplier_name, :supplier_role, :product_availability, :expected_ship_date]
241
- normalise_attrib_encodings!(current_enc, attribs)
242
- end
243
177
  end
244
178
 
245
179
  class Product
@@ -274,12 +208,19 @@ module TitlePage
274
208
  #
275
209
  def to_hash
276
210
  {
277
- :supplier => self.supply_detail.supplier_name,
278
- :title => self.title.title_text,
279
211
  :ean => self.product_identifiers.first.id_value,
212
+ :title => self.title.title_text,
213
+ :subtitle => self.title.subtitle,
214
+ :contributors => self.contributors.collect { |c| c.person_name_inverted },
215
+ :supplier => self.supply_detail.supplier_name,
216
+ :supplier_role => self.supply_detail.supplier_role,
280
217
  :price => self.supply_detail.price.price_amount.to_s("F").to_f,
281
218
  :availability => self.supply_detail.product_availability,
282
- :contributors => self.contributors.collect { |c| c.person_name_inverted }
219
+ :on_hand => self.supply_detail.stock.on_hand,
220
+ :on_order => self.supply_detail.stock.on_order,
221
+ :expected_shop_date => self.supply_detail.expected_ship_date,
222
+ :pack_quantity => self.supply_detail.pack_quantity,
223
+
283
224
  }
284
225
  end
285
226
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: titlepage
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
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: 2009-10-12 00:00:00 +11:00
12
+ date: 2009-11-14 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -33,14 +33,14 @@ dependencies:
33
33
  version: 1.3.1
34
34
  version:
35
35
  - !ruby/object:Gem::Dependency
36
- name: troelskn-handsoap
36
+ name: handsoap
37
37
  type: :runtime
38
38
  version_requirement:
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
- - - "="
41
+ - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 0.2.7
43
+ version: "1.0"
44
44
  version:
45
45
  description: This library is designed to assist with using the titlepage.com SOAP API.
46
46
  email: jimmy@deefa.com
@@ -53,13 +53,13 @@ extra_rdoc_files:
53
53
  - COPYING
54
54
  - LICENSE
55
55
  files:
56
- - examples/titlepage.rb
57
56
  - examples/titlepage_www.rb
58
- - lib/titlepage/client.rb
59
- - lib/titlepage/driver.rb
57
+ - examples/titlepage.rb
58
+ - lib/titlepage.rb
60
59
  - lib/titlepage/utils.rb
60
+ - lib/titlepage/client.rb
61
61
  - lib/titlepage/wwwclient.rb
62
- - lib/titlepage.rb
62
+ - lib/titlepage/driver.rb
63
63
  - Rakefile
64
64
  - README
65
65
  - COPYING