Class: BookFinder

Inherits:
Service show all
Defined in:
lib/service_adaptors/book_finder.rb

Overview

Link to BookFinder.com to compare online new and used prices for a book. Requires an ISBN. Does not a pre-check, just generates the link blind, but I think almost any ISBN will get results on BookFinder.

Constant Summary

Constant Summary

Constants inherited from Service

Service::LinkOutFilterTask, Service::StandardTask

Instance Attribute Summary

Attributes inherited from Service

#name, #priority, #request, #service_id, #session_id, #status, #task, #url

Instance Method Summary (collapse)

Methods inherited from Service

#display_name, #handle_wrapper, #link_out_filter, #preempted_by, required_config_params, #response_to_view_data, #response_url, #session, #update_session, #view_data_from_service_type

Constructor Details

- (BookFinder) initialize(config)

A new instance of BookFinder



8
9
10
11
12
13
14
15
# File 'lib/service_adaptors/book_finder.rb', line 8

def initialize(config)
  @display_text = "Compare online prices"
  @display_name = "BookFinder.com"
  # %s is where the ISBN goes
  @url_template = 'http://www.bookfinder.com/search/?isbn=%s&st=xl&ac=qr'

  super(config)
end

Instance Method Details

- (Object) handle(umlaut_request)



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/service_adaptors/book_finder.rb', line 21

def handle(umlaut_request)
  isbn = umlaut_request.referent.isbn

  # Unless we have a valid isbn, give up
  return request.dispatched(self, true) unless isbn && ISBN_Tools.is_valid?(isbn)

  # Okay, make a link
  url = @url_template.sub('%s', isbn)

  umlaut_request.add_service_response({:service=>self, :url=> url, :display_text=> @display_text, :service_type_value => :highlighted_link})

  return request.dispatched(self, true)    
end

- (Object) service_types_generated



17
18
19
# File 'lib/service_adaptors/book_finder.rb', line 17

def service_types_generated
  return [ServiceTypeValue['highlighted_link']]
end