Class: ElsevierCover

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

Overview

Elsevier provides publically available and linkable sample cover images for journals they publish. Thanks Elsevier! This service does nothing more than take an ISSN and look for a match from Elsevier.

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

Returns a new instance of ElsevierCover


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

def initialize(config)
  #@base_url = "http://www1.elsevier.com/inca/covers/store/issn/"
  @base_url = "http://www.extranet.elsevier.com/inca_covers_store/issn/"
  
  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/elsevier_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 => ServiceTypeValue[:cover_image] ,
                                  :url => check_url, 
                                  :size => "medium" )
  end   
  
  return request.dispatched(self, true)
end

#service_types_generatedObject


7
8
9
# File 'app/service_adaptors/elsevier_cover.rb', line 7

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/elsevier_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