api
This commit is contained in:
parent
d4409a0411
commit
a5e68aeaaa
1 changed files with 13 additions and 10 deletions
|
@ -52,11 +52,11 @@ class Client(object):
|
||||||
with open(config) as f:
|
with open(config) as f:
|
||||||
self._config = json.load(f)
|
self._config = json.load(f)
|
||||||
else:
|
else:
|
||||||
self.config = config
|
self._config = config
|
||||||
self.api = API(self._config['url'], media_cache=self.media_cache())
|
self.api = API(self._config['url'], media_cache=self.media_cache())
|
||||||
|
|
||||||
if 'username' in self._config:
|
if 'username' in self._config:
|
||||||
r = self.api.login(username=self._config['username'], password=self._config['password'])
|
r = self.api.signin(username=self._config['username'], password=self._config['password'])
|
||||||
if r['status']['code'] == 200:
|
if r['status']['code'] == 200:
|
||||||
self.user = r['data']['user']
|
self.user = r['data']['user']
|
||||||
else:
|
else:
|
||||||
|
@ -148,6 +148,7 @@ class Client(object):
|
||||||
filename = filename.decode('utf-8')
|
filename = filename.decode('utf-8')
|
||||||
if not filename.startswith('._') and not filename in ('.DS_Store', ):
|
if not filename.startswith('._') and not filename in ('.DS_Store', ):
|
||||||
file_path = os.path.join(dirpath, filename)
|
file_path = os.path.join(dirpath, filename)
|
||||||
|
if os.path.exists(file_path):
|
||||||
files.append(file_path)
|
files.append(file_path)
|
||||||
self.scan_file(file_path)
|
self.scan_file(file_path)
|
||||||
|
|
||||||
|
@ -295,8 +296,8 @@ class API(object):
|
||||||
self.media_cache = default_media_cache
|
self.media_cache = default_media_cache
|
||||||
|
|
||||||
self.url = url
|
self.url = url
|
||||||
r = self._request('apidoc', {})
|
r = self._request('api', {'docs': True})
|
||||||
self._doc = r['data']['actions']
|
self._properties = r['data']['actions']
|
||||||
self._actions = r['data']['actions'].keys()
|
self._actions = r['data']['actions'].keys()
|
||||||
for a in r['data']['actions']:
|
for a in r['data']['actions']:
|
||||||
self._add_action(a)
|
self._add_action(a)
|
||||||
|
@ -314,11 +315,12 @@ class API(object):
|
||||||
else:
|
else:
|
||||||
kw = None
|
kw = None
|
||||||
return self._request(action, kw)
|
return self._request(action, kw)
|
||||||
method.__doc__ = self._doc[action]
|
method.__doc__ = self._properties[action]['doc']
|
||||||
method.func_name = str(action)
|
method.func_name = str(action)
|
||||||
self._add_method(method, action)
|
self._add_method(method, action)
|
||||||
|
|
||||||
def _json_request(self, url, form):
|
def _json_request(self, url, form):
|
||||||
|
result = {}
|
||||||
try:
|
try:
|
||||||
request = urllib2.Request(url)
|
request = urllib2.Request(url)
|
||||||
request.add_header('User-agent', 'pandora_client/%s' % __version__)
|
request.add_header('User-agent', 'pandora_client/%s' % __version__)
|
||||||
|
@ -347,9 +349,10 @@ class API(object):
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
if result:
|
||||||
with open('/tmp/error.html', 'w') as f:
|
with open('/tmp/error.html', 'w') as f:
|
||||||
f.write(result)
|
f.write(str(result))
|
||||||
os.system('firefox /tmp/error.html')
|
webbrowser.open_new_tab('/tmp/error.html')
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def _request(self, action, data=None):
|
def _request(self, action, data=None):
|
||||||
|
|
Loading…
Reference in a new issue