Class: Sword2Ruby::AutoDiscover

Inherits:
Object
  • Object
show all
Defined in:
lib/sword2ruby/auto_discover.rb

Overview

AutoDiscover requires the hpricot gem.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(discover_uri) ⇒ AutoDiscover

Perform an Auto-Discovery on the URI supplied (which should point to an html document). The document will be retreived and parsed using hpricot. Service Document, Deposit Endpoint and Resource URIs will be extracted where identified.

For more information, see the Sword2 specification: section 13 “Auto-Discovery”.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/sword2ruby/auto_discover.rb', line 40

def initialize(discover_uri)
  doc = Hpricot(open(discover_uri))
  
  @service_document_uri = get_attribute(doc.at("//link[@rel='http://purl.org/net/sword/discovery/service-document']"), "href")
  @service_document_uri ||= get_attribute(doc.at("//link[@rel='sword']"), "href") #Old sword 1.3
  
  @deposit_endpoint_uri = get_attribute(doc.at("//link[@rel='http://purl.org/net/sword/terms/deposit']"), "href")
  
  @entry_edit_uris = []
  @sword_statement_links = []
  
  doc.search("//link[@rel='http://purl.org/net/sword/terms/edit']").each do |e|
    @entry_edit_uris << {:href => get_attribute(e, "href"), :type=> get_attribute(e, "type")}
  end
  
  doc.search("//link[@rel='http://purl.org/net/sword/terms/statement']").each do |e|
    @sword_statement_links << {:href => get_attribute(e, "href"), :type=> get_attribute(e, "type")}
  end
end

Instance Attribute Details

#deposit_endpoint_uriObject (readonly)

The Deposit Endpoint URI string discovered in the HTML document, or nil if it could not be discovered.

For more information, see the Sword2 specification: section 13.2. “For Deposit Endpoints”.



11
12
13
# File 'lib/sword2ruby/auto_discover.rb', line 11

def deposit_endpoint_uri
  @deposit_endpoint_uri
end

#entry_edit_urisObject (readonly)

An array of Atom Entry Edit URI hashes discovered in the HTML document, or an empty array [ ] if none found.

Example

href="http://some.url.org/edit/mycollection">some.url.org/edit/mycollection”, type=>nil

For more information, see the Sword2 specification: section 13.3. “For Resources”. attr_reader :resource_edit_uris



19
20
21
# File 'lib/sword2ruby/auto_discover.rb', line 19

def entry_edit_uris
  @entry_edit_uris
end

#service_document_uriObject (readonly)

The Service Document URI string discovered in the HTML document, or nil if it could not be discovered.

For more information, see the Sword2 specification: section 13.1. “For Service Documents”.



33
34
35
# File 'lib/sword2ruby/auto_discover.rb', line 33

def service_document_uri
  @service_document_uri
end

An array of Sword Statement URI hashes discovered in the HTML document, or an empty array [ ] if none found.

Example

[ href="http://some.url.org/myfeed.atom">some.url.org/myfeed.atom”, type=>“application/atom+xml;type=feed”, href="http://some.url.org/myfeed.rdf">some.url.org/myfeed.rdf”, type=>“application/rdf+xml” ]

For more information, see the Sword2 specification: section 13.3. “For Resources”.



28
29
30
# File 'lib/sword2ruby/auto_discover.rb', line 28

def sword_statement_links
  @sword_statement_links
end