Skip to content

Instantly share code, notes, and snippets.

@andyfoster
Created June 22, 2016 04:07
Show Gist options
  • Save andyfoster/480cd656a872c3ad5806d7e59d2d443c to your computer and use it in GitHub Desktop.
Save andyfoster/480cd656a872c3ad5806d7e59d2d443c to your computer and use it in GitHub Desktop.
<?php
/*
*
* Wrapper script for hitting Glip Webhooks
*
* @usage:
* Include this file and call like so:
*
* require_once("GlipPost.php");
*
* GlipPost::post(
* 'your-glip-webhook-integration-token',
* 'http://www.example.com/avatar.png',
* 'Web Hook Post User',
* 'Message to post');
*
*
*/
class GlipPost {
public function post($webhook_url, $icon_url, $activity, $message){
$glip_activity = array(
'icon' => $icon_url,
'activity' => $activity,
'body' => $message,
);
$json_message = json_encode($glip_activity);
//Send the JSON data to the server
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $webhook_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json; charset=utf-8"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_message);
$data = curl_exec($ch);
curl_close($ch);
echo "Script has finished running.";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment