Class: TitlePage::Driver

Inherits:
Handsoap::Service
  • Object
show all
Defined in:
lib/titlepage/driver.rb

Instance Method Summary collapse

Instance Method Details

#login(username, password) ⇒ Object

Login to the webservice. Accepts a username and password.

Note that you can use the standard same username and password, but the account needs to have API access activated first.

Returns a string token that must be passed to all other methods.



14
15
16
17
18
19
20
# File 'lib/titlepage/driver.rb', line 14

def (username, password)
  response = invoke("Login") do |message|
    message.add "UserName", username
    message.add "Password", password
  end
  response.document.xpath("//Token/text()").to_s
end

#logout(token) ⇒ Object

logout from the webservice. The standard authentication token must be provided.

There is no useful return value



27
28
29
30
31
32
# File 'lib/titlepage/driver.rb', line 27

def logout(token)
  response = invoke("Logout") do |message|
    message.add "token", token
  end
  true
end

#search_by_ean(token, ean) ⇒ Object

search for products by EAN. The standard authentication token must be provided along with the ISBN.

Returns an array of results.

Note that although in theory EAN and ISBN13 are the same, many suppliers don’t include an explicit EAN in the ONIX files they provide Titlepage, so it is nearly always preferable to search by ISBN13.



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

def search_by_ean(token, ean)
  response = invoke("SearchByEAN") do |message|
    message.add "Token", token
    message.add "EAN", ean
  end
  response.document.xpath("//SearchResults/Product").collect do |node|
    TitlePage::Product.from_xml(node)
  end
end

#search_by_isbn(token, isbn) ⇒ Object

search for products by ISBN10. The standard authentication token must be provided along with the ISBN.

Returns an array of results.



39
40
41
42
43
44
45
46
47
# File 'lib/titlepage/driver.rb', line 39

def search_by_isbn(token, isbn)
  response = invoke("SearchByISBN") do |message|
    message.add "Token", token
    message.add "ISBN", isbn
  end
  response.document.xpath("//SearchResults/Product").collect do |node|
    TitlePage::Product.from_xml(node)
  end
end

#search_by_isbn13(token, isbn) ⇒ Object

search for products by ISBN13. The standard authentication token must be provided along with the ISBN.

Returns an array of results.



54
55
56
57
58
59
60
61
62
# File 'lib/titlepage/driver.rb', line 54

def search_by_isbn13(token, isbn)
  response = invoke("SearchByISBN13") do |message|
    message.add "Token", token
    message.add "ISBN13", isbn
  end
  response.document.xpath("//SearchResults/Product").collect do |node|
    TitlePage::Product.from_xml(node)
  end
end