app\extensions\service \ Twitter

Simple Twitter Client

Download |
| Newest | Edit
<?php

namespace app\extensions\service;

class Twitter extends \lithium\http\Service {

	protected $_api = array(
		'statuses' => array(
			'user_timeline' => array(
				'path' => 'statuses/user_timeline',
				'method' => 'get',
				'params' => array(
					'id', 'user_id', 'screen_name', 'since_id', 'max_id', 'count', 'page'
				)
			),
			'update' => array(
				'path' => 'statuses/update',
				'method' => 'post',
				'params' => array(
					'status', 'in_reply_to_status_id', 'lat', 'long',
				)
			)
		)
	);

	public function __call($name, $options) {
		if (isset($this->_api[$name])) {
			$call = array_shift($options);
			if (isset($this->_api[$name][$call])) {
				extract($this->_api[$name][$call]);
				$args = array_shift($options);
				return $this->{$method}("{$name}/{$call}.json", $args);
			}
		}
	}

	public function send($method, $path = null, $data = null, $options = array()) {
		$this->request->headers('User-Agent', 'twittium');
		$data = parent::send($method, $path, $data, $options);
		if (get_magic_quotes_gpc() == true) {
			$data = stripslashes($data);
		}
		return json_decode($data);
	}
}

Description

This simple Twitter client shows how you can easily wrap a web API with the http\Service class.

Details

  • Version: 1
  • Created: 2010-07-23 08:24:25
  • File: app/extensions/service/Twitter.php

Maintainers