Module: Testrail::CommandHelper

Included in:
Request
Defined in:
lib/testrail/command_helper.rb

Instance Method Summary collapse

Instance Method Details

#build_url(command, ids = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/testrail/command_helper.rb', line 3

def build_url(command, ids = nil)
  arg_names = Client.instance_method(command.to_sym).parameters.map(&:last).map(&:to_s)
  command = Testrail.config.server + Testrail.config.api_path + Testrail.config.version + "/" + command
  unless ids.nil?
    args = ids.shift
    if args.kind_of?(Array)
      arg_names.shift(args.size)
      args = args.join('/')
    else
      arg_names.shift
      args = args.to_s
    end
    command += '/' + args
    command += '&' + ids.each_with_index.map{ |x,i| arg_names[i] + '=' + x.to_s}.join('&') unless ids.empty?
    #ids = '/' + [ids].flatten.join('/')
    #command += ids
  end
  puts command
  command + key
end