Class: Jabber::Bosh::Authentication::NonSASL::Query
- Inherits:
-
Object
- Object
- Jabber::Bosh::Authentication::NonSASL::Query
- Defined in:
- lib/jabber4r/bosh/authentication/non_sasl.rb
Constant Summary collapse
- MECHANISMS =
[:plain, :digest].freeze
Instance Attribute Summary collapse
-
#jid ⇒ Object
readonly
Returns the value of attribute jid.
-
#mechanism ⇒ Object
readonly
Returns the value of attribute mechanism.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#stream_id ⇒ Object
readonly
Returns the value of attribute stream_id.
Instance Method Summary collapse
-
#digest? ⇒ Boolean
Public: Is NonSASL object is for digest authentication.
-
#dump ⇒ Object
(also: #to_xml)
Public: Create XML string from NonSASL object.
-
#initialize(jid, password, options = {}) ⇒ Query
constructor
Public: Creates new Non-SASL authentication object.
-
#plain? ⇒ Boolean
Public: Is NonSASL object is for plain authentication.
-
#to_ox ⇒ Object
Public: Create Ox::Element from NonSASL object.
Constructor Details
#initialize(jid, password, options = {}) ⇒ Query
Public: Creates new Non-SASL authentication object
jid - [Jabber::JID|String] the jid of jabber server user password - String the user password options - Hash the authentication options (default: Empty hash)
:stream_id - String the stream identifier (authid)
:mechanism - Symbol the name of mechnism to use
Examples
non_sasl = Jabber::Protocol::Authentication::NonSASL.new(“strech@localhost/res-1”, “my-pass-phrase”) non_sasl.plain? # => true non_sasl.to_xml # =>
<iq type=“set” id=“…”>
<query xmlns="jabber:iq:auth">
<username>strech</username>
<password>my-pass-phrase</password>
<resource>res-1</resource>
</query>
</iq>
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/jabber4r/bosh/authentication/non_sasl.rb', line 120 def initialize(jid, password, = {}) raise TypeError, "Class(Jabber::JID) or Class(String) expected," + " but #{jid.class} was given" unless jid.is_a?(Jabber::JID) || jid.is_a?(String) @jid = jid.is_a?(Jabber::JID) ? jid : Jabber::JID.new(jid) @password = password @mechanism = .fetch(:mechanism, :plain) @stream_id = .fetch(:stream_id) if digest? raise ArgumentError, "Unknown authentication mechanism '#{mechanism}'," + " available is [#{MECHANISMS * ", "}]" unless MECHANISMS.include?(mechanism) end |
Instance Attribute Details
#jid ⇒ Object (readonly)
Returns the value of attribute jid.
96 97 98 |
# File 'lib/jabber4r/bosh/authentication/non_sasl.rb', line 96 def jid @jid end |
#mechanism ⇒ Object (readonly)
Returns the value of attribute mechanism.
97 98 99 |
# File 'lib/jabber4r/bosh/authentication/non_sasl.rb', line 97 def mechanism @mechanism end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
96 97 98 |
# File 'lib/jabber4r/bosh/authentication/non_sasl.rb', line 96 def password @password end |
#stream_id ⇒ Object (readonly)
Returns the value of attribute stream_id.
97 98 99 |
# File 'lib/jabber4r/bosh/authentication/non_sasl.rb', line 97 def stream_id @stream_id end |
Instance Method Details
#digest? ⇒ Boolean
Public: Is NonSASL object is for digest authentication
Returns boolean
146 147 148 |
# File 'lib/jabber4r/bosh/authentication/non_sasl.rb', line 146 def digest? mechanism == :digest end |
#dump ⇒ Object Also known as: to_xml
Public: Create XML string from NonSASL object
Returns String
153 154 155 |
# File 'lib/jabber4r/bosh/authentication/non_sasl.rb', line 153 def dump Ox.dump(send mechanism) end |
#plain? ⇒ Boolean
Public: Is NonSASL object is for plain authentication
Returns boolean
139 140 141 |
# File 'lib/jabber4r/bosh/authentication/non_sasl.rb', line 139 def plain? mechanism == :plain end |
#to_ox ⇒ Object
Public: Create Ox::Element from NonSASL object
Returns Ox::Element
161 162 163 |
# File 'lib/jabber4r/bosh/authentication/non_sasl.rb', line 161 def to_ox send(mechanism) end |