Ejemplo n.º 1
0
class WebhookSession(object):

    def __init__(self, config):
        self.webhook = Webhooks(config['webhook']['token'])
        self.base_url = config['webhook']['webhook']

    def start(self):
        logger.info('Session started.')

    def stop(self):
        logger.info('Session ended.')

    def fetch_head(self):
        logger.info('Fetching head track.')
        webhook_url = '{0}queues/head/'.format(self.base_url)

        return self.webhook.get(webhook_url)

    def pop_head(self, kwargs):
        logger.info('Removing current head track.')
        webhook_url = '{0}queues/head/'.format(self.base_url)

        return self.webhook.delete(webhook_url, **kwargs)

    def update_head(self, kwargs):
        logger.info('Updating current head track.')
        webhook_url = '{0}queues/head/'.format(self.base_url)

        return self.webhook.patch(webhook_url, **kwargs)
Ejemplo n.º 2
0
def hue_api_put_light(token, id_num):
    request_json = flask.request.get_json(force=True)
    print("PUT {0}/state: {1}".format(id_num, request_json))

    # Turn on
    if 'on' in request_json and request_json['on']:
        Webhooks.on()

        return flask.Response(json.dumps([{
            'success': {
                '/lights/{0}/state/on'.format(id_num): True
            }
        }]),
                              mimetype='application/json',
                              status=200)

    # Turn off
    if 'on' in request_json and not request_json['on']:
        Webhooks.off()

        return flask.Response(json.dumps([{
            'success': {
                '/lights/{0}/state/on'.format(id_num): False
            }
        }]),
                              mimetype='application/json',
                              status=200)

    # Change brightness
    if 'bri' in request_json:
        Webhooks.change_brightness(request_json['bri'])

        return flask.Response(json.dumps([{
            'success': {
                '/lights/{0}/state/bri': request_json['bri']
            }
        }]),
                              mimetype='application/json',
                              status=200)

    print("Unhandled API request: {0}".format(request_json))
    flask.abort(500)
Ejemplo n.º 3
0
 def __init__(self, config):
     self.webhook = Webhooks(config['webhook']['token'])
     self.base_url = config['webhook']['webhook']