File: discoinfo.rb

package info (click to toggle)
ruby-xmpp4r 0.5.6-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,384 kB
  • sloc: ruby: 17,382; xml: 74; sh: 12; makefile: 4
file content (211 lines) | stat: -rwxr-xr-x 4,921 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# =XMPP4R - XMPP Library for Ruby
# License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
# Website::http://xmpp4r.github.io

require 'xmpp4r/query'

module Jabber
  module Discovery
    NS_DISCO_INFO = 'http://jabber.org/protocol/disco#info'

    ##
    # Class for handling Service Discovery queries,
    # info
    # (JEP 0030)
    #
    # This <query/> may contain multiple Identity and Feature
    # elements, describing the type and the supported namespaces of
    # the service.
    class IqQueryDiscoInfo < IqQuery
      name_xmlns 'query', NS_DISCO_INFO

      ##
      # Get the queried Service Discovery node or nil
      #
      # See IqQueryDiscoItems#node for a
      # small explanation of this.
      def node
        attributes['node']
      end

      ##
      # Set the queried Service Discovery node or nil
      # val:: [String]
      def node=(val)
        attributes['node'] = val
      end

      ##
      # Set the queried Service Discovery node or nil
      # (chaining-friendly)
      # val:: [String]
      def set_node(val)
        self.node = val
        self
      end

      ##
      # Get the first identity child
      # result:: [Identity]
      def identity
        first_element('identity')
      end

      ##
      # Get list of identities
      # result:: [Array] of [Identity]
      def identities
        get_elements('identity')
      end

      ##
      # Get list of features
      # result:: [Array] of [String]
      def features
        res = []
        each_element('feature') { |feature|
          res.push(feature.var)
        }
        res
      end
    end


    ##
    # Service Discovery identity to add() to IqQueryDiscoInfo
    #
    # Please note that XEP 0030 requires both category and type to occur,
    # for a reference see: http://www.xmpp.org/registrar/disco-categories.html
    class Identity < XMPPElement
      name_xmlns 'identity', NS_DISCO_INFO

      ##
      # Initialize a new Identity
      # category:: [String] Initial category or nil
      # iname:: [String] Initial identity name or nil
      # type:: [String] Initial type or nil
      def initialize(category=nil, iname=nil, type=nil)
        super()
        set_category(category)
        set_iname(iname)
        set_type(type)
      end

      ##
      # Get the identity's category or nil
      # result:: [String]
      def category
        attributes['category']
      end

      ##
      # Set the identity's category
      #
      # Service Discovery categories should be somewhat
      # standardized by some registry, so clients may
      # represent specific categories by specific icons...
      # (see http://www.jabber.org/registrar/disco-categories.html)
      # val:: [String]
      def category=(val)
        attributes['category'] = val
      end

      ##
      # Set the identity's category (chaining-friendly)
      # val:: [String]
      def set_category(val)
        self.category = val
        self
      end

      ##
      # Get the identity's name or nil
      #
      # This has been renamed from <name/> to "iname" here
      # to keep REXML::Element#name accessible
      # result:: [String]
      def iname
        attributes['name']
      end

      ##
      # Set the identity's name
      # val:: [String]
      def iname=(val)
        attributes['name'] = val
      end

      ##
      # Set the identity's name (chaining-friendly)
      # val:: [String]
      def set_iname(val)
        self.iname = val
        self
      end

      ##
      # Get the identity's type or nil
      # result:: [String]
      def type
        attributes['type']
      end

      ##
      # Set the identity's type
      # (see http://www.jabber.org/registrar/disco-categories.html)
      # val:: [String]
      def type=(val)
        attributes['type'] = val
      end

      ##
      # Set the identity's type (chaining-friendly)
      # val:: [String]
      def set_type(val)
        self.type = val
        self
      end
    end

    ##
    # Service Discovery feature to add() to IqQueryDiscoInfo
    #
    # Please note that JEP 0030 requires var to be set,
    # for a reference see: http://www.xmpp.org/registrar/disco-features.html
    class Feature < XMPPElement
      name_xmlns 'feature', NS_DISCO_INFO

      ##
      # Create a new <feature/> element
      # var:: [String] New var
      def initialize(var=nil)
        super()
        set_var(var)
      end

      ##
      # Get the feature's var or nil
      # result:: [String]
      def var
        attributes['var']
      end

      ##
      # Set the feature's var
      #
      # This is a namespace the identity supports.
      # val:: [String]
      def var=(val)
        attributes['var'] = val
      end

      ##
      # Set the feature's var (chaining-friendly)
      # val:: [String]
      def set_var(val)
        self.var = val
        self
      end
    end
  end
end