<?php

class EWRmedio_Services_Imgur extends XenForo_Model
{
	public static function dumpMedia($service, $matches)
	{
		$client = new Zend_Http_Client('https://api.imgur.com/3/album/'.$matches['sval1']);
		$client->setHeaders('Authorization', 'Client-ID 39c17debda27773');
		$feed = $client->request()->getBody();
		$json = json_decode($feed, true);
		
		if (!empty($json['data']['error']))
		{
			throw new XenForo_Exception($json['data']['error'], true);
		}
		
		$json = $json['data'];
		
		$media = array(
			'media_value1' => $json['id'],
			'media_value2' => '',
			'media_thumb' => 'http://i.imgur.com/'.$json['cover'].'l.jpg',
			'media_title' => $json['title'],
			'media_description' => $json['title'],
			'media_duration' => $json['images_count'],
			'media_keywords' => '',
		);
		
		return $media;
	}
}