class SlackClient(object):
    def __init__(self, token):
        self.token = token
        self.server = Server(self.token, False)

    @asyncio.coroutine
    def rtm_connect(self):
        try:
            yield from self.server.rtm_connect()
            return True
        except:
            return False

    @asyncio.coroutine
    def api_call(self, method, **kwargs):
        return self.server.api_call(method, **kwargs)

    @asyncio.coroutine
    def rtm_read(self):
        # in the future, this should handle some events internally i.e. channel
        # creation
        if self.server:
            json_data = yield from self.server.websocket_safe_read()
            data = []
            if json_data != '':
                for d in json_data.split('\n'):
                    data.append(json.loads(d))
            for item in data:
                self.process_changes(item)
            return data
        else:
            raise SlackNotConnected

    @asyncio.coroutine
    def rtm_send_message(self, channel, message):
        res = yield from self.server.channels.find(channel).send_message(message)
        return res

    def process_changes(self, data):
        if "type" in data.keys():
            if data["type"] == 'channel_created':
                channel = data["channel"]
                self.server.attach_channel(channel["name"], channel["id"], [])
            if data["type"] == 'im_created':
                channel = data["channel"]
                self.server.attach_channel(channel["user"], channel["id"], [])
            if data["type"] == "team_join":
                user = data["user"]
                self.server.parse_user_data([user])
            pass
 def __init__(self, token):
     self.token = token
     self.server = Server(self.token, False)