<?php

class EWRmedio_Services_Twitch extends XenForo_Model
{
	public static function dumpMedia($service, $matches)
	{
		$client = new Zend_Http_Client('https://api.twitch.tv/kraken/videos/'.$matches['sval2'].$matches['sval1']);
		$client->setHeaders('Client-ID', $service['service_apikey']);
		$feed = $client->request()->getBody();
		$json = json_decode($feed, true);
		
		if (!empty($json['error']))
		{
			throw new XenForo_Exception($json['message'], true);
		}
		
		$media = array(
			'media_value1' => $matches['sval1'],
			'media_value2' => $matches['sval2'],
			'media_thumb' => $json['preview'],
			'media_title' => $json['title'],
			'media_description' => $json['description'],
			'media_duration' => $json['length'],
			'media_keywords' => '',
		);
		
		return $media;
	}
}