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:
parent
0892ec28e7
commit
f5af3107d5
|
@ -1,2 +1,3 @@
|
|||
token
|
||||
*.pyc
|
||||
*.sw*
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
#
|
||||
# Copyright 2015 (c) Anna Schumaker
|
||||
#
|
||||
|
||||
from . import api
|
|
@ -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"]
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue