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

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

Instance Method Summary collapse

Constructor Details

#initialize(params, headers) ⇒ Generator

Returns a new instance of Generator.



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

def initialize(params,headers)
  @params = params
  @headers = headers
end

Instance Method Details

#generate(mode = :output) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ruby/riddl/protocols/http/generator.rb', line 14

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
    if mode == :output
      @headers['Content-Type'] = 'text/plain'
      StringIO.new('','r+b')
    else
      StringIO.new('','r+b')
    end
  end
end