class Marc2LinkedData::OclcIdentity

Constants

PREFIX

Public Instance Methods

creative_works() click to toggle source

def get_xml

begin
  return @xml unless @xml.nil?
  http = Net::HTTP.new @iri.host
  resp = http.get(@iri.path, {'Accept' => 'application/xml'})
  case resp.code
    when '301','302','303'
      #301 Moved Permanently; 302 Moved Temporarily; 303 See Other
      resp = http.get(resp['location'], {'Accept' => 'application/xml'})
  end
  if resp.code != '200'
    raise
  end
  @xml = resp.body
rescue
  puts 'ERROR: Failed to request OCLC identity xml.'
end

end

# File lib/marc2linkeddata/oclc_identity.rb, line 38
def creative_works
  q = SPARQL.parse('SELECT * WHERE { ?oclcWork a <http://schema.org/CreativeWork> }')
  rdf.query(q).collect {|s| s[:oclcWork] }
end
rdf() click to toggle source
# File lib/marc2linkeddata/oclc_identity.rb, line 9
def rdf
  # e.g. 'http://www.worldcat.org/identities/lccn-n79044803/'
  # the html returned contains RDFa data
  return nil if @iri.nil?
  return @rdf unless @rdf.nil?
  uri4rdf = @iri.to_s
  uri4rdf += '/' unless uri4rdf.end_with? '/'
  @rdf = get_rdf(uri4rdf)
end