##// END OF EJS Templates
rcextensions: helpers fix, non json data should use params.
dan -
r4158:57895576 default
parent child Browse files
Show More
@@ -1,49 +1,49 b''
1 1 # -*- coding: utf-8 -*-
2 2 # Copyright (C) 2016-2019 RhodeCode GmbH
3 3 #
4 4 # This program is free software: you can redistribute it and/or modify
5 5 # it under the terms of the GNU Affero General Public License, version 3
6 6 # (only), as published by the Free Software Foundation.
7 7 #
8 8 # This program is distributed in the hope that it will be useful,
9 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 11 # GNU General Public License for more details.
12 12 #
13 13 # You should have received a copy of the GNU Affero General Public License
14 14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 15 #
16 16 # This program is dual-licensed. If you wish to learn more about the
17 17 # RhodeCode Enterprise Edition, including its added features, Support services,
18 18 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 19
20 20 """
21 21 us in hooks::
22 22
23 23 from .helpers import http_call
24 24 # returns response after making a POST call
25 25 response = http_call.run(url=url, json_data={"key": "val"})
26 26
27 27 # returns response after making a GET call
28 28 response = http_call.run(url=url, params={"key": "val"}, method='get')
29 29
30 30 """
31 31
32 32 from rhodecode.integrations.types.base import requests_retry_call
33 33
34 34
35 35 def run(url, json_data=None, params=None, method='post'):
36 36 requests_session = requests_retry_call()
37 37 requests_session.verify = True # Verify SSL
38 38 method_caller = getattr(requests_session, method, 'post')
39 39
40 40 timeout = 60
41 41 if json_data:
42 42 resp = method_caller(url, json=json_data, timeout=timeout)
43 43 elif params:
44 resp = method_caller(url, params=json_data, timeout=timeout)
44 resp = method_caller(url, params=params, timeout=timeout)
45 45 else:
46 46 raise AttributeError('Provide json_data= or params= in function call')
47 47 resp.raise_for_status() # raise exception on a failed request
48 48 return resp
49 49
General Comments 0
You need to be logged in to leave comments. Login now