Class: Testrail::Request

Inherits:
Object
  • Object
show all
Extended by:
CommandHelper
Includes:
HTTParty
Defined in:
lib/testrail/deprecated/request.rb

Class Method Summary collapse

Methods included from CommandHelper

build_url

Class Method Details

.get(*args) ⇒ Object



12
13
14
# File 'lib/testrail/deprecated/request.rb', line 12

def self.get(*args)
  request(:get, *args)
end

.log_error(error, message) ⇒ Object



40
41
42
43
44
45
# File 'lib/testrail/deprecated/request.rb', line 40

def self.log_error(error, message)
  unless Testrail.logger.nil?
    Testrail.logger.error message
    Testrail.logger.error error
  end
end

.parse_args(*args) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/testrail/deprecated/request.rb', line 47

def self.parse_args(*args)
  opts = args.last.instance_of?(Hash) ? args.pop : {}
  opts[:headers] = opts[:headers] ? Testrail.config.headers.merge(opts[:headers]) : Testrail.config.headers
  command = args.shift
  ids = args.empty? ? nil : args
  [command, ids, opts]
end

.post(*args) ⇒ Object



16
17
18
# File 'lib/testrail/deprecated/request.rb', line 16

def self.post(*args)
  request(:post, *args)
end

.request(method, *args) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/testrail/deprecated/request.rb', line 22

def self.request(method, *args)
  command, ids, opts = parse_args(*args)
  url = build_url(command, ids)
  attempts = 0
  begin
    response = Testrail::Response.new(HTTParty.send(method, url, opts))
  rescue TimeoutError => error
    attempts += 1
    retry if attempts < 3
    log_error error, "Timeout connecting to #{method.to_s.upcase} #{url}"
    raise error
  rescue Exception => error
    log_error error, 'Unexpected exception intercepted calling TestRail'
    raise error
  end
  response
end