Class: XCAPClient::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/xcapclient/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auid, data = {}) ⇒ Application

:nodoc:

Raises:



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/xcapclient/application.rb', line 7

def initialize(auid, data={})  #:nodoc:

  @auid = auid

  # Check application data.
  raise ConfigError, "application `data' must be a hash ('#{@auid}')" unless (Hash === data)

  @xmlns = data[:xmlns].freeze
  @mime_type = data[:mime_type].freeze

  # Check auid.
  raise ConfigError, "application `auid' must be a non empty string ('#{@auid}')" unless String === @auid && ! @auid.empty?

  # Check xmlns.
  raise ConfigError, "application `xmlns' must be a non empty string ('#{@auid}')" unless String === @xmlns && ! @xmlns.empty?

  # Check mime-type.
  raise ConfigError, "application `mime_type' must be a non empty string ('#{@auid}')" unless String === @mime_type && ! @mime_type.empty?

  # Create the _documents_ Array.
  @documents = []

end

Instance Attribute Details

#auidObject (readonly)

Returns the value of attribute auid.



5
6
7
# File 'lib/xcapclient/application.rb', line 5

def auid
  @auid
end

#document_nameObject (readonly)

Returns the value of attribute document_name.



5
6
7
# File 'lib/xcapclient/application.rb', line 5

def document_name
  @document_name
end

#mime_typeObject (readonly)

Returns the value of attribute mime_type.



5
6
7
# File 'lib/xcapclient/application.rb', line 5

def mime_type
  @mime_type
end

#scopeObject (readonly)

Returns the value of attribute scope.



5
6
7
# File 'lib/xcapclient/application.rb', line 5

def scope
  @scope
end

#xmlnsObject (readonly)

Returns the value of attribute xmlns.



5
6
7
# File 'lib/xcapclient/application.rb', line 5

def xmlns
  @xmlns
end

Instance Method Details

#add_document(name, scope = nil, xui = nil) ⇒ Object

Creates a new XCAPClient::Document for this application with name document_name, scope scope and xui xui. scope can be :users (default) or :global Symbol. If xui is nil then the documents belongs to our user.

Raises:



50
51
52
53
54
55
56
# File 'lib/xcapclient/application.rb', line 50

def add_document(name, scope=nil, xui=nil)
  scope = :users  unless scope
  raise DocumentError, "document '#{name}' with scope '#{scope} and xui '#{xui}' already exists"  if document(name, scope, xui)
  @documents << document = Document.new(name, scope, xui)

  return document
end

#document(name = nil, scope = nil, xui = nil) ⇒ Object

Get the XCAPClient::Document with name name, scope scope (:users or :global) belonging to user xui. If name is nil then the first available document is fetched (careful). If scope is not set then it’s :users by default. If xui is nil then it’s a document owned by us.



34
35
36
37
38
39
40
41
# File 'lib/xcapclient/application.rb', line 34

def document(name=nil, scope=nil, xui=nil)
  scope = :users  unless scope
  if name
    @documents.find { |doc| doc.name == name and doc.scope == scope and doc.xui == xui }
  else
    @documents.first
  end
end

#documentsObject

Get an Array containing all the documents created for this application.



44
45
46
# File 'lib/xcapclient/application.rb', line 44

def documents
  @documents
end