Skip to content

Instantly share code, notes, and snippets.

View nicholasareed's full-sized avatar

Nicholas Reed nicholasareed

View GitHub Profile
@nicholasareed
nicholasareed / gist:1463073
Created December 11, 2011 22:09
PHP POST Authentication
<?php
// Get token_secret from Settings page
$inbox_hooks_access_token = 'secret_token_here'
// Get the given (POSTed) digest
$headers = getallheaders();
if(!isset($headers['X-InboxHooks-Post-Auth'])){
header('HTTP/1.1 401 Unauthorized');
echo "Failed authentication, no X-InboxHooks-Post-Auth was present";
@nicholasareed
nicholasareed / gist:1463469
Created December 11, 2011 23:27
Python POST Authentication
import hmac
# Get token_secret from Settings page
inbox_hooks_access_token = 'secret_token_here'
hmac_hexdigest = hmac.new(inbox_hooks_access_token, request.raw_post_body).hexdigest()
if hmac_hexdigest == request.headers['X-InboxHooks-Post-Auth']:
return True
return False
@nicholasareed
nicholasareed / gist:1463662
Created December 12, 2011 00:11
JSON sample expanded return
{
"view":"cv",
"to_address":[
"to_address@example.com",
"to_address_2@example.com"
],
"from_address":"no-reply@example.com",
"cc_address":[
"cc1@example.com",
"cc2@example.com"
@nicholasareed
nicholasareed / gist:1463981
Created December 12, 2011 01:11
PHP Set JSON Response Header
<?php
header('Content-Type: application/json');
echo json_encode($key_pairs_here);
exit;
?>
@nicholasareed
nicholasareed / gist:1463991
Created December 12, 2011 01:13
PHP Set HTML Response Header
<?php
header('Content-Type: text/html');
echo $html_is_here;
exit;
?>
@nicholasareed
nicholasareed / gist:1464015
Created December 12, 2011 01:17
sidebar border CSS example
div.ih_cv_sidebar div {
border:red;
}
@nicholasareed
nicholasareed / gist:1464055
Created December 12, 2011 01:24
PHP Sample Simple Integration
<?php
// Do Authentication
// - see Important Notes in Docs
// Get raw POST data
$raw_post = @file_get_contents('php://input');
// json_decode into an Array
$details = json_decode($raw_post);
@nicholasareed
nicholasareed / gist:1464233
Created December 12, 2011 01:56
Example Custom HTML Nested in DIVs
<div id="ih_cv_sidebar">
<div class="ih_row" ih_row_num="1">
HTML from Webhook #1 goes here
</div>
<div class="ih_row" ih_row_num="2">
HTML from Webhook #2 goes here
</div>
</div>
@nicholasareed
nicholasareed / gist:1465296
Created December 12, 2011 06:04
Sample POST request body
{"view":"cv","to_address":["to_address@example.com"],"from_address":"no-reply@example.com","cc_address":[],"subject":"This is the subject of the email","thread_id":"1342f5223ss9028e1710","date_received":"Sun, Dec 11, 2011 at 2:51 PM"}
@nicholasareed
nicholasareed / gist:1465697
Created December 12, 2011 07:38
PHP Parse POST string to JSON object
<?php
// Get the raw post string
$raw_post = @file_get_contents('php://input');
// Parse using json_decode
$post = json_decode($raw_post);
// $post now contains the JSON object