Class: Marc2LinkedData::OclcIdentity
- Defined in:
- lib/marc2linkeddata/oclc_identity.rb
Constant Summary collapse
- PREFIX =
'http://www.worldcat.org/identities/'
Instance Attribute Summary
Attributes inherited from Resource
Instance Method Summary collapse
-
#creative_works ⇒ Object
def get_xml begin return @xml unless @xml.nil? http = Net::HTTP.new @iri.host resp = http.get(@iri.path, => ‘application/xml’) case resp.code when ‘301’,‘302’,‘303’ #301 Moved Permanently; 302 Moved Temporarily; 303 See Other resp = http.get(resp, => ‘application/xml’) end if resp.code != ‘200’ raise end @xml = resp.body rescue puts ‘ERROR: Failed to request OCLC identity xml.’ end end.
- #rdf ⇒ Object
Methods inherited from Resource
#get_rdf, #id, #initialize, #iri_types, #rdf_find_object, #rdf_find_subject, #rdf_uri, #rdf_valid?, #resolve_external_auth, #same_as, #same_as_array
Constructor Details
This class inherits a constructor from Marc2LinkedData::Resource
Instance Method Details
#creative_works ⇒ Object
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
38 39 40 41 |
# 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 ⇒ Object
9 10 11 12 13 14 15 16 17 |
# 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 |