@classmethod
	def do_request(self, method, url, *args, **kwargs):

		auth_token = kwargs.get('token', None)
		params = kwargs.get('params', None)
		headers = kwargs.get('headers', None)
		proxy = kwargs.get('proxy', None)

		if not auth_token:
			try:
				config = ConfigParser.ConfigParser()
				config.read(os.path.expanduser('~/.do.cfg'))
				auth_token = config.get('docli', 'auth_token') or os.getenv('do_auth_token')
			except:
				auth_token = None

		if not auth_token:
			data = {'has_error':True, 'error_message':'Authentication token not provided.'}
			return data

		if headers:
			headers.update({'Authorization': 'Bearer ' + auth_token})
		else:
			headers = {'Authorization': 'Bearer ' + auth_token}

		if proxy:
			proxy = {'http': proxy}

		request_method = {'GET':requests.get, 'POST': requests.post, 'PUT': requests.put, 'DELETE': requests.delete}

		request_url = self.api_url + url

		req = request_method[method]

		try:
			res = req(request_url, headers=headers, params=params,  proxies=proxy)
		except (requests.exceptions.ConnectionError, requests.exceptions.RequestException) as e:
			data = {'has_error':True, 'error_message':e.message}
			return data

		if res.status_code == 204:
			data = {'has_error':False, 'error_message':''}
			return data

		try:
			data = res.json()
			data.update({'has_error':False, 'error_message':''})
		except __HOLE__ as e:
			msg = "Cannot read response, %s" %(e.message)
			data = {'has_error':True, 'error_message':msg}

		if not res.ok:
			msg = data['message']
			data.update({'has_error':True, 'error_message':msg})

		return data
dataset/ETHPy150Open yspanchal/docli/docli/commands/base_request.py/DigitalOcean.do_request