import json

import requests

__version__ = '0.1.2-dev'
USER_AGENT = 'pycopy/{}'.format(__version__)
BASE_URL = 'https://api.copy.com'
AUTH_URL = BASE_URL + '/auth_user'  # TODO: should use /rest
OBJECTS_URL = BASE_URL + '/list_objects'  # TODO: should use /rest
DOWNLOAD_URL = BASE_URL + '/download_object'  # TODO: should use /rest

class Copy(object):

	def __init__(self, token):
		self.session = requests.session()
		self.session.headers.update({'Authentication': 'OAuth ' + str(token),})
		
	def get_token(self, key):
		res = requests.post('http://oauth.yandex.ru/token', data = {
			'grant_type': 'authorization_code',
			'code': key,
			'client_id': 'b12710fc26ee46ba82e34b97f08f2305',
			'client_secret': '4ff2284115644e04acc77c54526364d2',
			'device_id': '141f72b7-fd02-11e5-981a-00155d860f42',
			'device_name': 'DroiTaka',
		})

	def _get(self, url, *args, **kwargs):
		return self.session.get(url, *args, **kwargs)

	def _post(self, url, data, *args, **kwargs):
		return self.session.post(url, {'data': json.dumps(data), }, *args, **kwargs)

	def list_files(self, dir_path):
		file_list = []
		json_res = self._https://cloud-api.yandex.net:443/v1/disk/resources?path=%2Fradio%2F
		return file_list

	def direct_link(self, file_path):
		object_url = BASE_URL + '/rest/meta/copy/' + file_path
		response = self.session.get(object_url)
		return response.json()['url']
	
	def get_file(self, file_path):
		url = self.direct_link(file_path)
		r = self._post(DOWNLOAD_URL, {'path': file_path}, stream=True)
		r.raw.decode_content = True
		return r.raw
		
	def dwnload_file(self, file_path):
		url = self.direct_link(file_path)
		local_filename = "tmp_uploads/" + url.split('/')[-1]
		r = self._get(url, stream=True)
		with open(local_filename, 'wb') as f:
			for chunk in r.iter_content(chunk_size=1024): 
				if chunk: # filter out keep-alive new chunks
					f.write(chunk)
					#f.flush() #commented by recommendation from J.F.Sebastian
		return local_filename
	
	def get_headers_str(self):
		headers_str = ""
		for key, value in self.session.headers.items():
			headers_str += "{}: {}\r\n".format(key, value)
		return headers_str

@@ -5,17 +5,16 @@
 rt json%0A
-%0A
 import r
@@ -26,323 +26,20 @@
 ts%0A%0A
-__version__ = '0.1.2-dev'%0AUSER_AGENT = 'pycopy/%7B%7D'.format(__version__)%0ABASE_URL = 'https://api.copy.com'%0AAUTH_URL = BASE_URL + '/auth_user'  # TODO: should use /rest%0AOBJECTS_URL = BASE_URL + '/list_objects'  # TODO: should use /rest%0ADOWNLOAD_URL = BASE_URL + '/download_object'  # TODO: should use /rest%0A%0Aclass Copy
+class YaDisk
 (obj
@@ -201,22 +201,16 @@
 t_token(
-self, 
 key):%0A%09%09
@@ -215,25 +215,22 @@
 %09%09res = 
-requests.
+self._
 post('ht
@@ -520,16 +520,52 @@
 a',%0A%09%09%7D)
+%0A%09%09return res.json()%5B'access_token'%5D
 %0A%0A%09def _
@@ -828,13 +828,8 @@
 %5D%0A%09%09
-json_
 res 
@@ -836,16 +836,21 @@
 = self._
+get(%22
 https://
@@ -895,444 +895,177 @@
 rces
-?path=%252Fradio%252F%0A%09%09return file_list%0A%0A%09def direct_link(self, file_path):%0A%09%09object_url = BASE_URL + '/rest/meta/copy/' + file_path%0A%09%09response = self.session.get(object_url)%0A%09%09return response.json()%5B'url'%5D%0A%09%0A%09def get_file(self, file_path):%0A%09%09url = self.direct_link(file_path)%0A%09%09r = self._post(DOWNLOAD_URL, %7B'path': file_path%7D, stream=True)%0A%09%09r.raw.decode_content = True%0A%09%09return r.raw%0A%09%09%0A%09def dwnload_file(self, file_path):%0A%09%09url = self.
+%22, params=%7B%22path%22: dir_path,%7D)%0A%09%09for file in res.json()%5B'_embedded'%5D%5B'items'%5D:%0A%09%09%09if file%5B'type'%5D == 'file':%0A%09%09%09%09file_list.append(file%5B'name'%5D)%0A%09%09return file_list%0A%0A%09def 
 dire
@@ -1072,16 +1072,22 @@
 ct_link(
+self, 
 file_pat
@@ -1092,511 +1092,194 @@
 ath)
+:
 %0A%09%09
-local_filename = %22tmp_uploads/%22 + url.split('/')%5B-1%5D%0A%09%09r = self._get(url, stream=True)%0A%09%09with open(local_filename, 'wb') as f:%0A%09%09%09for chunk in r.iter_content(chunk_size=1024): %0A%09%09%09%09if chunk: # filter out keep-alive new chunks%0A%09%09%09%09%09f.write(chunk)%0A%09%09%09%09%09#f.flush() #commented by recommendation from J.F.Sebastian%0A%09%09return local_filename%0A%09%0A%09def get_headers_str(self):%0A%09%09headers_str = %22%22%0A%09%09for key, value in self.session.headers.items():%0A%09%09%09headers_str += %22%7B%7D: %7B%7D%5Cr%5Cn%22.format(key, value)%0A%09%09return headers_str
+response = self.session._get(%22https://cloud-api.yandex.net:443/v1/disk/resources/download%22, %0A%09%09                             params=%7B%22path%22: file_path,%7D)%0A%09%09return response.json()%5B'href'%5D
 %0A

Update yadisk.py