Sha256: 1680e3c00edfde89df5053e6ab782a5a423fce03790347d043276540ee65bea3

Contents?: true

Size: 1.5 KB

Versions: 59

Compression:

Stored size: 1.5 KB

Contents

# 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. 
class UlrichsCover < Service
  require 'open-uri'
  
  def service_types_generated
    return [ServiceTypeValue[:cover_image]]
  end

  def initialize(config)
    @base_url = "http://images.serialssolutions.com/ulrichs/"
    
    super(config)
  end
  
  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

  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
  
end

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
umlaut-4.1.7 app/service_adaptors/ulrichs_cover.rb
umlaut-4.1.6 app/service_adaptors/ulrichs_cover.rb
umlaut-4.1.5 app/service_adaptors/ulrichs_cover.rb
umlaut-4.1.4 app/service_adaptors/ulrichs_cover.rb
umlaut-4.1.3 app/service_adaptors/ulrichs_cover.rb
umlaut-4.1.2 app/service_adaptors/ulrichs_cover.rb
umlaut-4.1.1 app/service_adaptors/ulrichs_cover.rb
umlaut-4.1.0 app/service_adaptors/ulrichs_cover.rb
umlaut-4.1.0.pre3 app/service_adaptors/ulrichs_cover.rb
umlaut-4.1.0.pre.2 app/service_adaptors/ulrichs_cover.rb
umlaut-4.1.0.pre.alpha.1 app/service_adaptors/ulrichs_cover.rb
umlaut-4.0.3 app/service_adaptors/ulrichs_cover.rb
umlaut-4.0.2 app/service_adaptors/ulrichs_cover.rb
umlaut-4.0.1 app/service_adaptors/ulrichs_cover.rb
umlaut-4.0.0 app/service_adaptors/ulrichs_cover.rb
umlaut-4.0.0.beta5 app/service_adaptors/ulrichs_cover.rb
umlaut-4.0.0.beta4 app/service_adaptors/ulrichs_cover.rb
umlaut-4.0.0.beta3 app/service_adaptors/ulrichs_cover.rb
umlaut-4.0.0.beta2 app/service_adaptors/ulrichs_cover.rb
umlaut-4.0.0.beta1 app/service_adaptors/ulrichs_cover.rb