titlepage 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +340 -0
- data/LICENSE +13 -0
- data/README +17 -0
- data/Rakefile +84 -0
- data/examples/titlepage.rb +15 -0
- data/examples/titlepage_www.rb +11 -0
- data/lib/titlepage/client.rb +88 -0
- data/lib/titlepage/mapping_registry.rb +201 -0
- data/lib/titlepage/titlepage_driver.rb +87 -0
- data/lib/titlepage/titlepage_utils.rb +293 -0
- data/lib/titlepage/wwwclient.rb +102 -0
- data/lib/titlepage.rb +47 -0
- metadata +80 -0
@@ -0,0 +1,201 @@
|
|
1
|
+
require 'soap/mapping'
|
2
|
+
|
3
|
+
module TitlePage
|
4
|
+
|
5
|
+
module DefaultMappingRegistry
|
6
|
+
EncodedRegistry = ::SOAP::Mapping::EncodedRegistry.new
|
7
|
+
LiteralRegistry = ::SOAP::Mapping::LiteralRegistry.new
|
8
|
+
NsTitleQuery = "urn:TitleQuery"
|
9
|
+
|
10
|
+
EncodedRegistry.register(
|
11
|
+
:class => TitlePage::ProductIdentifier,
|
12
|
+
:schema_type => XSD::QName.new(NsTitleQuery, "ProductIdentifier"),
|
13
|
+
:schema_element => [
|
14
|
+
["productIDType", ["SOAP::SOAPString", XSD::QName.new(nil, "ProductIDType")]],
|
15
|
+
["iDValue", ["SOAP::SOAPString", XSD::QName.new(nil, "IDValue")]]
|
16
|
+
]
|
17
|
+
)
|
18
|
+
|
19
|
+
EncodedRegistry.register(
|
20
|
+
:class => TitlePage::Title,
|
21
|
+
:schema_type => XSD::QName.new(NsTitleQuery, "Title"),
|
22
|
+
:schema_element => [
|
23
|
+
["titleType", ["SOAP::SOAPString", XSD::QName.new(nil, "TitleType")]],
|
24
|
+
["titleText", ["SOAP::SOAPString", XSD::QName.new(nil, "TitleText")]],
|
25
|
+
["titlePrefix", ["SOAP::SOAPString", XSD::QName.new(nil, "TitlePrefix")]],
|
26
|
+
["titleWithoutPrefix", ["SOAP::SOAPString", XSD::QName.new(nil, "TitleWithoutPrefix")]],
|
27
|
+
["subtitle", ["SOAP::SOAPString", XSD::QName.new(nil, "Subtitle")]]
|
28
|
+
]
|
29
|
+
)
|
30
|
+
|
31
|
+
EncodedRegistry.register(
|
32
|
+
:class => TitlePage::Contributor,
|
33
|
+
:schema_type => XSD::QName.new(NsTitleQuery, "Contributor"),
|
34
|
+
:schema_element => [
|
35
|
+
["sequenceNumber", ["SOAP::SOAPInteger", XSD::QName.new(nil, "SequenceNumber")]],
|
36
|
+
["contributorRole", ["SOAP::SOAPString", XSD::QName.new(nil, "ContributorRole")]],
|
37
|
+
["personName", ["SOAP::SOAPString", XSD::QName.new(nil, "PersonName")]],
|
38
|
+
["personNameInverted", ["SOAP::SOAPString", XSD::QName.new(nil, "PersonNameInverted")]],
|
39
|
+
["titlesBeforeNames", ["SOAP::SOAPString", XSD::QName.new(nil, "TitlesBeforeNames")]],
|
40
|
+
["keyNames", ["SOAP::SOAPString", XSD::QName.new(nil, "KeyNames")]]
|
41
|
+
]
|
42
|
+
)
|
43
|
+
|
44
|
+
EncodedRegistry.register(
|
45
|
+
:class => TitlePage::Stock,
|
46
|
+
:schema_type => XSD::QName.new(NsTitleQuery, "Stock"),
|
47
|
+
:schema_element => [
|
48
|
+
["onHand", ["SOAP::SOAPString", XSD::QName.new(nil, "OnHand")]],
|
49
|
+
["onOrder", ["SOAP::SOAPString", XSD::QName.new(nil, "OnOrder")]]
|
50
|
+
]
|
51
|
+
)
|
52
|
+
|
53
|
+
EncodedRegistry.register(
|
54
|
+
:class => TitlePage::Price,
|
55
|
+
:schema_type => XSD::QName.new(NsTitleQuery, "Price"),
|
56
|
+
:schema_element => [
|
57
|
+
["priceTypeCode", ["SOAP::SOAPString", XSD::QName.new(nil, "PriceTypeCode")]],
|
58
|
+
["priceAmount", ["SOAP::SOAPDecimal", XSD::QName.new(nil, "PriceAmount")]]
|
59
|
+
]
|
60
|
+
)
|
61
|
+
|
62
|
+
EncodedRegistry.register(
|
63
|
+
:class => TitlePage::SupplyDetail,
|
64
|
+
:schema_type => XSD::QName.new(NsTitleQuery, "SupplyDetail"),
|
65
|
+
:schema_element => [
|
66
|
+
["supplierName", ["SOAP::SOAPString", XSD::QName.new(nil, "SupplierName")]],
|
67
|
+
["supplierRole", ["SOAP::SOAPString", XSD::QName.new(nil, "SupplierRole")]],
|
68
|
+
["productAvailability", ["SOAP::SOAPString", XSD::QName.new(nil, "ProductAvailability")]],
|
69
|
+
["expectedShipDate", ["SOAP::SOAPString", XSD::QName.new(nil, "ExpectedShipDate")]],
|
70
|
+
["stock", ["TitlePage::Stock", XSD::QName.new(nil, "Stock")]],
|
71
|
+
["packQuantity", ["SOAP::SOAPInteger", XSD::QName.new(nil, "PackQuantity")]],
|
72
|
+
["price", ["TitlePage::Price", XSD::QName.new(nil, "Price")]]
|
73
|
+
]
|
74
|
+
)
|
75
|
+
|
76
|
+
EncodedRegistry.set(
|
77
|
+
TitlePage::ArrayOfContributor,
|
78
|
+
::SOAP::SOAPArray,
|
79
|
+
::SOAP::Mapping::EncodedRegistry::TypedArrayFactory,
|
80
|
+
{ :type => XSD::QName.new(NsTitleQuery, "Contributor") }
|
81
|
+
)
|
82
|
+
|
83
|
+
EncodedRegistry.set(
|
84
|
+
TitlePage::ArrayOfProductIdentifier,
|
85
|
+
::SOAP::SOAPArray,
|
86
|
+
::SOAP::Mapping::EncodedRegistry::TypedArrayFactory,
|
87
|
+
{ :type => XSD::QName.new(NsTitleQuery, "ProductIdentifier") }
|
88
|
+
)
|
89
|
+
|
90
|
+
EncodedRegistry.register(
|
91
|
+
:class => TitlePage::Product,
|
92
|
+
:schema_type => XSD::QName.new(NsTitleQuery, "Product"),
|
93
|
+
:schema_element => [
|
94
|
+
["productIdentifiers", ["TitlePage::ArrayOfProductIdentifier", XSD::QName.new(nil, "ProductIdentifiers")]],
|
95
|
+
["title", ["TitlePage::Title", XSD::QName.new(nil, "Title")]],
|
96
|
+
["contributors", ["TitlePage::ArrayOfContributor", XSD::QName.new(nil, "Contributors")]],
|
97
|
+
["supplyDetail", ["TitlePage::SupplyDetail", XSD::QName.new(nil, "SupplyDetail")]]
|
98
|
+
]
|
99
|
+
)
|
100
|
+
|
101
|
+
EncodedRegistry.register(
|
102
|
+
:class => TitlePage::SearchResults,
|
103
|
+
:schema_type => XSD::QName.new(NsTitleQuery, "SearchResults"),
|
104
|
+
:schema_element => [
|
105
|
+
["iSBN", ["SOAP::SOAPString", XSD::QName.new(nil, "ISBN")]],
|
106
|
+
["eAN", ["SOAP::SOAPString", XSD::QName.new(nil, "EAN")]],
|
107
|
+
["iSBN13", ["SOAP::SOAPString", XSD::QName.new(nil, "ISBN13")]],
|
108
|
+
["product", ["TitlePage::Product", XSD::QName.new(nil, "Product")]]
|
109
|
+
]
|
110
|
+
)
|
111
|
+
|
112
|
+
LiteralRegistry.register(
|
113
|
+
:class => TitlePage::ProductIdentifier,
|
114
|
+
:schema_type => XSD::QName.new(NsTitleQuery, "ProductIdentifier"),
|
115
|
+
:schema_element => [
|
116
|
+
["productIDType", ["SOAP::SOAPString", XSD::QName.new(nil, "ProductIDType")]],
|
117
|
+
["iDValue", ["SOAP::SOAPString", XSD::QName.new(nil, "IDValue")]]
|
118
|
+
]
|
119
|
+
)
|
120
|
+
|
121
|
+
LiteralRegistry.register(
|
122
|
+
:class => TitlePage::Title,
|
123
|
+
:schema_type => XSD::QName.new(NsTitleQuery, "Title"),
|
124
|
+
:schema_element => [
|
125
|
+
["titleType", ["SOAP::SOAPString", XSD::QName.new(nil, "TitleType")]],
|
126
|
+
["titleText", ["SOAP::SOAPString", XSD::QName.new(nil, "TitleText")]],
|
127
|
+
["titlePrefix", ["SOAP::SOAPString", XSD::QName.new(nil, "TitlePrefix")]],
|
128
|
+
["titleWithoutPrefix", ["SOAP::SOAPString", XSD::QName.new(nil, "TitleWithoutPrefix")]],
|
129
|
+
["subtitle", ["SOAP::SOAPString", XSD::QName.new(nil, "Subtitle")]]
|
130
|
+
]
|
131
|
+
)
|
132
|
+
|
133
|
+
LiteralRegistry.register(
|
134
|
+
:class => TitlePage::Contributor,
|
135
|
+
:schema_type => XSD::QName.new(NsTitleQuery, "Contributor"),
|
136
|
+
:schema_element => [
|
137
|
+
["sequenceNumber", ["SOAP::SOAPInteger", XSD::QName.new(nil, "SequenceNumber")]],
|
138
|
+
["contributorRole", ["SOAP::SOAPString", XSD::QName.new(nil, "ContributorRole")]],
|
139
|
+
["personName", ["SOAP::SOAPString", XSD::QName.new(nil, "PersonName")]],
|
140
|
+
["personNameInverted", ["SOAP::SOAPString", XSD::QName.new(nil, "PersonNameInverted")]],
|
141
|
+
["titlesBeforeNames", ["SOAP::SOAPString", XSD::QName.new(nil, "TitlesBeforeNames")]],
|
142
|
+
["keyNames", ["SOAP::SOAPString", XSD::QName.new(nil, "KeyNames")]]
|
143
|
+
]
|
144
|
+
)
|
145
|
+
|
146
|
+
LiteralRegistry.register(
|
147
|
+
:class => TitlePage::Stock,
|
148
|
+
:schema_type => XSD::QName.new(NsTitleQuery, "Stock"),
|
149
|
+
:schema_element => [
|
150
|
+
["onHand", ["SOAP::SOAPString", XSD::QName.new(nil, "OnHand")]],
|
151
|
+
["onOrder", ["SOAP::SOAPString", XSD::QName.new(nil, "OnOrder")]]
|
152
|
+
]
|
153
|
+
)
|
154
|
+
|
155
|
+
LiteralRegistry.register(
|
156
|
+
:class => TitlePage::Price,
|
157
|
+
:schema_type => XSD::QName.new(NsTitleQuery, "Price"),
|
158
|
+
:schema_element => [
|
159
|
+
["priceTypeCode", ["SOAP::SOAPString", XSD::QName.new(nil, "PriceTypeCode")]],
|
160
|
+
["priceAmount", ["SOAP::SOAPDecimal", XSD::QName.new(nil, "PriceAmount")]]
|
161
|
+
]
|
162
|
+
)
|
163
|
+
|
164
|
+
LiteralRegistry.register(
|
165
|
+
:class => TitlePage::SupplyDetail,
|
166
|
+
:schema_type => XSD::QName.new(NsTitleQuery, "SupplyDetail"),
|
167
|
+
:schema_element => [
|
168
|
+
["supplierName", ["SOAP::SOAPString", XSD::QName.new(nil, "SupplierName")]],
|
169
|
+
["supplierRole", ["SOAP::SOAPString", XSD::QName.new(nil, "SupplierRole")]],
|
170
|
+
["productAvailability", ["SOAP::SOAPString", XSD::QName.new(nil, "ProductAvailability")]],
|
171
|
+
["expectedShipDate", ["SOAP::SOAPString", XSD::QName.new(nil, "ExpectedShipDate")]],
|
172
|
+
["stock", ["TitlePage::Stock", XSD::QName.new(nil, "Stock")]],
|
173
|
+
["packQuantity", ["SOAP::SOAPInteger", XSD::QName.new(nil, "PackQuantity")]],
|
174
|
+
["price", ["TitlePage::Price", XSD::QName.new(nil, "Price")]]
|
175
|
+
]
|
176
|
+
)
|
177
|
+
|
178
|
+
LiteralRegistry.register(
|
179
|
+
:class => TitlePage::Product,
|
180
|
+
:schema_type => XSD::QName.new(NsTitleQuery, "Product"),
|
181
|
+
:schema_element => [
|
182
|
+
["productIdentifiers", ["TitlePage::ArrayOfProductIdentifier", XSD::QName.new(nil, "ProductIdentifiers")]],
|
183
|
+
["title", ["TitlePage::Title", XSD::QName.new(nil, "Title")]],
|
184
|
+
["contributors", ["TitlePage::ArrayOfContributor", XSD::QName.new(nil, "Contributors")]],
|
185
|
+
["supplyDetail", ["TitlePage::SupplyDetail", XSD::QName.new(nil, "SupplyDetail")]]
|
186
|
+
]
|
187
|
+
)
|
188
|
+
|
189
|
+
LiteralRegistry.register(
|
190
|
+
:class => TitlePage::SearchResults,
|
191
|
+
:schema_type => XSD::QName.new(NsTitleQuery, "SearchResults"),
|
192
|
+
:schema_element => [
|
193
|
+
["iSBN", ["SOAP::SOAPString", XSD::QName.new(nil, "ISBN")]],
|
194
|
+
["eAN", ["SOAP::SOAPString", XSD::QName.new(nil, "EAN")]],
|
195
|
+
["iSBN13", ["SOAP::SOAPString", XSD::QName.new(nil, "ISBN13")]],
|
196
|
+
["product", ["TitlePage::Product", XSD::QName.new(nil, "Product")]]
|
197
|
+
]
|
198
|
+
)
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'soap/rpc/driver'
|
2
|
+
|
3
|
+
module TitlePage
|
4
|
+
class TitleQueryPortType < ::SOAP::RPC::Driver
|
5
|
+
DefaultEndpointUrl = "http://www.titlepage.com.au/ws/TitleQuery.php"
|
6
|
+
NsWs = "http://www.titlepage.com/ws"
|
7
|
+
|
8
|
+
Methods = [
|
9
|
+
[ XSD::QName.new(NsWs, "Login"),
|
10
|
+
"http://www.titlepage.com.au/ws/TitleQuery.php/Login",
|
11
|
+
"login",
|
12
|
+
[ ["in", "UserName", ["::SOAP::SOAPString"]],
|
13
|
+
["in", "Password", ["::SOAP::SOAPString"]],
|
14
|
+
["retval", "Token", ["::SOAP::SOAPString"]] ],
|
15
|
+
{ :request_style => :rpc, :request_use => :encoded,
|
16
|
+
:response_style => :rpc, :response_use => :encoded,
|
17
|
+
:faults => {} }
|
18
|
+
],
|
19
|
+
[ XSD::QName.new(NsWs, "SearchByISBN"),
|
20
|
+
"http://www.titlepage.com.au/ws/TitleQuery.php/SearchByISBN",
|
21
|
+
"searchByISBN",
|
22
|
+
[ ["in", "Token", ["::SOAP::SOAPString"]],
|
23
|
+
["in", "ISBN", ["::SOAP::SOAPString"]],
|
24
|
+
["retval", "SearchResults", ["TitlePage::SearchResults", "urn:TitleQuery", "SearchResults"]] ],
|
25
|
+
{ :request_style => :rpc, :request_use => :encoded,
|
26
|
+
:response_style => :rpc, :response_use => :encoded,
|
27
|
+
:faults => {} }
|
28
|
+
],
|
29
|
+
[ XSD::QName.new(NsWs, "SearchByISBN13"),
|
30
|
+
"http://www.titlepage.com.au/ws/TitleQuery.php/SearchByISBN13",
|
31
|
+
"searchByISBN13",
|
32
|
+
[ ["in", "Token", ["::SOAP::SOAPString"]],
|
33
|
+
["in", "ISBN13", ["::SOAP::SOAPString"]],
|
34
|
+
["retval", "SearchResults", ["TitlePage::SearchResults", "urn:TitleQuery", "SearchResults"]] ],
|
35
|
+
{ :request_style => :rpc, :request_use => :encoded,
|
36
|
+
:response_style => :rpc, :response_use => :encoded,
|
37
|
+
:faults => {} }
|
38
|
+
],
|
39
|
+
[ XSD::QName.new(NsWs, "SearchByEAN"),
|
40
|
+
"http://www.titlepage.com.au/ws/TitleQuery.php/SearchByEAN",
|
41
|
+
"searchByEAN",
|
42
|
+
[ ["in", "Token", ["::SOAP::SOAPString"]],
|
43
|
+
["in", "EAN", ["::SOAP::SOAPString"]],
|
44
|
+
["retval", "SearchResults", ["TitlePage::SearchResults", "urn:TitleQuery", "SearchResults"]] ],
|
45
|
+
{ :request_style => :rpc, :request_use => :encoded,
|
46
|
+
:response_style => :rpc, :response_use => :encoded,
|
47
|
+
:faults => {} }
|
48
|
+
],
|
49
|
+
[ XSD::QName.new(NsWs, "Logout"),
|
50
|
+
"http://www.titlepage.com.au/ws/TitleQuery.php/Logout",
|
51
|
+
"logout",
|
52
|
+
[ ["in", "token", ["::SOAP::SOAPString"]] ],
|
53
|
+
{ :request_style => :rpc, :request_use => :encoded,
|
54
|
+
:response_style => :rpc, :response_use => :encoded,
|
55
|
+
:faults => {} }
|
56
|
+
]
|
57
|
+
]
|
58
|
+
|
59
|
+
def initialize(endpoint_url = nil)
|
60
|
+
endpoint_url ||= DefaultEndpointUrl
|
61
|
+
super(endpoint_url, nil)
|
62
|
+
self.mapping_registry = DefaultMappingRegistry::EncodedRegistry
|
63
|
+
self.literal_mapping_registry = DefaultMappingRegistry::LiteralRegistry
|
64
|
+
init_methods
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def init_methods
|
70
|
+
Methods.each do |definitions|
|
71
|
+
opt = definitions.last
|
72
|
+
if opt[:request_style] == :document
|
73
|
+
add_document_operation(*definitions)
|
74
|
+
else
|
75
|
+
add_rpc_operation(*definitions)
|
76
|
+
qname = definitions[0]
|
77
|
+
name = definitions[2]
|
78
|
+
if qname.name != name and qname.name.capitalize == name.capitalize
|
79
|
+
::SOAP::Mapping.define_singleton_method(self, qname.name) do |*arg|
|
80
|
+
__send__(name, *arg)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,293 @@
|
|
1
|
+
require 'xsd/qname'
|
2
|
+
|
3
|
+
module TitlePage
|
4
|
+
|
5
|
+
# {urn:TitleQuery}ProductIdentifier
|
6
|
+
# productIDType - SOAP::SOAPString
|
7
|
+
# iDValue - SOAP::SOAPString
|
8
|
+
class ProductIdentifier
|
9
|
+
attr_accessor :productIDType
|
10
|
+
attr_accessor :iDValue
|
11
|
+
|
12
|
+
def initialize(productIDType = nil, iDValue = nil)
|
13
|
+
@productIDType = productIDType
|
14
|
+
@iDValue = iDValue
|
15
|
+
end
|
16
|
+
|
17
|
+
# An older version of soap4r that was used to generate boilerplate code
|
18
|
+
# in versions of this gem <= 0.9.3 created methods that started with
|
19
|
+
# capitals. Detect when some code calls these old method names and
|
20
|
+
# print a deprecation warning.
|
21
|
+
def method_missing(method, *arguments)
|
22
|
+
new_method = method.to_s[0,1].downcase
|
23
|
+
new_method << method.to_s[1,20]
|
24
|
+
|
25
|
+
if self.respond_to?(new_method)
|
26
|
+
$stderr.puts "Warning: #{method} is deprecated. Use #{new_method} instead"
|
27
|
+
self.send(new_method, *arguments)
|
28
|
+
else
|
29
|
+
super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# {urn:TitleQuery}Title
|
35
|
+
# titleType - SOAP::SOAPString
|
36
|
+
# titleText - SOAP::SOAPString
|
37
|
+
# titlePrefix - SOAP::SOAPString
|
38
|
+
# titleWithoutPrefix - SOAP::SOAPString
|
39
|
+
# subtitle - SOAP::SOAPString
|
40
|
+
class Title
|
41
|
+
attr_accessor :titleType
|
42
|
+
attr_accessor :titleText
|
43
|
+
attr_accessor :titlePrefix
|
44
|
+
attr_accessor :titleWithoutPrefix
|
45
|
+
attr_accessor :subtitle
|
46
|
+
|
47
|
+
def initialize(titleType = nil, titleText = nil, titlePrefix = nil, titleWithoutPrefix = nil, subtitle = nil)
|
48
|
+
@titleType = titleType
|
49
|
+
@titleText = titleText
|
50
|
+
@titlePrefix = titlePrefix
|
51
|
+
@titleWithoutPrefix = titleWithoutPrefix
|
52
|
+
@subtitle = subtitle
|
53
|
+
end
|
54
|
+
|
55
|
+
# An older version of soap4r that was used to generate boilerplate code
|
56
|
+
# in versions of this gem <= 0.9.3 created methods that started with
|
57
|
+
# capitals. Detect when some code calls these old method names and
|
58
|
+
# print a deprecation warning.
|
59
|
+
def method_missing(method, *arguments)
|
60
|
+
new_method = method.to_s[0,1].downcase
|
61
|
+
new_method << method.to_s[1,20]
|
62
|
+
|
63
|
+
if self.respond_to?(new_method)
|
64
|
+
$stderr.puts "Warning: #{method} is deprecated. Use #{new_method} instead"
|
65
|
+
self.send(new_method, *arguments)
|
66
|
+
else
|
67
|
+
super
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# {urn:TitleQuery}Contributor
|
73
|
+
# sequenceNumber - SOAP::SOAPInteger
|
74
|
+
# contributorRole - SOAP::SOAPString
|
75
|
+
# personName - SOAP::SOAPString
|
76
|
+
# personNameInverted - SOAP::SOAPString
|
77
|
+
# titlesBeforeNames - SOAP::SOAPString
|
78
|
+
# keyNames - SOAP::SOAPString
|
79
|
+
class Contributor
|
80
|
+
attr_accessor :sequenceNumber
|
81
|
+
attr_accessor :contributorRole
|
82
|
+
attr_accessor :personName
|
83
|
+
attr_accessor :personNameInverted
|
84
|
+
attr_accessor :titlesBeforeNames
|
85
|
+
attr_accessor :keyNames
|
86
|
+
|
87
|
+
def initialize(sequenceNumber = nil, contributorRole = nil, personName = nil, personNameInverted = nil, titlesBeforeNames = nil, keyNames = nil)
|
88
|
+
@sequenceNumber = sequenceNumber
|
89
|
+
@contributorRole = contributorRole
|
90
|
+
@personName = personName
|
91
|
+
@personNameInverted = personNameInverted
|
92
|
+
@titlesBeforeNames = titlesBeforeNames
|
93
|
+
@keyNames = keyNames
|
94
|
+
end
|
95
|
+
|
96
|
+
# An older version of soap4r that was used to generate boilerplate code
|
97
|
+
# in versions of this gem <= 0.9.3 created methods that started with
|
98
|
+
# capitals. Detect when some code calls these old method names and
|
99
|
+
# print a deprecation warning.
|
100
|
+
def method_missing(method, *arguments)
|
101
|
+
new_method = method.to_s[0,1].downcase
|
102
|
+
new_method << method.to_s[1,20]
|
103
|
+
|
104
|
+
if self.respond_to?(new_method)
|
105
|
+
$stderr.puts "Warning: #{method} is deprecated. Use #{new_method} instead"
|
106
|
+
self.send(new_method, *arguments)
|
107
|
+
else
|
108
|
+
super
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# {urn:TitleQuery}Stock
|
114
|
+
# onHand - SOAP::SOAPString
|
115
|
+
# onOrder - SOAP::SOAPString
|
116
|
+
class Stock
|
117
|
+
attr_accessor :onHand
|
118
|
+
attr_accessor :onOrder
|
119
|
+
|
120
|
+
def initialize(onHand = nil, onOrder = nil)
|
121
|
+
@onHand = onHand
|
122
|
+
@onOrder = onOrder
|
123
|
+
end
|
124
|
+
|
125
|
+
# An older version of soap4r that was used to generate boilerplate code
|
126
|
+
# in versions of this gem <= 0.9.3 created methods that started with
|
127
|
+
# capitals. Detect when some code calls these old method names and
|
128
|
+
# print a deprecation warning.
|
129
|
+
def method_missing(method, *arguments)
|
130
|
+
new_method = method.to_s[0,1].downcase
|
131
|
+
new_method << method.to_s[1,20]
|
132
|
+
|
133
|
+
if self.respond_to?(new_method)
|
134
|
+
$stderr.puts "Warning: #{method} is deprecated. Use #{new_method} instead"
|
135
|
+
self.send(new_method, *arguments)
|
136
|
+
else
|
137
|
+
super
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# {urn:TitleQuery}Price
|
143
|
+
# priceTypeCode - SOAP::SOAPString
|
144
|
+
# priceAmount - SOAP::SOAPDecimal
|
145
|
+
class Price
|
146
|
+
attr_accessor :priceTypeCode
|
147
|
+
attr_accessor :priceAmount
|
148
|
+
|
149
|
+
def initialize(priceTypeCode = nil, priceAmount = nil)
|
150
|
+
@priceTypeCode = priceTypeCode
|
151
|
+
@priceAmount = priceAmount
|
152
|
+
end
|
153
|
+
|
154
|
+
# An older version of soap4r that was used to generate boilerplate code
|
155
|
+
# in versions of this gem <= 0.9.3 created methods that started with
|
156
|
+
# capitals. Detect when some code calls these old method names and
|
157
|
+
# print a deprecation warning.
|
158
|
+
def method_missing(method, *arguments)
|
159
|
+
new_method = method.to_s[0,1].downcase
|
160
|
+
new_method << method.to_s[1,20]
|
161
|
+
|
162
|
+
if self.respond_to?(new_method)
|
163
|
+
$stderr.puts "Warning: #{method} is deprecated. Use #{new_method} instead"
|
164
|
+
self.send(new_method, *arguments)
|
165
|
+
else
|
166
|
+
super
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
# {urn:TitleQuery}SupplyDetail
|
172
|
+
# supplierName - SOAP::SOAPString
|
173
|
+
# supplierRole - SOAP::SOAPString
|
174
|
+
# productAvailability - SOAP::SOAPString
|
175
|
+
# expectedShipDate - SOAP::SOAPString
|
176
|
+
# stock - TitlePage::Stock
|
177
|
+
# packQuantity - SOAP::SOAPInteger
|
178
|
+
# price - TitlePage::Price
|
179
|
+
class SupplyDetail
|
180
|
+
attr_accessor :supplierName
|
181
|
+
attr_accessor :supplierRole
|
182
|
+
attr_accessor :productAvailability
|
183
|
+
attr_accessor :expectedShipDate
|
184
|
+
attr_accessor :stock
|
185
|
+
attr_accessor :packQuantity
|
186
|
+
attr_accessor :price
|
187
|
+
|
188
|
+
def initialize(supplierName = nil, supplierRole = nil, productAvailability = nil, expectedShipDate = nil, stock = nil, packQuantity = nil, price = nil)
|
189
|
+
@supplierName = supplierName
|
190
|
+
@supplierRole = supplierRole
|
191
|
+
@productAvailability = productAvailability
|
192
|
+
@expectedShipDate = expectedShipDate
|
193
|
+
@stock = stock
|
194
|
+
@packQuantity = packQuantity
|
195
|
+
@price = price
|
196
|
+
end
|
197
|
+
|
198
|
+
# An older version of soap4r that was used to generate boilerplate code
|
199
|
+
# in versions of this gem <= 0.9.3 created methods that started with
|
200
|
+
# capitals. Detect when some code calls these old method names and
|
201
|
+
# print a deprecation warning.
|
202
|
+
def method_missing(method, *arguments)
|
203
|
+
new_method = method.to_s[0,1].downcase
|
204
|
+
new_method << method.to_s[1,20]
|
205
|
+
|
206
|
+
if self.respond_to?(new_method)
|
207
|
+
$stderr.puts "Warning: #{method} is deprecated. Use #{new_method} instead"
|
208
|
+
self.send(new_method, *arguments)
|
209
|
+
else
|
210
|
+
super
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
# {urn:TitleQuery}Product
|
216
|
+
# productIdentifiers - TitlePage::ArrayOfProductIdentifier
|
217
|
+
# title - TitlePage::Title
|
218
|
+
# contributors - TitlePage::ArrayOfContributor
|
219
|
+
# supplyDetail - TitlePage::SupplyDetail
|
220
|
+
class Product
|
221
|
+
attr_accessor :productIdentifiers
|
222
|
+
attr_accessor :title
|
223
|
+
attr_accessor :contributors
|
224
|
+
attr_accessor :supplyDetail
|
225
|
+
|
226
|
+
def initialize(productIdentifiers = nil, title = nil, contributors = nil, supplyDetail = nil)
|
227
|
+
@productIdentifiers = productIdentifiers
|
228
|
+
@title = title
|
229
|
+
@contributors = contributors
|
230
|
+
@supplyDetail = supplyDetail
|
231
|
+
end
|
232
|
+
|
233
|
+
# An older version of soap4r that was used to generate boilerplate code
|
234
|
+
# in versions of this gem <= 0.9.3 created methods that started with
|
235
|
+
# capitals. Detect when some code calls these old method names and
|
236
|
+
# print a deprecation warning.
|
237
|
+
def method_missing(method, *arguments)
|
238
|
+
new_method = method.to_s[0,1].downcase
|
239
|
+
new_method << method.to_s[1,20]
|
240
|
+
|
241
|
+
if self.respond_to?(new_method)
|
242
|
+
$stderr.puts "Warning: #{method} is deprecated. Use #{new_method} instead"
|
243
|
+
self.send(new_method, *arguments)
|
244
|
+
else
|
245
|
+
super
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
# {urn:TitleQuery}SearchResults
|
251
|
+
# iSBN - SOAP::SOAPString
|
252
|
+
# eAN - SOAP::SOAPString
|
253
|
+
# iSBN13 - SOAP::SOAPString
|
254
|
+
# product - TitlePage::Product
|
255
|
+
class SearchResults
|
256
|
+
attr_accessor :iSBN
|
257
|
+
attr_accessor :eAN
|
258
|
+
attr_accessor :iSBN13
|
259
|
+
attr_accessor :product
|
260
|
+
|
261
|
+
def initialize(iSBN = nil, eAN = nil, iSBN13 = nil, product = nil)
|
262
|
+
@iSBN = iSBN
|
263
|
+
@eAN = eAN
|
264
|
+
@iSBN13 = iSBN13
|
265
|
+
@product = product
|
266
|
+
end
|
267
|
+
|
268
|
+
# An older version of soap4r that was used to generate boilerplate code
|
269
|
+
# in versions of this gem <= 0.9.3 created methods that started with
|
270
|
+
# capitals. Detect when some code calls these old method names and
|
271
|
+
# print a deprecation warning.
|
272
|
+
def method_missing(method, *arguments)
|
273
|
+
new_method = method.to_s[0,1].downcase
|
274
|
+
new_method << method.to_s[1,20]
|
275
|
+
|
276
|
+
if self.respond_to?(new_method)
|
277
|
+
$stderr.puts "Warning: #{method} is deprecated. Use #{new_method} instead"
|
278
|
+
self.send(new_method, *arguments)
|
279
|
+
else
|
280
|
+
super
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
# {urn:TitleQuery}ArrayOfContributor
|
286
|
+
class ArrayOfContributor < ::Array
|
287
|
+
end
|
288
|
+
|
289
|
+
# {urn:TitleQuery}ArrayOfProductIdentifier
|
290
|
+
class ArrayOfProductIdentifier < ::Array
|
291
|
+
end
|
292
|
+
|
293
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + "/../")
|
2
|
+
|
3
|
+
require 'rbook/isbn'
|
4
|
+
require 'net/http'
|
5
|
+
|
6
|
+
module TitlePage
|
7
|
+
|
8
|
+
# A helper class for grabbing ONIX files from titlepage.com
|
9
|
+
#
|
10
|
+
# A valid login is required, see the site for information on applying
|
11
|
+
# for access.
|
12
|
+
#
|
13
|
+
# You should be aware of any limits of query volume imposed by the provider - currently a
|
14
|
+
# maximum of 30 queries per minute is permitted.
|
15
|
+
#
|
16
|
+
# = Usage
|
17
|
+
#
|
18
|
+
# TitlePage::WWWClient.open("username","password") do |tp|
|
19
|
+
# puts tp.get_onix_file("9780091835132")
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
class WWWClient
|
23
|
+
|
24
|
+
TITLEPAGE_DOMAIN = "www.titlepage.com"
|
25
|
+
|
26
|
+
def get_onix_file(isbn)
|
27
|
+
isbn = RBook::ISBN.convert_to_isbn13(isbn)
|
28
|
+
raise ArgumentError, 'Invalid ISBN supplied' if isbn.nil?
|
29
|
+
|
30
|
+
headers = { 'Cookie' => @cookie }
|
31
|
+
|
32
|
+
login_response = Net::HTTP.start(TITLEPAGE_DOMAIN, 80) do |http|
|
33
|
+
data = [
|
34
|
+
"posted=yes",
|
35
|
+
"quicksearch=#{isbn}",
|
36
|
+
"qsrchby=ean",
|
37
|
+
"detailed=Search"
|
38
|
+
].join("&")
|
39
|
+
http.post('/results.php', data, headers)
|
40
|
+
end
|
41
|
+
regex = /onclick=\"bookPopUp\(\'(.+)\'\);\"/
|
42
|
+
code = login_response.body.match(regex)
|
43
|
+
if code.nil?
|
44
|
+
return nil
|
45
|
+
else
|
46
|
+
code = code[1]
|
47
|
+
end
|
48
|
+
onix_file = Net::HTTP.start(TITLEPAGE_DOMAIN, 80) do |http|
|
49
|
+
data = [
|
50
|
+
"download=Download",
|
51
|
+
"rr=#{code}"
|
52
|
+
].join("&")
|
53
|
+
http.post('/detail.php', data, headers)
|
54
|
+
end
|
55
|
+
return onix_file.body
|
56
|
+
end
|
57
|
+
|
58
|
+
# login to the titlepage website.
|
59
|
+
def login(username, password)
|
60
|
+
login_response = Net::HTTP.start(TITLEPAGE_DOMAIN, 80) do |http|
|
61
|
+
data = [
|
62
|
+
"usr=#{username}",
|
63
|
+
"pwd=#{password}",
|
64
|
+
"login=Login"
|
65
|
+
].join("&")
|
66
|
+
http.post('/index.php', data)
|
67
|
+
end
|
68
|
+
@cookie = login_response['set-cookie']
|
69
|
+
end
|
70
|
+
|
71
|
+
# logout from the titlepage API
|
72
|
+
def logout
|
73
|
+
if @cookie
|
74
|
+
login_response = Net::HTTP.start(TITLEPAGE_DOMAIN, 80) do |http|
|
75
|
+
http.get("/logout.php")
|
76
|
+
end
|
77
|
+
@cookie = nil
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# a convenience method to make queries to title page a little cleaner. This function
|
82
|
+
# essentially calls the login and logout functions for you automatically.
|
83
|
+
#
|
84
|
+
# TitlePage::WWWClient.open("username","password") do |tp|
|
85
|
+
# result = tp.get_onix_file("9780091835132")
|
86
|
+
# end
|
87
|
+
def self.open(username, password)
|
88
|
+
|
89
|
+
tp = self.new
|
90
|
+
|
91
|
+
begin
|
92
|
+
tp.login(username, password)
|
93
|
+
|
94
|
+
yield(tp)
|
95
|
+
|
96
|
+
ensure
|
97
|
+
tp.logout
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|