Exemple #1
0
def post(config, path, uuid):
    headers = {'Accept': 'application/json'}
    parsed_url = urlparse.urlparse(config['tunnel_url'])
    if parsed_url.scheme == 'http':
        conn_class = httplib.HTTPConnection
    else:
        conn_class = httplib.HTTPSConnection
    conn = conn_class(parsed_url.netloc)

    if isinstance(path, basestring):
        try:
            with open(path, 'r') as f:
                conn.request('POST', '/post/' + uuid, f, headers)
        except IOError:
            conn.request('POST', '/post/' + uuid, 'CLUTCH404DOESNOTEXIST',
                headers)
    else:
        conn.request('POST', '/post/' + uuid, json.dumps(path), headers)

    response = conn.getresponse()
    raw_data = response.read()
    conn.close()
    return json.loads(raw_data)
Exemple #2
0
def send_reload_message(config, filename, app_slug, **kwargs):
    headers = kwargs.get('headers', {})
    headers.update({
        'Content-Type': 'application/json',
        'Accept': 'application/json',
    })
    parsed_url = urlparse.urlparse(config['tunnel_url'])
    if parsed_url.scheme == 'http':
        conn_class = httplib.HTTPConnection
    else:
        conn_class = httplib.HTTPSConnection
    conn = conn_class(parsed_url.netloc)
    print filename
    data = json.dumps({
        'password': config['password'],
        'message': {'changed_file': filename},
    })
    path = '/event/%s/%s/' % (config['username'], app_slug)
    conn.request('POST', path, data, headers)
    response = conn.getresponse()
    raw_data = response.read()
    conn.close()
    return raw_data