Exemplo n.º 1
0
def create_message():
    msgdct  = flask.json.loads(request.data)

    if not 'user' in flask.session:
        return unauthorized()

    user = flask.session['user']

    if user != msgdct['user']:
        return bad_request("invalid user")

    msgdct['created'] = datetime.datetime.now()
    msgdct['tags'] = model.Message.extract_tags(msgdct['text'])
    msgdct['mentions'] = model.Message.extract_mentions(msgdct['text'])
    msgdct['timeline'] = user

    status, msg = model.Message.from_dict(msgdct)

    if not status:
        return bad_request(msg)

    msg.save()
    try:
        pshb.publish(HUB_URL, get_domain() + "/atom/messages/from/" + user + "/")
    except Exception, ex:
        app.logger.error("error sending ping to pubsubhubbub", ex)
Exemplo n.º 2
0
def create_message(session_username):
    msgdct  = flask.json.loads(request.data)
    username = msgdct['username']

    if session_username == username:
        msg = msgdct['msg']
        timestamp = int(time.time())

        message = model.Message(
            username=username,
            owner=username,
            msg=msg,
            timestamp=timestamp)

        message.put()

        try:
            feed_url = get_domain(request) + "/api/msgs/" + username + ".xml"
            app.logger.info("sending ping to pshb from feed %s" % feed_url)
            pshb.publish(settings.HUB_URL, feed_url)
        except pshb.PublishError as error:
            app.logger.error("error sending ping to pubsubhubbub %s" % str(error))

        return flask.jsonify(**message.toJSON())
    else:
        return status_response(403, ok=False, reason="unauthorized")
Exemplo n.º 3
0
def create_message():
    msgdct = flask.json.loads(request.data)

    if not 'user' in flask.session:
        return unauthorized()

    user = flask.session['user']

    if user != msgdct['user']:
        return bad_request("invalid user")

    msgdct['created'] = datetime.datetime.now()
    msgdct['tags'] = model.Message.extract_tags(msgdct['text'])
    msgdct['mentions'] = model.Message.extract_mentions(msgdct['text'])
    msgdct['timeline'] = user

    status, msg = model.Message.from_dict(msgdct)

    if not status:
        return bad_request(msg)

    msg.save()
    try:
        pshb.publish(HUB_URL,
                     get_domain() + "/atom/messages/from/" + user + "/")
    except Exception, ex:
        app.logger.error("error sending ping to pubsubhubbub", ex)
 def testBatchSizeLimit(self):
     old = pubsubhubbub_publish.URL_BATCH_SIZE
     try:
         pubsubhubbub_publish.URL_BATCH_SIZE = 2
         pubsubhubbub_publish.publish(self.hub + "/batch", [self.feed, self.feed2, self.feed3])
     finally:
         pubsubhubbub_publish.URL_BATCH_SIZE = old
     self.assertEquals(2, REQUESTS)
 def testBatchSizeLimit(self):
     old = pubsubhubbub_publish.URL_BATCH_SIZE
     try:
         pubsubhubbub_publish.URL_BATCH_SIZE = 2
         pubsubhubbub_publish.publish(self.hub + '/batch',
                                      [self.feed, self.feed2, self.feed3])
     finally:
         pubsubhubbub_publish.URL_BATCH_SIZE = old
     self.assertEquals(2, REQUESTS)
Exemplo n.º 6
0
Arquivo: main.py Projeto: mcaudy/tubes
def create_notice_json(request, notice):
    notice.uid = str(uuid.uuid4())
    notice.creation = time.time()
    notices[notice.uid] = notice
    stream.append(notice)

    author = notice.author
    if author not in user_notices:
        user_notices[author] = []

    user_notices[author].append(notice)

    pshb.publish('http://localhost:8080/', DOMAIN + "atom/stream/" + author)
    return notice.to_json()
Exemplo n.º 7
0
class PubSubHubBubHandler(yagi.handler.BaseHandler):
    CONFIG_SECTION = "hub"
    AUTO_ACK = True

    def _topic_url(self, key):
        host = yagi.config.get('event_feed', 'feed_host') or '127.0.0.1'
        port = yagi.config.get('event_feed', 'port', default=80)
        if yagi.config.get_bool('event_feed', 'use_https'):
            scheme = 'https'
        else:
            scheme = 'http'
        return '%s://%s:%s/%s' % (scheme, host, port, key)

    def _hub_url(self):
        host = self.config_get('host')
        port = self.config_get('port', default='80')
        scheme = 'https' if self.config_getbool('use_https') else 'http'
        return "%s://%s:%s" % (scheme, host, port)

    def handle_messages(self, messages, env):
        host = self._hub_url()
        topics = {}
        # Compile the list of updated topic urls
        for payload in self.iterate_payloads(messages, env):
            try:
                event_type = payload['event_type']
                if not event_type in topics:
                    topics[event_type] = self._topic_url(event_type)
            except KeyError, e:
                LOG.error('Malformed Notification: %s' % payload)
                LOG.exception(e)

        for event_type, topic in topics.iteritems():
            try:
                LOG.info('Publishing topic %s to %s' % (topic, host))
                pubsubhubbub_publish.publish(host, topic)
            except pubsubhubbub_publish.PublishError, e:
                LOG.exception('Publish failed:\n%s' % e)
 def testList(self):
     pubsubhubbub_publish.publish(self.hub + '/multiple',
                                  [self.feed, self.feed2, self.feed3])
 def testMultiple(self):
     pubsubhubbub_publish.publish(self.hub + '/multiple', self.feed,
                                  self.feed2, self.feed3)
 def testSingle(self):
     pubsubhubbub_publish.publish(self.hub + '/single', self.feed)
     self.assertEquals(1, REQUESTS)
 def testIterable(self):
     pubsubhubbub_publish.publish(self.hub + '/multiple',
                                  iter([self.feed, self.feed2, self.feed3]))
Exemplo n.º 12
0
def ping(args):
    import pubsubhubbub_publish as pubsub
    pubsub.publish('http://pubsubhubbub.appspot.com/publish', settings.FEED_URL)
 def testIterable(self):
     pubsubhubbub_publish.publish(self.hub + "/multiple", iter([self.feed, self.feed2, self.feed3]))
 def testList(self):
     pubsubhubbub_publish.publish(self.hub + "/multiple", [self.feed, self.feed2, self.feed3])
 def testMultiple(self):
     pubsubhubbub_publish.publish(self.hub + "/multiple", self.feed, self.feed2, self.feed3)
 def testSingle(self):
     pubsubhubbub_publish.publish(self.hub + "/single", self.feed)
     self.assertEquals(1, REQUESTS)