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

Class: Services_Twitter

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

Class Overview


Base class for interacting with Twitter's API.


Author(s):

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

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

  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.  }



[ Top ]


Class Variables

$api = array()

[line 164]

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 174]

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

Type:   string


[ Top ]

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

[line 136]

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,
  • 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 112]

Password of Twitter user

Type:   string


[ Top ]

$request =  null

[line 151]

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 96]

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

Type:   string


[ Top ]

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

[line 89]

Public URI of Twitter's API
  • Access: public

Type:   string


[ Top ]

$user =  ''

[line 104]

Username of Twitter user

Type:   string


[ Top ]



Method Detail

decodeBody   [line 427]

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 345]

mixed getOption( string $option)

Get an option from Services_Twitter::$options

Parameters:

string   $option     Name of option

[ Top ]

getOptions   [line 381]

array getOptions( )

Return the Services_Twitter options array.

[ Top ]

getRequest   [line 394]

HTTP_Request2 getRequest( )

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

[ Top ]

isUnicode   [line 735]

boolean isUnicode( string $str)

Check if the given string is a unicode 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 453]

void loadAPI( )

Loads the XML API definition.
  • Access: protected

[ Top ]

__construct (Constructor)   [line 188]

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 489]

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 ]

sendRequest   [line 596]

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 ]

setOption   [line 324]

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 365]

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 412]

void setRequest( $request)

Sets the HTTP_Request2 instance.
  • Access: public

Parameters:

HTTP_Request2   $request     The request to set

[ Top ]

validateArg   [line 645]

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 241]

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 214]

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 Wed, 26 Aug 2009 18:00:03 +0000 by phpDocumentor 1.4.2. PEAR Logo Copyright © PHP Group 2004.