Services_Twitter
[ class tree: Services_Twitter ] [ index: Services_Twitter ] [ all elements ]

Class: Services_Twitter

Source Location: /Services_Twitter-0.6.3/Services/Twitter.php

Class Overview


Base class for interacting with Twitter's API.


Author(s):

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 81]
Base class for interacting with Twitter's API.

Here's a basic auth example:

  1.  require_once 'Services/Twitter.php';
  2.  
  3.  $username 'Your_Username';
  4.  $password 'Your_Password';
  5.  
  6.  try {
  7.      $twitter = new Services_Twitter($username$password);
  8.      $msg $twitter->statuses->update("I'm coding with PEAR right now!");
  9.      print_r($msg);
  10.  catch (Services_Twitter_Exception $e{
  11.      echo $e->getMessage();
  12.  }

Here's an OAuth example:

  1.  require_once 'Services/Twitter.php';
  2.  require_once 'HTTP/OAuth/Consumer.php';
  3.  
  4.  
  5.  try {
  6.      $twitter = new Services_Twitter();
  7.      $oauth   = new HTTP_OAuth_Consumer('consumer_key',
  8.                                         'consumer_secret',
  9.                                         'auth_token',
  10.                                         'token_secret');
  11.      $twitter->setOAuth($oauth);
  12.  
  13.      $msg $twitter->statuses->update("I'm coding with PEAR right now!");
  14.      print_r($msg);
  15.  catch (Services_Twitter_Exception $e{
  16.      echo $e->getMessage();
  17.  }



[ Top ]


Class Variables

$api = array()

[line 201]

The Twitter API mapping array, used internally to retrieve infos about the API categories, endpoints, parameters, etc...

The mapping is constructed with the api.xml file present in the Services_Twitter data directory.


Type:   array


[ Top ]

$currentCategory =  null

[line 211]

Used internally by the __get() and __call() methods to identify the current call.

Type:   string


[ Top ]

$oauth =  null

[line 146]

Optional instance of HTTP_OAuth_Consumer
  • See: HTTP_OAuth_Consumer
  • Access: protected

Type:   HTTP_OAuth_Consumer


[ Top ]

$options = array(
        'format'     => self::OUTPUT_JSON,
        'raw_format' => false,
        'source'     => 'pearservicestwitter',
        'use_ssl'    => false,
        'validate'   => false,
    )

[line 172]

Options for HTTP requests and misc.

Available options are:

  • format: the desired output format: json (default) or xml,
  • raw_format: if set to true, the configured format is returned "as is",
  • source: you can set this if you have registered a twitter source {@see http://twitter.com/help/request_source}, your source will be passed with each POST request,
  • use_ssl: whether to send all requests over ssl or not. If set to true, the script will replace the http:// URL scheme with https://,
  • validate: if set to true the class will validate api xml file against the RelaxNG file (you should not need this unless you are hacking Services_Twitter...).
These options can be set either by passing them directly to the constructor as an array (3rd parameter), or by using the setOption() or setOptions() methods.


Type:   array


[ Top ]

$pass =  ''

[line 138]

Password of Twitter user

Type:   string


[ Top ]

$request =  null

[line 188]

The HTTP_Request2 instance, you can customize the request if you want to (proxy, auth etc...) with the get/setRequest() methods.

Type:   HTTP_Request2


[ Top ]

$searchUri =  'http://search.twitter.com'

[line 122]

Public URI of Twitter's Search API
  • Access: public

Type:   string


[ Top ]

$uri =  'http://api.twitter.com/1'

[line 115]

Public URI of Twitter's API
  • Access: public

Type:   string


[ Top ]

$user =  ''

[line 130]

Username of Twitter user

Type:   string


[ Top ]



Method Detail

decodeBody   [line 527]

mixed decodeBody( string $body)

Decode the response body according to the configured format.
  • Access: protected

Parameters:

string   $body     The response body to decode

[ Top ]

getOption   [line 440]

mixed getOption( string $option)

Get an option from Services_Twitter::$options

Parameters:

string   $option     Name of option

[ Top ]

getOptions   [line 476]

array getOptions( )

Return the Services_Twitter options array.

[ Top ]

getRequest   [line 489]

HTTP_Request2 getRequest( )

Returns the HTTP_Request2 instance.
  • Return: The request
  • Access: public

[ Top ]

isUtf8   [line 891]

boolean isUtf8( string $str)

Check if the given string is a UTF-8 string or an iso-8859-1 one.
  • Return: Wether the string is unicode or not
  • Access: protected

Parameters:

string   $str     The string to check

[ Top ]

loadAPI   [line 556]

void loadAPI( )

Loads the XML API definition.
  • Access: protected

[ Top ]

__construct (Constructor)   [line 225]

void __construct( [string $user = null], [string $pass = null], [array $options = array()])

Constructor.
  • Access: public

Parameters:

string   $user     Twitter username
string   $pass     Twitter password
array   $options     An array of options

[ Top ]

prepareRequest   [line 592]

array prepareRequest( SimpleXMLElement $endpoint, [ $args = array()], [string $cat = null])

Prepare the request before it is sent.
  • Return: The array of arguments to pass to in the request
  • Throws: Services_Twitter_Exception
  • Access: protected

Parameters:

SimpleXMLElement   $endpoint     API endpoint xml node
array   $args     API endpoint arguments
string   $cat     The current category

[ Top ]

sendOAuthRequest   [line 361]

HTTP_Request2_Response sendOAuthRequest( string $uri, string $method, array $params, array $files)

Sends a request using OAuth instead of basic auth

Parameters:

string   $uri     The full URI of the endpoint
string   $method     GET or POST
array   $params     Array of additional parameter
array   $files     Array of files to upload

[ Top ]

sendRequest   [line 726]

object Instance sendRequest( string $uri, [array $method = 'GET'], [ $args = array()], [ $files = array()])

Send a request to the Twitter API.
  • Return: of SimpleXMLElement
  • Throws: Services_Twitter_Exception
  • Access: protected

Parameters:

string   $uri     The full URI to the API endpoint
array   $method     The HTTP request method (GET or POST)
array   $args     The API endpoint arguments if any
array   $files     The API endpoint file uploads if any

[ Top ]

setOAuth   [line 424]

void setOAuth( $oauth)

Sets an instance of HTTP_OAuth_Consumer

Parameters:

HTTP_OAuth_Consumer   $oauth     Object containing OAuth credentials

[ Top ]

setOption   [line 405]

void setOption( string $option, mixed $value)

Set an option in Services_Twitter::$options

If a function exists named _set$option (e.g. _setUserAgent()) then that method will be used instead. Otherwise, the value is set directly into the options array.


Parameters:

string   $option     Name of option
mixed   $value     Value of option

[ Top ]

setOptions   [line 460]

void setOptions( $options)

Set a number of options at once in Services_Twitter::$options

Parameters:

array   $options     Associative array of options name/value

[ Top ]

setRequest   [line 512]

void setRequest( $request)

Sets the HTTP_Request2 instance.
  • Access: public

Parameters:

HTTP_Request2   $request     The request to set

[ Top ]

validateArg   [line 775]

void validateArg( array $name, array &$val, array $type, [array $maxLength = null])

Check the validity of an argument (required, max length, type...).
  • Throws: Services_Twitter_Exception
  • Access: protected

Parameters:

array   $name     The argument name
array   &$val     The argument value, passed by reference
array   $type     The argument type
array   $maxLength     The argument maximum length (optional)

[ Top ]

__call   [line 275]

object Instance __call( string $endpoint, [ $args = array()])

Overloaded call for API passthrough.
  • Return: of SimpleXMLElement
  • Access: public

Parameters:

string   $endpoint     API endpoint being called
array   $args     $args[0] is an array of GET/POST arguments

[ Top ]

__get   [line 248]

mixed __get( string $property)

Get interceptor, if the requested property is "options", it just return the options array, otherwise, if the property matches a valid API category it return an instance of this class.
  • Access: public

Parameters:

string   $property     The property of the call

[ Top ]


Documentation generated on Sun, 12 Sep 2010 19:00:03 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.