@@ -0,0 +1,2889 @@
+#!/usr/bin/env python%0A%22%22%22Simple library for posting to Rocket.Chat via webhooks a.k.a. integrations.%22%22%22%0A%0Aimport json%0Aimport httplib%0Aimport urllib%0A%0A%0Aclass WebhookError(Exception):%0A    def __init__(self, status, message):%0A        self.status = status%0A        self.message = 'Rocket.Chat server error, code %7B0%7D: %7B1%7D'.format(status, message)%0A        super(WebhookError, self).__init__(self.message)%0A%0A%0Aclass Webhook(object):%0A    def __init__(self, server_url, token):%0A        if server_url.split('://')%5B0%5D == 'https':%0A            self.https = True%0A        else:%0A            self.https = False%0A        self.server_fqdn = server_url.split('://')%5B-1%5D.replace('/', '')%0A        self.token = token%0A%0A    def quick_post(self, text):%0A        %22%22%22Method for posting simple text messages via single hook.%22%22%22%0A        self.post(Message(text))%0A%0A    def post(self, message):%0A        %22%22%22Send your message to Rocket.Chat.%0A%0A        message argument is expected to be a pyrocketchat.Message object.%0A        If you want to just post simple text message, please use quick_post() method.%0A%0A        Raises pyrocketchat.WebhookError if response code is not 200.%22%22%22%0A%0A        assert type(message) is Message, 'Error: message is not a pyrocketchat.Message'%0A%0A        payload_dict = %7B%7D%0A        if message.text:%0A            payload_dict%5B'text'%5D = message.text%0A        if message.icon_url:%0A            payload_dict%5B'icon_url'%5D = message.icon_url%0A        if message.attachments:%0A            payload_dict%5B'attachments'%5D = message.attachments%0A        payload = 'payload=' + urllib.quote_plus(json.dumps(payload_dict))%0A        headers = %7B'Content-Type': 'application/x-www-form-urlencoded'%7D%0A%0A        if self.https:%0A            conn = httplib.HTTPSConnection(self.server_fqdn)%0A        else:%0A            conn = httplib.HTTPConnection(self.server_fqdn)%0A        conn.request('POST', '/hooks/' + self.token, payload, headers)%0A        response = conn.getresponse()%0A        if response.status != 200:%0A            error = json.loads(response.read())%0A            conn.close()%0A            raise WebhookError(response.status, error%5B'message'%5D)%0A        conn.close()%0A%0A%0Aclass Message(object):%0A    def __init__(self, text='', icon_url=None):%0A        self.text = text%0A        self.icon_url = icon_url%0A        self.attachments = %5B%5D%0A%0A    def append_text(self, text_to_append):%0A        %22%22%22Add new text to the message.%22%22%22%0A        if self.text:%0A            self.text = self.text + '%5Cn' + text_to_append%0A        else:%0A            self.text = text_to_append%0A%0A    def add_attachment(self, **kwargs):%0A        %22%22%22Add an attachment to the message.%0A%0A        As of Rocket.Chat version 0.17, valid attachment arguments are the following:%0A            * title%0A            * title_link%0A            * text%0A            * image_url%0A            * color%0A        You can have multiple attachments in a single message.%0A        %22%22%22%0A        self.attachments.append(kwargs)%0A

Move code from old repo.