Created
May 13, 2014 23:01
-
-
Save benallfree/3d3c0abe0b62598a6730 to your computer and use it in GitHub Desktop.
Wistia Upload and Status Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WistiaApi | |
{ | |
static $WISTIA_UPLOAD_URL='https://upload.wistia.com'; | |
static $WISTIA_API_URL='https://api.wistia.com/v1'; | |
function __construct($api_key) | |
{ | |
$this->key = $api_key; | |
} | |
function upload($url) | |
{ | |
$fields = array( | |
'api_password'=>$this->key, | |
'url'=>$url, | |
); | |
$r = $this->post($fields); | |
return $r; | |
} | |
function status($id) | |
{ | |
$r = $this->get($id); | |
return $r; | |
} | |
function get($id) | |
{ | |
$ch = curl_init(); | |
$url = sprintf("%s/medias/%s.json?api_password=%s", self::$WISTIA_API_URL, urlencode($id), urlencode($this->key)); | |
var_dump($url); | |
curl_setopt($ch,CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
$server_output = curl_exec ($ch); | |
$response = json_decode($server_output,true); | |
curl_close($ch); | |
return $response; | |
} | |
function post($data) | |
{ | |
$encoded = http_build_query($data); | |
//open connection | |
$ch = curl_init(); | |
//set the url, number of POST vars, POST data | |
curl_setopt($ch,CURLOPT_URL, self::$WISTIA_UPLOAD_URL); | |
curl_setopt($ch,CURLOPT_POST, 1); | |
curl_setopt($ch,CURLOPT_POSTFIELDS, $encoded); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
$server_output = curl_exec ($ch); | |
$response = json_decode($server_output,true); | |
curl_close($ch); | |
return $response; | |
} | |
} | |
$api = new WistiaApi(API_KEY); | |
$res = $api->upload('https://youdrone.s3.amazonaws.com/1_1399660040_0.avi'); | |
var_dump($res); | |
$res = $api->status($res['hashed_id']); | |
var_dump($res); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment