Class: TitlePage::Client
- Inherits:
-
Object
- Object
- TitlePage::Client
- Defined in:
- lib/titlepage/client.rb
Overview
a convenience class for accessing the SOAP API for www.titlepage.com. Uses boilerplate code generated by soap4r.
You should be aware of any limits of query volume imposed by the provider - currently a maximum of 30 queries per minute is permitted.
For a basic usage overview, check out TitlePage
Class Method Summary collapse
-
.find(username, password, isbn) ⇒ Object
a convenience method to make single queries to title page a little cleaner.
-
.open(username, password) ⇒ Object
a convenience method to make queries to title page a little cleaner.
Instance Method Summary collapse
-
#find(isbn) ⇒ Object
retrieve information on a specified ISBN.
-
#initialize ⇒ Client
constructor
Optional driver parameter allows an alternative SOAP driver to the default to be specified.
-
#login(username, password) ⇒ Object
login to the titlepage API.
-
#logout ⇒ Object
logout from the titlepage API.
Constructor Details
#initialize ⇒ Client
Optional driver parameter allows an alternative SOAP driver to the default to be specified. This is primarily for testing purposes and probably isn’t useful to anyone in the real world.
16 17 18 19 |
# File 'lib/titlepage/client.rb', line 16 def initialize @driver = TitleQueryPortType.new @token = nil end |
Class Method Details
.find(username, password, isbn) ⇒ Object
a convenience method to make single queries to title page a little cleaner.
result = RBook::TitlePage.find("username","password","9780091835132")
puts result.inspect
61 62 63 64 65 66 67 |
# File 'lib/titlepage/client.rb', line 61 def self.find(username, password, isbn) result = nil RBook::TitlePage::Client.open(username, password) do |tp| result = tp.find(isbn) end return result end |
.open(username, password) ⇒ Object
a convenience method to make queries to title page a little cleaner. This function essentially calls the login and logout functions for you automatically.
RBook::TitlePage.open("username","password") do |tp|
result = tp.find("9780091835132")
end
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/titlepage/client.rb', line 75 def self.open(username, password) tp = self.new begin tp.login(username, password) yield tp ensure tp.logout end end |
Instance Method Details
#find(isbn) ⇒ Object
retrieve information on a specified ISBN
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/titlepage/client.rb', line 42 def find(isbn) return NotLoggedInError, 'You must login to titlepage API before performing a search' unless @token isbn = RBook::ISBN::convert_to_isbn13(isbn) return nil if isbn.nil? begin result = @driver.SearchByISBN13(@token, isbn) if result.Product.nil? return nil else return result end end end |
#login(username, password) ⇒ Object
login to the titlepage API.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/titlepage/client.rb', line 22 def login(username, password) raise InvalidRubyVersionError, 'Ruby 1.8.3 or higher is required to use this class' unless RUBY_VERSION >= "1.8.3" logout if @token @token = @driver.login(username, password) if @token return true else return false end end |
#logout ⇒ Object
logout from the titlepage API
34 35 36 37 38 39 |
# File 'lib/titlepage/client.rb', line 34 def logout if @token @driver.logout(@token) @token = nil end end |