Class: BookFinder

Inherits:
Service show all
Defined in:
app/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

Constants inherited from Service

Service::LinkOutFilterTask, Service::StandardTask

Instance Attribute Summary

Attributes inherited from Service

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

Instance Method Summary collapse

Methods inherited from Service

#credits, #display_name, #handle_wrapper, #link_out_filter, #preempted_by, required_config_params, #response_url, #translate

Constructor Details

#initialize(config) ⇒ BookFinder


8
9
10
11
12
13
14
15
# File 'app/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

#handle(umlaut_request) ⇒ Object


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/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.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

#service_types_generatedObject


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

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