Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #91 from ltworf/minorstuff
Browse files Browse the repository at this point in the history
Minorstuff
  • Loading branch information
ltworf authored Aug 17, 2018
2 parents 3e7f9f0 + 81bdaf8 commit 032eea1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 90 deletions.
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ test: lint
install:
#Install slackclient
install -d $${DESTDIR:-/}/usr/share/localslackirc/slackclient/
install -m644 slackclient/slackrequest.py $${DESTDIR:-/}/usr/share/localslackirc/slackclient/
install -m644 slackclient/exceptions.py $${DESTDIR:-/}/usr/share/localslackirc/slackclient/
install -m644 slackclient/client.py $${DESTDIR:-/}/usr/share/localslackirc/slackclient/
install -m644 slackclient/__init__.py $${DESTDIR:-/}/usr/share/localslackirc/slackclient/
Expand All @@ -37,7 +36,6 @@ dist:
localslackirc/slackclient/__init__.py \
localslackirc/slackclient/client.py \
localslackirc/slackclient/exceptions.py \
localslackirc/slackclient/slackrequest.py \
localslackirc/Makefile \
localslackirc/CHANGELOG \
localslackirc/LICENSE \
Expand Down
38 changes: 37 additions & 1 deletion slackclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,54 @@
# to the changes made since it was copied.

from .exceptions import *
from .slackrequest import SlackRequest

import json
from typing import Any, Dict, List, NamedTuple, Optional

from requests.packages.urllib3.util.url import parse_url
import requests
from ssl import SSLWantReadError
from typedload import load
from websocket import create_connection, WebSocket
from websocket._exceptions import WebSocketConnectionClosedException


class SlackRequest:
def __init__(self, proxies: Optional[Dict[str,str]] = None) -> None:
self.proxies = proxies

def do(self, token: str, request: str, post_data: Dict[str,str], timeout: Optional[float], files: Optional[Dict]):
"""
Perform a POST request to the Slack Web API
Args:
token (str): your authentication token
request (str): the method to call from the Slack API. For example: 'channels.list'
timeout (float): stop waiting for a response after a given number of seconds
post_data (dict): key/value arguments to pass for the request. For example:
{'channel': 'CABC12345'}
"""
domain = "slack.com"

url = f'https://{domain}/api/{request}'

# Set user-agent and auth headers
headers = {
'user-agent': 'localslackirc',
'Authorization': f'Bearer {token}'
}

# Submit the request
return requests.post(
url,
headers=headers,
data=post_data,
timeout=timeout,
files=files,
proxies=self.proxies
)


class Team(NamedTuple):
id: str
name: str
Expand Down
27 changes: 3 additions & 24 deletions slackclient/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,17 @@ class SlackClientError(Exception):
"""
Base exception for all errors raised by the SlackClient library
"""
def __init__(self, msg=None):
if msg is None:
# default error message
msg = "An error occurred in the SlackClient library"
def __init__(self, msg: str) -> None:
super(SlackClientError, self).__init__(msg)


class ParseResponseError(SlackClientError, ValueError):
"""
Error raised when responses to Web API methods cannot be parsed as valid JSON
"""
def __init__(self, response_body, original_exception):
super(ParseResponseError, self).__init__(
"Slack API response body could not be parsed: {0}. Original exception: {1}".format(
response_body, original_exception
)
)
self.response_body = response_body
self.original_exception = original_exception


class SlackConnectionError(SlackClientError):
def __init__(self, message='', reply=None):
def __init__(self, message='', reply=None) -> None:
super(SlackConnectionError, self).__init__(message)
self.reply = reply


class SlackLoginError(SlackClientError):
def __init__(self, message='', reply=None):
def __init__(self, message='', reply=None) -> None:
super(SlackLoginError, self).__init__(message)
self.reply = reply


class SlackNotConnected(Exception):
pass
63 changes: 0 additions & 63 deletions slackclient/slackrequest.py

This file was deleted.

0 comments on commit 032eea1

Please sign in to comment.