Class: XCAPClient::Document
- Inherits:
-
Object
- Object
- XCAPClient::Document
- Defined in:
- lib/xcapclient/document.rb
Instance Attribute Summary collapse
-
#etag ⇒ Object
The last received ETag value in a response from the server.
-
#last_response ⇒ Object
The last response received from the server.
-
#local_modified ⇒ Object
Convenient field to indicate that the document has been modified locally but it hasn’t been commited yet to the server (true then).
-
#name ⇒ Object
readonly
The name of the document as it exists in the server.
-
#parsed ⇒ Object
This attribute contains the parsed instance of the XML document after calling parse method.
-
#plain ⇒ Object
Contains the plain document fetched from the server or manually set.
-
#scope ⇒ Object
readonly
The scope of this document (:users or :global).
-
#server_modified ⇒ Object
Convenient field to indicate that the document has been modified in the server but it hasn’t been fetched so the local copy isn’t up-to-date (true then).
-
#xui ⇒ Object
readonly
The XUI this document belongs to.
Instance Method Summary collapse
-
#initialize(name, scope = nil, xui = nil) ⇒ Document
constructor
Create a new instance.
-
#parse ⇒ Object
Parse the plain XML document using Nokogiri and store it into @parsed attribute.
-
#reset ⇒ Object
Delete the local plain and parsed document and the ETag.
Constructor Details
#initialize(name, scope = nil, xui = nil) ⇒ Document
Create a new instance. name and xui are String. scope can be :users (default) or :group Symbol. xui is the user owning the document, if it’s nil then is a document owned by our user.
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/xcapclient/document.rb', line 40 def initialize(name, scope=nil, xui=nil) scope = :users unless scope @name = name @scope = scope @xui = xui # Check name. raise ConfigError, "document `name' must be a non empty string" unless String === @name && ! @name.empty? # Check scope. raise ConfigError, "document `scope' must be :users or _global" unless @scope == :users or @scope == :global end |
Instance Attribute Details
#etag ⇒ Object
The last received ETag value in a response from the server. It can be set manually.
18 19 20 |
# File 'lib/xcapclient/document.rb', line 18 def etag @etag end |
#last_response ⇒ Object
The last response received from the server. It’s a :Message object.
24 25 26 |
# File 'lib/xcapclient/document.rb', line 24 def last_response @last_response end |
#local_modified ⇒ Object
Convenient field to indicate that the document has been modified locally but it hasn’t been commited yet to the server (true then). This field must be set manually by the application if it wants to use it (for example after giving a new value to @plain or after modifyng @parsed).
30 31 32 |
# File 'lib/xcapclient/document.rb', line 30 def local_modified @local_modified end |
#name ⇒ Object (readonly)
The name of the document as it exists in the server.
6 7 8 |
# File 'lib/xcapclient/document.rb', line 6 def name @name end |
#parsed ⇒ Object
This attribute contains the parsed instance of the XML document after calling parse method.
21 22 23 |
# File 'lib/xcapclient/document.rb', line 21 def parsed @parsed end |
#plain ⇒ Object
Contains the plain document fetched from the server or manually set.
15 16 17 |
# File 'lib/xcapclient/document.rb', line 15 def plain @plain end |
#scope ⇒ Object (readonly)
The scope of this document (:users or :global).
9 10 11 |
# File 'lib/xcapclient/document.rb', line 9 def scope @scope end |
#server_modified ⇒ Object
Convenient field to indicate that the document has been modified in the server but it hasn’t been fetched so the local copy isn’t up-to-date (true then). This field must be set manually by the application if it wants to use it (for example after the SIP UA receives a NOTIFY indicating that this document has been modified in the server).
36 37 38 |
# File 'lib/xcapclient/document.rb', line 36 def server_modified @server_modified end |
#xui ⇒ Object (readonly)
The XUI this document belongs to. This allow fetching a document owner by other user (for example a icon).
12 13 14 |
# File 'lib/xcapclient/document.rb', line 12 def xui @xui end |
Instance Method Details
#parse ⇒ Object
Parse the plain XML document using Nokogiri and store it into @parsed attribute. NOTE: This method is just available if Nokogiri is installed.
63 64 65 66 67 68 69 70 |
# File 'lib/xcapclient/document.rb', line 63 def parse raise DocumentError, "cannot parse the document as the plain document doesn't exist" unless @plain begin @parsed = ::Nokogiri::XML::Document.parse(@plain, nil, "UTF-8", PARSE_OPTIONS) rescue ::Nokogiri::SyntaxError => e raise XMLParsingError, "XML parsing error: #{e.}" end end |
#reset ⇒ Object
Delete the local plain and parsed document and the ETag.
54 55 56 57 58 |
# File 'lib/xcapclient/document.rb', line 54 def reset @plain = nil @parsed = nil @etag = nil end |