-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathns1trellobase.py
53 lines (42 loc) · 1.58 KB
/
ns1trellobase.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from trello import TrelloClient, Member
from trello.exceptions import Unauthorized
import os
import sys
class NS1Base(object):
# https://trello.com/b/1diHBDGp/
SPRINT_BOARD_ID = '56b0bee08a91f6b079ba6ae9'
def __init__(self):
self.client = None
self._me = None
def check_api_key(self):
if not os.getenv('TRELLO_API_KEY') or not os.getenv('TRELLO_API_SECRET'):
raise Exception("You must define TRELLO_API_KEY and TRELLO_API_SECRET, from these: https://trello.com/app-key")
def check_oauth(self):
if not os.getenv('TRELLO_OAUTH_KEY') or not os.getenv('TRELLO_OAUTH_SECRET'):
self.create_oauth()
def create_oauth(self):
from trello import util
util.create_oauth_token()
sys.exit(0)
def init_client(self):
self.client = TrelloClient(api_key=os.getenv('TRELLO_API_KEY'),
api_secret=os.getenv('TRELLO_API_SECRET'),
token=os.getenv('TRELLO_OAUTH_KEY'),
token_secret=os.getenv('TRELLO_OAUTH_SECRET'))
# check for auth
try:
self.client.list_organizations()
except Unauthorized:
print "RECEIVED UNAUTHORIZED, RECREATING OAUTH"
self.create_oauth()
@property
def me(self):
if self._me:
return self._me
self._me = Member(self.client, 'me')
self._me.fetch()
return self._me
def boot(self):
self.check_api_key()
self.check_oauth()
self.init_client()