slack: Add a wrapper for the auth API call

This module sets up the token to be used for most API calls.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-05-26 14:44:59 -04:00
parent f5af3107d5
commit 02b610e671
3 changed files with 34 additions and 10 deletions

View File

@ -3,3 +3,20 @@
#
from . import api
from . import auth
import sys
#
# Verify connection and setup team information.
#
if api.test() == False:
print("Connection error, cannot continue.")
sys.exit(1)
__auth = auth.test()
if __auth == None:
sys.exit(1)
__TEAM = __auth["team"]

16
slack/auth.py Normal file
View File

@ -0,0 +1,16 @@
#
# Copyright 2015 (c) Anna Schumaker
#
from . import api
# TODO: Move the token config file outside of code directory
__TOKEN = ""
with open("token") as f:
__TOKEN = f.read().strip()
def test():
ret = api.call("auth.test", token = __TOKEN)
if ret["ok"] == False:
print("Authentication error: %s." % ret["error"])
return None
return ret

View File

@ -4,6 +4,7 @@
import slack
import json
import os
import slack
import sys
from datetime import datetime
from urllib import request
@ -33,16 +34,6 @@ def call_method_auth(method, args = dict()):
#
# Test connection before doing anything else
#
if slack.api.test() == False:
print("Connection error!")
sys.exit(1)
auth = call_method_auth("auth.test")
if auth["ok"] == False:
sys.exit(1)
team = auth["team"]