Class: Atom::Service

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

Overview

Extend existing Atom::Service with Sword methods

For more information, see the Sword2 specification: section 6.1. “Retrieving a Service Document”.

Instance Method Summary collapse

Constructor Details

#initialize(service_uri, connection = Connection.new()) ⇒ Service

Retrieves and parses an Atom service document.

Parameters

:service_uri

The URI to the Sword Service Document.

:connection

(optional) Sword2Ruby::Connection object used to perform the operation. If not supplied, a new Connection object will be created.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/sword2ruby/service.rb', line 31

def initialize(service_uri, connection = Connection.new())
  Utility.check_argument_class('service_uri', service_uri, String)
  Utility.check_uri(service_uri)
  Utility.check_argument_class('connection', connection, Connection)
  
  
  super()

  @http = connection

  return if service_uri.empty?

  base = URI.parse(service_uri)

  rxml = nil

  res = connection.get(base, "Accept" => "application/atomsvc+xml")
 
  
  if res.is_a? Net::HTTPSuccess
    res.validate_content_type(["application/atomsvc+xml"])
    
    service = self.class.parse(res.body, base, self)

    #Update workspaces, collections and their feeds to use the Service's http connection
    set_http(connection)

    service
  else
   raise Sword2Ruby::Exception.new("Failed to do get(#{service_uri}): server returned #{res.code} #{res.message}")
  end

end

Instance Method Details

#service_document_uriObject

This method returns the URI object of the service document.



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

def service_document_uri
  base.to_s
end

#sword_max_upload_sizeObject

This method returns the integer value of the <sword:maxUploadSize> tag (usually contained in the Service Document), or 0 if it is not defined.



23
24
25
# File 'lib/sword2ruby/service.rb', line 23

def sword_max_upload_size
  Utility.find_element_integer(extensions, "sword:maxUploadSize")
end

#sword_versionObject

This method returns the string value of the <sword:version> tag (usually contained in the Service Document), or nil if it is not defined.



17
18
19
# File 'lib/sword2ruby/service.rb', line 17

def sword_version
  Utility.find_element_text(extensions, "sword:version")
end