18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/rest_redmine/api.rb', line 18
def self.request(action, data: {}, id: nil, method: :get)
retries ||= RestRedmine.configuration.retries
url = get_path(action, id: id)
if RestRedmine.configuration.api_key.nil?
message = "
You must set configure first.
RestRedmine.configure do |config|
config.api_key = '<api_key>'
config.server_url = '<server_url>'
end
"
raise RestRedmine::Exception.new(message)
end
response = RestClient::Request.execute(
:method => method,
:url => url,
:payload => data,
:headers => {
:accept => :json,
"X-Redmine-API-Key" => RestRedmine.configuration.api_key
},
:timeout => RestRedmine.configuration.timeout,
:open_timeout => RestRedmine.configuration.timeout
)
rescue RestRedmine::Exception => e
RestRedmine.log << e
RestRedmine.log << "REDMINE FAIL\nurl - #{url}\nparams - #{data}\nmethod - #{method}"
rescue => e
RestRedmine.log << e
RestRedmine.log << "REDMINE FAIL\nurl - #{url}\nparams - #{data}\nmethod - #{method}"
retry unless (retries -= 1).zero?
else
if response.length > 0
JSON.parse(response)
else
true
end
end
|