Class: UlrichsCover

Inherits:
Service show all
Defined in:
app/service_adaptors/ulrichs_cover.rb

Overview

Ulrich’s provides journal cover images that are publically available, at predictable urls based on issn. Not sure if this is intentional. But as an ulrich’s subscriber, I feel fine using it. If my insitution was not an ulrich’s subscriber, I probably wouldn’t use this service.

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) ⇒ UlrichsCover

Returns a new instance of UlrichsCover.



12
13
14
15
16
# File 'app/service_adaptors/ulrichs_cover.rb', line 12

def initialize(config)
  @base_url = "http://images.serialssolutions.com/ulrichs/"
  
  super(config)
end

Instance Method Details

#handle(request) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/service_adaptors/ulrichs_cover.rb', line 18

def handle(request)
  issn = request.referent.issn

  # We need an ISSN
  return request.dispatched(self, true) unless issn 

  # No hyphens please
  issn = issn.gsub(/[^0-9X]/, '')
  
  check_url = @base_url + issn + '.gif'

  # does it exist?
  if ( url_resolves(check_url)   )
     request.add_service_response(:service => self,
                                  :service_type_value => :cover_image ,
                                  :url => check_url, 
                                  :size => "medium" )
  end   
  
  return request.dispatched(self, true)
end

#service_types_generatedObject



8
9
10
# File 'app/service_adaptors/ulrichs_cover.rb', line 8

def service_types_generated
  return [ServiceTypeValue[:cover_image]]
end

#url_resolves(url) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/service_adaptors/ulrichs_cover.rb', line 40

def url_resolves(url)
  uri_obj = URI.parse(url)
  response = Net::HTTP.start(uri_obj.host, uri_obj.port) {|http|
    http.head(uri_obj.request_uri)
  }
  if (response.kind_of?( Net::HTTPSuccess  ))
    return true
  elsif ( response.kind_of?(Net::HTTPNotFound))
    return false
  else
    # unexpected condition, raise
    response.value
  end

  
end