Coder Social home page Coder Social logo

gae-pusherapp's Introduction

Google App Engine Pusherapp Wrapper

Getting started

Request pusher credentials from http://pusherapp.com

First, instantiate a pusher, using your API key

import pusherapp
pusher = pusherapp.Pusher(app_id='your-pusher-app-id',
    key='your-pusher-api-key', secret='your-pusher-secret')

Next, trigger an event

pusher['channel'].trigger('event', data={'msg': 'Hello world!'})

You probably want to run this in a taskqueue... read on for details...

Using within Google App Engine

Typical usage (e.g. using a taskqueue, see: http://code.google.com/appengine/docs/python/taskqueue/):

import pusherapp

from google.appengine.api import urlfetch
from google.appengine.api.labs import taskqueue
from google.appengine.ext import webapp

class MyWebAppRequestHandler(webapp.RequestHandler):

    def get(self):
        # ...

    def post(self):
        # ...
    
        # Trigger some event with pusherapp, using a taskqueue
        # The task will be picked up by WorkerPushRequestHandler, below
        taskqueue.add(url='/worker/push/channel/event', params={'msg': 'Hello world!'})
    
        # ...

class WorkerPushRequestHandler(webapp.RequestHandler):

    pusher_api_key = "{your-pusher-api-key}"
    pusher_app_id  = "{your-pusher-app-id}"
    pusher_secret  = "{your-pusher-secret}"

    def post(self, channel, event):

        # Construct pusher...
        pusher = pusherapp.Pusher(app_id=self.pusher_app_id,
            key=self.pusher_api_key, secret=self.pusher_secret)
    
        # Construct data from request parameters...
        data = dict([(arg, self.request.get(arg)) for arg in self.request.arguments()])
    
        # Trigger the event...
        result = pusher[channel].trigger(event, data=data)
    
        # Handle success/failure...
        if result.status_code >= 200 and result.status_code <= 299:
            self.response.headers["Content-Type"] = "text/plain"
            self.response.out.write("OK")
        else:
            self.error(result.status_code)

gae-pusherapp's People

Contributors

swinton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gae-pusherapp's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.