Skip to content

Instantly share code, notes, and snippets.

@abediali
Last active April 12, 2018 22:39
Show Gist options
  • Save abediali/ee76a2fa36c2fbe3c1366a99504eed7e to your computer and use it in GitHub Desktop.
Save abediali/ee76a2fa36c2fbe3c1366a99504eed7e to your computer and use it in GitHub Desktop.
/**
* Synchronize to Hulu
*/
protected function sendDatesToHulu($inField = "huluDatesNew", $outField = "huluResults")
{
$debugFlag = isset($_REQUEST['syncDebug']) && $_REQUEST['syncDebug'] == "on";
if ($debugFlag)
exit;
/* What services? */
$services = array();
if (isset($_REQUEST['sync_haap']) && $_REQUEST['sync_haap'] == "on")
$services[] = "haap_fvod";
if (isset($_REQUEST['sync_fvod']) && $_REQUEST['sync_fvod'] == "on")
$services[] = "fvod";
/* Loop */
foreach($this->$inField as $huluId => $huluDate) {
foreach($services as $service) {
//echo $huluId . ": " . $huluDate . "<br/>\n";
$url = "https://content.hulu.com/api/v1/asset/$huluId/dates/$service?guid=e7b79f24-41c5-48e0-9d00-23a15a011b6b";
$data_string = $huluDate; //"{\"start_date\": \"$startDate\", \"end_date\": \"$endDate\"}";
// yyy
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
//$huluResults[$huluId] = $result;
if (isset($huluResults[$huluId]))
$huluResults[$huluId] .= "\n" . $result;
else
$huluResults[$huluId] = $result;
}
}
$this->$outField = $huluResults;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment