Class: TitlePage::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeClient

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 = TitlePage::Driver.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 = TitlePage.find("username","password","9780091835132")
puts result.inspect


74
75
76
77
78
79
80
# File 'lib/titlepage/client.rb', line 74

def self.find(username, password, isbn)
  result = nil
  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.

TitlePage.open("username","password") do |tp|
  result = tp.find("9780091835132")
end


88
89
90
91
92
93
94
95
96
97
98
# File 'lib/titlepage/client.rb', line 88

def self.open(username, password)

  tp = self.new

  begin
    tp.(username, password)
    yield tp
  ensure
    tp.logout
  end
end

Instance Method Details

#all(isbn) ⇒ Object



55
56
57
58
59
# File 'lib/titlepage/client.rb', line 55

def all(isbn)
  return NotLoggedInError, 'You must login to titlepage API before performing a search' unless @token
  isbn = ISBN10.new(isbn).to_ean || isbn
  @driver.search_by_isbn13(@token, isbn)
end

#find(type, isbn) ⇒ Object

Retrieve information on a specified ISBN. Can be an ISBN10 or ISBN13.



44
45
46
47
48
49
50
51
52
53
# File 'lib/titlepage/client.rb', line 44

def find(type, isbn)
  case type
  when :first
    first(isbn)
  when :all
    all(isbn)
  else
    raise ArgumentError, "invalid type #{type}"
  end
end

#first(isbn) ⇒ Object



61
62
63
# File 'lib/titlepage/client.rb', line 61

def first(isbn)
  all(isbn).first
end

#last(isbn) ⇒ Object



65
66
67
# File 'lib/titlepage/client.rb', line 65

def last(isbn)
  all(isbn).last
end

#login(username, password) ⇒ Object

login to the titlepage API.



23
24
25
26
27
28
29
30
31
# File 'lib/titlepage/client.rb', line 23

def (username, password)
  logout if @token
  @token = @driver.(username, password)
  if @token
    return true
  else
    return false
  end
end

#logoutObject

logout from the titlepage API



35
36
37
38
39
40
# File 'lib/titlepage/client.rb', line 35

def logout
  if @token
    @driver.logout(@token)
    @token = nil
  end
end