slack: Begin API wrapper directory

I think this will make things easier to work with overall

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-05-26 14:21:19 -04:00
parent 0892ec28e7
commit f5af3107d5
4 changed files with 26 additions and 1 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
token
*.pyc
*.sw*

5
slack/__init__.py Normal file
View File

@ -0,0 +1,5 @@
#
# Copyright 2015 (c) Anna Schumaker
#
from . import api

17
slack/api.py Normal file
View File

@ -0,0 +1,17 @@
#
# Copyright 2015 (c) Anna Schumaker
#
import json
from urllib import request
__SLACK_SERVER = "https://slack.com/api"
def call(method, **kwargs):
args = "&&".join("%s=%s" % x for x in kwargs.items())
with request.urlopen("%s/%s?%s" % (__SLACK_SERVER, method, args)) as req:
return json.loads(req.read().decode())
return {"ok" : False}
def test():
return call("api.test")["ok"]

View File

@ -1,6 +1,7 @@
#!/usr/bin/python
# Copyright 2015 (c) Anna Schumaker.
import slack
import json
import os
import sys
@ -35,7 +36,8 @@ def call_method_auth(method, args = dict()):
#
# Test connection before doing anything else
#
if call_method("api.test")["ok"] == False:
if slack.api.test() == False:
print("Connection error!")
sys.exit(1)
auth = call_method_auth("auth.test")
if auth["ok"] == False: