OAuth refreshes keys, added project view
This commit is contained in:
43
cmdasana.py
43
cmdasana.py
@@ -6,6 +6,7 @@ import json
|
|||||||
|
|
||||||
import urwid
|
import urwid
|
||||||
import asana
|
import asana
|
||||||
|
from asana.session import AsanaOAuth2Session
|
||||||
from oauthlib.oauth2.rfc6749.errors import TokenExpiredError
|
from oauthlib.oauth2.rfc6749.errors import TokenExpiredError
|
||||||
|
|
||||||
import ui
|
import ui
|
||||||
@@ -19,25 +20,36 @@ class CmdAsana:
|
|||||||
f.close()
|
f.close()
|
||||||
self.client = asana.Client.oauth(
|
self.client = asana.Client.oauth(
|
||||||
client_id=CLIENT_ID,
|
client_id=CLIENT_ID,
|
||||||
token=token
|
client_secret=CLIENT_SECRET,
|
||||||
|
token=token,
|
||||||
|
token_updater=self.saveToken,
|
||||||
|
auto_refresh_url=AsanaOAuth2Session.token_url,
|
||||||
|
auto_refresh_kwargs={
|
||||||
|
'client_id': CLIENT_ID,
|
||||||
|
'client_secret': CLIENT_SECRET
|
||||||
|
},
|
||||||
)
|
)
|
||||||
except IOError:
|
except IOError:
|
||||||
self.getToken()
|
self.getToken()
|
||||||
|
|
||||||
try:
|
self.me = self.client.users.me()
|
||||||
self.me = self.client.users.me()
|
|
||||||
except TokenExpiredError:
|
def saveToken(self, token):
|
||||||
token = self.client.session.fetch_token(code=token['refresh_token'])
|
f = open('.oauth', 'w')
|
||||||
f = open('.oauth', 'w')
|
f.write(json.dumps(token))
|
||||||
f.write(json.dumps(token))
|
f.close()
|
||||||
f.close()
|
|
||||||
self.me = self.client.users.me()
|
|
||||||
|
|
||||||
def getToken(self):
|
def getToken(self):
|
||||||
self.client = asana.Client.oauth(
|
self.client = asana.Client.oauth(
|
||||||
client_id=CLIENT_ID,
|
client_id=CLIENT_ID,
|
||||||
client_secret=CLIENT_SECRET,
|
client_secret=CLIENT_SECRET,
|
||||||
redirect_uri='urn:ietf:wg:oauth:2.0:oob'
|
redirect_uri='urn:ietf:wg:oauth:2.0:oob',
|
||||||
|
token_updater=self.saveToken,
|
||||||
|
auto_refresh_url=AsanaOAuth2Session.token_url,
|
||||||
|
auto_refresh_kwargs={
|
||||||
|
'client_id': CLIENT_ID,
|
||||||
|
'client_secret': CLIENT_SECRET
|
||||||
|
},
|
||||||
)
|
)
|
||||||
(url, state) = self.client.session.authorization_url()
|
(url, state) = self.client.session.authorization_url()
|
||||||
try:
|
try:
|
||||||
@@ -49,9 +61,7 @@ class CmdAsana:
|
|||||||
|
|
||||||
code = sys.stdin.readline().strip()
|
code = sys.stdin.readline().strip()
|
||||||
token = self.client.session.fetch_token(code=code)
|
token = self.client.session.fetch_token(code=code)
|
||||||
f = open('.oauth', 'w')
|
self.saveToken(token)
|
||||||
f.write(json.dumps(token))
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
def myWorkspaces(self):
|
def myWorkspaces(self):
|
||||||
return self.me['workspaces']
|
return self.me['workspaces']
|
||||||
@@ -62,6 +72,8 @@ class CmdAsana:
|
|||||||
'workspace': workspace_id,
|
'workspace': workspace_id,
|
||||||
'completed_since': 'now'
|
'completed_since': 'now'
|
||||||
})
|
})
|
||||||
|
def projectTasks(self, project_id):
|
||||||
|
return self.client.tasks.find_by_project(project_id)
|
||||||
|
|
||||||
def completeTask(self, task_id):
|
def completeTask(self, task_id):
|
||||||
self.client.tasks.update(task_id, completed=True)
|
self.client.tasks.update(task_id, completed=True)
|
||||||
@@ -92,6 +104,11 @@ class CmdAsana:
|
|||||||
self.replaceBody(task_list)
|
self.replaceBody(task_list)
|
||||||
self.workspace_id = workspace_id
|
self.workspace_id = workspace_id
|
||||||
|
|
||||||
|
def showProject(self, project_id):
|
||||||
|
task_list = ui.TaskList(self.projectTasks(project_id))
|
||||||
|
self.connectTaskListSignals(task_list)
|
||||||
|
self.replaceBody(task_list)
|
||||||
|
|
||||||
def loadDetails(self, task_id):
|
def loadDetails(self, task_id):
|
||||||
task = self.client.tasks.find_by_id(task_id)
|
task = self.client.tasks.find_by_id(task_id)
|
||||||
stories = self.client.stories.find_by_task(task_id)
|
stories = self.client.stories.find_by_task(task_id)
|
||||||
|
|||||||
7
ui.py
7
ui.py
@@ -10,6 +10,7 @@ palette = [
|
|||||||
('selected workspace', 'standout,bold', ''),
|
('selected workspace', 'standout,bold', ''),
|
||||||
('header', 'bold,light green', ''),
|
('header', 'bold,light green', ''),
|
||||||
('task', 'light green', ''),
|
('task', 'light green', ''),
|
||||||
|
('section', 'white', 'dark green'),
|
||||||
('workspace', 'white', 'dark blue')
|
('workspace', 'white', 'dark blue')
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -51,7 +52,8 @@ class TaskList(urwid.ListBox):
|
|||||||
body = urwid.SimpleFocusListWalker([])
|
body = urwid.SimpleFocusListWalker([])
|
||||||
for task_widget,_ in task_widgets.contents:
|
for task_widget,_ in task_widgets.contents:
|
||||||
self.connectSignals(task_widget)
|
self.connectSignals(task_widget)
|
||||||
body.append(urwid.AttrMap(task_widget, 'task', focus_map='selected'))
|
style = 'section' if task_widget.task['name'][-1] == ':' else 'task'
|
||||||
|
body.append(urwid.AttrMap(task_widget, style, focus_map='selected'))
|
||||||
|
|
||||||
super(TaskList, self).__init__(body)
|
super(TaskList, self).__init__(body)
|
||||||
|
|
||||||
@@ -59,8 +61,9 @@ class TaskList(urwid.ListBox):
|
|||||||
task_widget = TaskEdit(task, mode=EDIT)
|
task_widget = TaskEdit(task, mode=EDIT)
|
||||||
self.connectSignals(task_widget)
|
self.connectSignals(task_widget)
|
||||||
index = self.focus_position + 1
|
index = self.focus_position + 1
|
||||||
|
style = 'section' if task['name'][-1] == ':' else 'task'
|
||||||
self.body.insert(index,
|
self.body.insert(index,
|
||||||
urwid.AttrMap(task_widget, None, focus_map='selected'))
|
urwid.AttrMap(task_widget, style, focus_map='selected'))
|
||||||
self.focus_position += 1
|
self.focus_position += 1
|
||||||
|
|
||||||
def connectSignals(self, task_widget):
|
def connectSignals(self, task_widget):
|
||||||
|
|||||||
Reference in New Issue
Block a user