Class: Riddl::Protocols::HTTP::Generator

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, headers) ⇒ Generator

Returns a new instance of Generator.



8
9
10
11
# File 'lib/ruby/riddl/protocols/http/generator.rb', line 8

def initialize(params,headers)
  @params = params
  @headers = headers
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).



16
17
18
19
20
# File 'lib/ruby/riddl/protocols/http/generator.rb', line 16

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



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ruby/riddl/protocols/http/generator.rb', line 22

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
    StringIO.new('','r+b')
  end  
end