View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFDEV:Zend Proposal Zone Template}

{zone-data:component-name}
Zend_Service_Gravatar
{zone-data}

{zone-data:proposer-list}
[mailto:w.naruniec@gmail.com]
[Darby Felton|~matthew], Zend liaison
{zone-data}

{zone-data:revision}
0.1 - 9 April 2007: Initial version
0.2 - 25 July 2007: Added some use cases, corrected small mistakes
0.3 - 6 August 2007: Improved class skeletons
{zone-data}

{zone-data:overview}
Zend_Service_Gravatar is a implementation of the Gravatar web service.
{zone-data}

{zone-data:references}
* [Gravatar implementor's guide|http://site.gravatar.com/site/implement]
{zone-data}

{zone-data:requirements}
* Abillity to generate valid URI for avatar using email adress
* Provide a way of configuring avatar rating, avatar size, and default avatar adress
* Provide a method to check if the avatar image exists
* Provide getter and setter to allow change email adress after instantiation
{zone-data}

{zone-data:dependencies}
* Zend_Http_Client
* Zend_Service_Exception
{zone-data}

{zone-data:operation}
Generates uri of gravatar, checks if gravatar's file exists.
{zone-data}

{zone-data:milestones}
* Milestone 1: \[DONE\][Design notes will be published here|http://framework.zend.com/wiki/x/xGg]
* Milestone 2: \[DONE\]Class skeletons will be published here
* Milestone 3: \[DONE\]Working prototype checked into the incubator supporting use cases #1, #2, #3, #4 and #5.
* Milestone 4: \[DONE\]Unit tests exist, work, and are checked into SVN.
* Milestone 5: \[DONE\]Initial documentation exists.
{zone-data}

{zone-data:class-list}
* Zend_Service_Gravatar
{zone-data}

{zone-data:use-cases}
{composition-setup}
{deck:id=Usecase}
{card:label=UC 01}
h3. UC 01
{code}
// If avatar doesn't exists, then print default from web service (blind)

$avatar = new Zend_Service_Gravatar('john.doe@example.com');

echo '<img src="' . $avatar->getUri() . '" />' . "\n";
{code}
{card}
{card:label=UC 02}
h3. UC 02
{code}
// If avatar doesn't exists, then print our default

$gravatar = new Zend_Service_Gravatar('john.doe@example.com');

$params = array(
'default', 'http://example.com/def_avatar.png'
);

$gravatar->setParams($params);

echo '<img src="' . $avatar->getUri() . '" />' . "\n";
{code}
{card}
{card:label=UC 03}
h3. UC 03
{code}
// If avatar doesn't exists, then print nothing

$gravatar = new Zend_Service_Gravatar('john.doe@example.com');

if ($gravatar->isValid()) {
echo '<img src="' . $gravatar->getUri() . '" />' . "\n";
}
{code}
{card}
{card:label=UC 04}
h3. UC 04
{code}
// If avatar doesn't exists, then print default from web service (blind)
// Generate URI manually, using Gravatar ID

$gravatar = new Zend_Service_Gravatar('w.naruniec@gmail.com');

echo '<img src="http://www.gravatar.com/avatar.php?gravatar_id='
. $gravatar->getGravatarId()
. '&rating=G&size=80" />'
. "\n";
{code}
{card}
{card:label=UC 05}
h3. UC 05
{code}
// Generate avatars in loop
$emails = array(
'john.doe@example.com',
'w.naruniec@gmail.com',
'someone@example.com',
);

$gravatar = new Zend_Service_Gravatar();

foreach ($emails as $email) {
$gravatar->setEmail($email);
echo '<img src="' . $gravatar->getUri() . '" />' . "\n";
}
{code}
{card}
{deck}
{zone-data}

{zone-data:skeletons}
{code}
class Zend_Service_Gravatar extends Zend_Service_Abstract
{
/**
* Base URI for the HTTP client
*/
const API_URI = 'http://www.gravatar.com';

/**
* Query path for the HTTP client
*/
const PATH_AVATAR = 'avatar.php';

/**
* Email adress used to make query
*
* @var string
*/
protected $_email;

/**
* Default query parameters
*
* @var array
*/
protected $_params = array(
'rating' => 'G',
'size' => '80',
'default' => 'http://www.gravatar.com/avatar.php',
'border' => '',
);

/**
* Construct a new Gravatar Web Service Client
*
* @param string $email
* @param array $params Associative array of query parameters
*/
public function __construct($email = '', $params = null);

/**
* Set parameters
*
* @param array $params Associative array of query parameters
*/
public function setParams($params);

/**
* Get params
*
*/
public function getParams();

/**
* Set an e-mail adress
*
* @param string $email
*/
public function setEmail($email);

/**
* Get an e-mail adress
*
*/
public function getEmail();

/**
* Check if an avatar for e-mail adress is valid
*
* Returns TRUE when avatar exists (succesful request without redirect)
* Returns FALSE when avatar doesn't exist (succesful request with redirect)
* Throws exception when something goes wrong, e.g. unsuccesful request.
*
* @return boolean
* @throws Zend_Service_Exception when response is other than successful or redirect
*/
public function isValid();

/**
* Get escaped URI of gravatar image.
*
* @return string escaped URI of gravatar image
*/
public function getUri();

/**
* Get generated Gravatar ID
*
* @return string Gravatar ID generated using e-mail adress
*/
public function getGravatarId();

/**
* Prepare query parameters
*
* @return string
*/
protected function _getQuery();

/**
* Generates URI of gravatar image.
*
* @return string URI of gravatar image
*/
protected function _generateUri($separator = '&');
}
{code}
{zone-data}

{zone-template-instance}]]></ac:plain-text-body></ac:macro>