Class: Riddl::Protocols::XMPP::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/riddl/protocols/xmpp/generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(what, params, headers, ack = false) ⇒ Generator

Returns a new instance of Generator.



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ruby/riddl/protocols/xmpp/generator.rb', line 58

def initialize(what,params,headers,ack=false)
  @params = params
  @stanza = Stanza.new
  @node = XML::Smart::Dom::Element.new(@stanza)
  if what.is_a?(Fixnum)
    @node.add('ok').namespaces.add(nil,XR_NS)
  else
    @node.add('operation',what,:ack=>ack).namespaces.add(nil,XR_NS)
  end
  headers.each do |k,v|
    @node.add('header',v,:name => k).namespaces.add(nil,XR_NS)
  end
end

Class Method Details

.escape(s) ⇒ Object

Performs URI escaping so that you can construct proper query strings faster. Use this rather than the cgi.rb version since it’s faster. (%20 instead of + for improved standards conformance).



75
76
77
78
79
# File 'lib/ruby/riddl/protocols/xmpp/generator.rb', line 75

def self.escape(s)
  s.to_s.gsub(/([^a-zA-Z0-9_.-]+)/n) {
    '%'+$1.unpack('H2'*$1.size).join('%').upcase
  }
end

Instance Method Details

#generate(mode = :output) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/ruby/riddl/protocols/xmpp/generator.rb', line 81

def generate(mode=:output)
  if @params.is_a?(Array) && @params.length == 1
    body(@params[0],mode)
  elsif @params.class == Riddl::Parameter::Simple || @params.class == Riddl::Parameter::Complex
    body(@params,mode)
  elsif @params.is_a?(Array) && @params.length > 1
    multipart(mode)
  else
    @stanza
  end  
end