Sha256: e6947bf8701c5ba7a0201ab0fe0b4061aa9e70a019b6f08bf66518fd63f35be6

Contents?: true

Size: 1.52 KB

Versions: 59

Compression:

Stored size: 1.52 KB

Contents

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

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

  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-3.0.0beta4 lib/service_adaptors/elsevier_cover.rb
umlaut-3.0.0beta3 lib/service_adaptors/elsevier_cover.rb
umlaut-3.0.0beta2 lib/service_adaptors/elsevier_cover.rb
umlaut-3.0.0beta1 lib/service_adaptors/elsevier_cover.rb
umlaut-3.0.0alpha15 lib/service_adaptors/elsevier_cover.rb
umlaut-3.0.0alpha14 lib/service_adaptors/elsevier_cover.rb
umlaut-3.0.0alpha13 lib/service_adaptors/elsevier_cover.rb
umlaut-3.0.0alpha12 lib/service_adaptors/elsevier_cover.rb
umlaut-3.0.0alpha11 lib/service_adaptors/elsevier_cover.rb
umlaut-3.0.0alpha10 lib/service_adaptors/elsevier_cover.rb
umlaut-3.0.0alpha9 lib/service_adaptors/elsevier_cover.rb
umlaut-3.0.0alpha8 lib/service_adaptors/elsevier_cover.rb
umlaut-3.0.0alpha7 lib/service_adaptors/elsevier_cover.rb
umlaut-3.0.0alpha6 lib/service_adaptors/elsevier_cover.rb
umlaut-3.0.0alpha5 lib/service_adaptors/elsevier_cover.rb
umlaut-3.0.0alpha4 lib/service_adaptors/elsevier_cover.rb
umlaut-3.0.0alpha3 lib/service_adaptors/elsevier_cover.rb
umlaut-3.0.0alpha2 lib/service_adaptors/elsevier_cover.rb
umlaut-3.0.0alpha1 lib/service_adaptors/elsevier_cover.rb