rveitch
1/29/2016 - 8:53 PM

JW API: Episode View Stats

JW API: Episode View Stats

<?php
/**
 * JW API: Episode View Stats
 *
 * Returns view stats for Segments 1-3 of weekly podcast.
 */
function fcc_jw_search( $string, $field ) {
  $botr_api = new BotrAPI( get_option('options_jw_platform_api_key'), get_option('options_jw_platform_api_secret') ); // Instantiate the API.
	$response = $botr_api->call("/videos/list", array( "search:{$field}" => $string ));
	
	$segment_1_views = $response['videos']['0']['views'];
	$segment_2_views = $response['videos']['1']['views'];
	$segment_3_views = $response['videos']['2']['views'];
	$pubdate = $response['videos']['0']['date'];
	
	$date = '<strong>Northland Outdoors Radio: ' . date( 'm/d/Y', $pubdate ) . ' Weekly Podcast</strong><br>';
	$segment_1 = 'Segment 1: ' . $segment_1_views . '<br>';
	$segment_2 = 'Segment 2: ' . $segment_2_views . '<br>';
	$segment_3 = 'Segment 3: ' . $segment_3_views . '<br>';
	$total_views = 'Total Views: ' . ($segment_1_views + $segment_2_views + $segment_3_views);
	
	$response = $date . '--------------<br>' . $segment_1 . $segment_2 . $segment_3 . '--------------<br>' . $total_views;

	return $response;
}


$field = 'custom.episode'; // "Episode" custom properties field
$string = '012316'; // Episode Date. Each episode has 3 segments.

echo fcc_jw_search( $string, $field );