Class: JstorCover

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

Overview

JStor covers are freely available at a predictable URL. These are in the "fsearch-sandbox" -- not sure if this is going to break in the future.

I'm not entirely sure if JStor actually would like it if we were using them like this, but as a publisher they hopefully want to help customers advertise journals with covers.

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

- (JstorCover) initialize(config)

Returns a new instance of JstorCover



14
15
16
17
18
19
# File 'lib/service_adaptors/jstor_cover.rb', line 14

def initialize(config)
  @base_url = "http://fsearch-sandbox.jstor.org/graphics/thumbs/"
  @display_name = "JStor Journal Covers"
  
  super(config)
end

Instance Method Details

- (Object) handle(request)



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/service_adaptors/jstor_cover.rb', line 21

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

- (Object) service_types_generated



10
11
12
# File 'lib/service_adaptors/jstor_cover.rb', line 10

def service_types_generated
  return [ServiceTypeValue[:cover_image]]
end

- (Object) url_resolves(url)



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/service_adaptors/jstor_cover.rb', line 43

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