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