def main(): """ Usage: scmd (API_COMMAND | -h | -v ) [<params>] [--auth-token=<token>] Options: -h - Show this screen. -v Show version. --auth-token=<token> The authentication token which will be used to access the slack api. As an alternative you can specify it in the .slackrc or set the $SLACK_API_TOKEN environment variable. """ args = docopt.docopt(doc=main.__doc__, version='0.0.1') auth_token = None if args['API_COMMAND']: auth_token = try_to_get_auth_token(args) if not auth_token: print("Error: No authentication token available!", file=sys.stderr) exit(-1) slack_api = slackapi.SlackApi(authentication_token=auth_token) params = args['<params>'] if args['<params>'] else 'None' response = slack_api.call(args['API_COMMAND'], parameters=eval(params)) if response.is_error(): error_message = "Error occured, details: {0}" print(error_message.format(response.get_error_message()), file=sys.stderr) exit(-2) print(response.data) exit(0)
def main(): """ Usage: sls [--auth-token=<token>] sls -h | --help sls -v | --version Options: -h --help Show this screen. -v --version Show version. --auth-token=<token> The authentication token which will be used to access the slack api. As an alternative you can specify it in the .slackyrc or set the $SLACK_API_TOKEN environment variable. """ args = docopt.docopt(doc=main.__doc__, version='0.0.1') auth_token = try_to_get_auth_token(args) if not auth_token: print("Error: No authentication token available!", file=sys.stderr) sys.exit(-1) else: SlackShell(auth_token).cmdloop() sys.exit(0)
def test_returns_token_found_in_environment(self): auth_token = "XoXa-MyAuthTOken123LooksLikeThis1" os.environ['SLACK_API_TOKEN'] = auth_token self.assertEqual(auth_token, try_to_get_auth_token({}))
def test_returns_none_because_no_auth_token_was_found_in_environment(self): self.assertEqual(None, try_to_get_auth_token({}))
def test_returns_none_because_the_contents_of_the_environement_var_is_empty(self): os.environ['SLACK_API_TOKEN'] = '' self.assertEqual(None, try_to_get_auth_token({}))
def test_returns_token_found_in_args(self): auth_token = "XoXa-MyAuthTOken123LooksLikeThis1" args = {'--auth-token': auth_token} self.assertEqual(auth_token, try_to_get_auth_token(args))