Service/Twitter.php

Show: PublicProtectedPrivateinherited
Table of Contents
Zend Framework
LICENSE This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to license@zend.com so we can send you a copy immediately.
Category
Zend  
Copyright
Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  
Package
Zend_Service  
Subpackage
Twitter  
Version
$Id$  

\Zend_Service_Twitter

Package: Zend_Service\Twitter
Category
Zend  
Copyright
Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  

Constants

>VConstant  API_BASE_URI = 'https://api.twitter.com/1.1/'
Base URI for all API calls
>VConstant  OAUTH_BASE_URI = 'https://api.twitter.com/oauth'
OAuth Endpoint
>VConstant  STATUS_MAX_CHARACTERS = 246
246 is the current limit for a status message, 140 characters are displayed initially, with the remainder linked from the web UI or client. The limit is applied to a html encoded UTF-8 string (i.e. entities are counted in the limit which may appear unusual but is a security measure).
This should be reviewed in the future...

Properties

>VPropertyprotectedarray $cookieJar
Details
Type
array
>VPropertyprotectedstring $dateFormat = 'D, d M Y H:i:s T'
Date format for 'since' strings
Default value'D, d M Y H:i:s T'Details
Type
string
>VPropertyprotected\Zend_Http_Client $httpClient = null
Default valuenullDetails
Type
\Zend_Http_Client
>VPropertyprotectedstring $methodType
Current method type (for method proxying)
Details
Type
string
>VPropertyprotectedarray $methodTypes = array('account', 'application', 'blocks', 'directmessages', 'favorites', 'friendships', 'search', 'statuses', 'users')
Types of API methods
Default valuearray('account', 'application', 'blocks', 'directmessages', 'favorites', 'friendships', 'search', 'statuses', 'users')Details
Type
array
>VPropertyprotected\Zend_Oauth_Consumer $oauthConsumer = null
Oauth Consumer
Default valuenullDetails
Type
\Zend_Oauth_Consumer
>VPropertyprotectedarray $options = array()
Options passed to constructor
Default valuearray()Details
Type
array
>VPropertyprotectedstring $username
Username
Details
Type
string

Methods

methodpublic__call(string $method, array $params) : mixed

Method overloading

Parameters
NameTypeDescription
$methodstring
$paramsarray
Returns
TypeDescription
mixed
Throws
ExceptionDescription
\Exception\BadMethodCallExceptionif unable to find method
methodpublic__construct(null | array | \Zend_Config $options = null, null | \Zend_Oauth_Consumer $consumer = null, null | \Zend_Http_Client $httpClient = null) : void

Constructor

Parameters
NameTypeDescription
$optionsnull | array | \Zend_Config
$consumernull | \Zend_Oauth_Consumer
$httpClientnull | \Zend_Http_Client
methodpublic__get(string $type) : \Twitter

Proxy service methods

Parameters
NameTypeDescription
$typestring
Returns
TypeDescription
\Twitter
Throws
ExceptionDescription
\Exception\DomainExceptionIf method not in method types list
methodpublicaccountVerifyCredentials() : \Zend_Service_Twitter_Response

Verify Account Credentials

Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Zend_Http_Client_Exceptionif HTTP request fails or times out
\Exception\DomainExceptionif unable to decode JSON payload
methodpublicapplicationRateLimitStatus() : \Zend_Service_Twitter_Response

Returns the number of api requests you have left per hour.

Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Zend_Http_Client_Exceptionif HTTP request fails or times out
\Exception\DomainExceptionif unable to decode JSON payload
Details
Todo
Have a separate payload object to represent rate limits  
methodpublicblocksCreate(integer | string $id) : \Zend_Service_Twitter_Response

Blocks the user specified in the ID parameter as the authenticating user.

Destroys a friendship to the blocked user if it exists.
Parameters
NameTypeDescription
$idinteger | string

The ID or screen name of a user to block.

Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Exception\DomainExceptionif unable to decode JSON payload
methodpublicblocksDestroy(integer | string $id) : \Zend_Service_Twitter_Response

Un-blocks the user specified in the ID parameter for the authenticating user

Parameters
NameTypeDescription
$idinteger | string

The ID or screen_name of the user to un-block.

Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Exception\DomainExceptionif unable to decode JSON payload
methodpublicblocksIds(integer $cursor = -1) : \Zend_Service_Twitter_Response

Returns an array of user ids that the authenticating user is blocking

Parameters
NameTypeDescription
$cursorinteger

Optional. Specifies the cursor position at which to begin listing ids; defaults to first "page" of results.

Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Exception\DomainExceptionif unable to decode JSON payload
methodpublicblocksList(integer $cursor = -1) : \Zend_Service_Twitter_Response

Returns an array of user objects that the authenticating user is blocking

Parameters
NameTypeDescription
$cursorinteger

Optional. Specifies the cursor position at which to begin listing ids; defaults to first "page" of results.

Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Exception\DomainExceptionif unable to decode JSON payload
methodprotectedcreateUserParameter(int | string $id, array $params) : array

Create a parameter representing the user

Determines if $id is an integer, and, if so, sets the "user_id" parameter. If not, assumes the $id is the "screen_name".
Parameters
NameTypeDescription
$idint | string
$paramsarray
Returns
TypeDescription
array
methodpublicdirectMessagesDestroy(int $id) : \Zend_Service_Twitter_Response

Destroy a direct message

Parameters
NameTypeDescription
$idint

ID of message to destroy

Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Zend_Http_Client_Exceptionif HTTP request fails or times out
\Exception\DomainExceptionif unable to decode JSON payload
methodpublicdirectMessagesMessages(array $options = array()) : \Zend_Service_Twitter_Response

Retrieve direct messages for the current user

$options may include one or more of the following keys - count: return page X of results - since_id: return statuses only greater than the one specified - max_id: return statuses with an ID less than (older than) or equal to that specified - include_entities: setting to false will disable embedded entities - skip_status:setting to true, "t", or 1 will omit the status in returned users
Parameters
NameTypeDescription
$optionsarray
Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Zend_Http_Client_Exceptionif HTTP request fails or times out
\Exception\DomainExceptionif unable to decode JSON payload
methodpublicdirectMessagesNew(int | string $user, string $text) : \Zend_Service_Twitter_Response

Send a direct message to a user

Parameters
NameTypeDescription
$userint | string

User to whom to send message

$textstring

Message to send to user

Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Exception\InvalidArgumentExceptionif message is empty
\Exception\OutOfRangeExceptionif message is too long
\Zend_Http_Client_Exceptionif HTTP request fails or times out
\Exception\DomainExceptionif unable to decode JSON payload
methodpublicdirectMessagesSent(array $options = array()) : \Zend_Service_Twitter_Response

Retrieve list of direct messages sent by current user

$options may include one or more of the following keys - count: return page X of results - page: return starting at page - since_id: return statuses only greater than the one specified - max_id: return statuses with an ID less than (older than) or equal to that specified - include_entities: setting to false will disable embedded entities
Parameters
NameTypeDescription
$optionsarray
Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Zend_Http_Client_Exceptionif HTTP request fails or times out
\Exception\DomainExceptionif unable to decode JSON payload
methodpublicfavoritesCreate(int $id) : \Zend_Service_Twitter_Response

Mark a status as a favorite

Parameters
NameTypeDescription
$idint

Status ID you want to mark as a favorite

Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Zend_Http_Client_Exceptionif HTTP request fails or times out
\Exception\DomainExceptionif unable to decode JSON payload
methodpublicfavoritesDestroy(int $id) : \Zend_Service_Twitter_Response

Remove a favorite

Parameters
NameTypeDescription
$idint

Status ID you want to de-list as a favorite

Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Zend_Http_Client_Exceptionif HTTP request fails or times out
\Exception\DomainExceptionif unable to decode JSON payload
methodpublicfavoritesList( $options = array()) : \Zend_Service_Twitter_Response

Fetch favorites

$options may contain one or more of the following: - user_id: Id of a user for whom to fetch favorites - screen_name: Screen name of a user for whom to fetch favorites - count: number of tweets to attempt to retrieve, up to 200 - since_id: return results only after the specified tweet id - max_id: return results with an ID less than (older than) or equal to the specified ID - include_entities: when set to false, entities member will be omitted
Parameters
NameTypeDescription
$options
Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Zend_Http_Client_Exceptionif HTTP request fails or times out
\Exception\DomainExceptionif unable to decode JSON payload
methodpublicfriendshipsCreate(int | string $id, array $params = array()) : \Zend_Service_Twitter_Response

Create friendship

Parameters
NameTypeDescription
$idint | string

User ID or name of new friend

$paramsarray

Additional parameters to pass

Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Zend_Http_Client_Exceptionif HTTP request fails or times out
\Exception\DomainExceptionif unable to decode JSON payload
methodpublicfriendshipsDestroy(int | string $id) : \Zend_Service_Twitter_Response

Destroy friendship

Parameters
NameTypeDescription
$idint | string

User ID or name of friend to remove

Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Zend_Http_Client_Exceptionif HTTP request fails or times out
\Exception\DomainExceptionif unable to decode JSON payload
methodprotectedget(string $path, array $query = array()) : \Zend_Http_Response

Performs an HTTP GET request to the $path.

Parameters
NameTypeDescription
$pathstring
$queryarray

Array of GET parameters

Returns
TypeDescription
\Zend_Http_Response
Throws
ExceptionDescription
\Zend_Http_Client_Exception
methodpublicgetHttpClient() : \Zend_Http_Client

Get the HTTP client

Lazy loads one if none present
Returns
TypeDescription
\Zend_Http_Client
methodpublicgetUsername() : string

Retrieve username

Returns
TypeDescription
string
methodprotectedinit() : void

Initialize HTTP authentication

Throws
ExceptionDescription
\Exception\DomainExceptionif unauthorised
methodpublicisAuthorised() : bool

Checks for an authorised state

Returns
TypeDescription
bool
methodprotectedperformPost(mixed $method, mixed $data,  $client) : \Zend_Http_Response

Perform a POST or PUT

Performs a POST or PUT request. Any data provided is set in the HTTP client. String data is pushed in as raw POST data; array or object data is pushed in as POST parameters.
Parameters
NameTypeDescription
$methodmixed
$datamixed
$client
Returns
TypeDescription
\Zend_Http_Response
methodprotectedpost(string $path, mixed $data = null) : \Zend_Http_Response

Performs an HTTP POST request to $path.

Parameters
NameTypeDescription
$pathstring
$datamixed

Raw data to send

Returns
TypeDescription
\Zend_Http_Response
Throws
ExceptionDescription
\Zend_Http_Client_Exception
methodprotectedprepare(string $path, \Zend_Http_Client $client) : void

Call a remote REST web service URI

Parameters
NameTypeDescription
$pathstring

The path to append to the URI

$client\Zend_Http_Client
Throws
ExceptionDescription
\Zend_Http_Client_Exception
methodpublicsearchTweets(string $query, array $options = array()) : \Zend_Service_Twitter_Response

Search tweets

$options may include any of the following: - geocode: a string of the form "latitude, longitude, radius" - lang: restrict tweets to the two-letter language code - locale: query is in the given two-letter language code - result_type: what type of results to receive: mixed, recent, or popular - count: number of tweets to return per page; up to 100 - until: return tweets generated before the given date - since_id: return resutls with an ID greater than (more recent than) the given ID - max_id: return results with an ID less than (older than) the given ID - include_entities: whether or not to include embedded entities
Parameters
NameTypeDescription
$querystring
$optionsarray
Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Zend_Http_Client_Exceptionif HTTP request fails or times out
\Exception\DomainExceptionif unable to decode JSON payload
methodpublicsetHttpClient(\Zend_Http_Client $client) : \Zend_Service_Twitter

Set HTTP client

Parameters
NameTypeDescription
$client\Zend_Http_Client
Returns
TypeDescription
\Zend_Service_Twitter
Details
Fluent
This method is part of a fluent interface and will return the same instance  
methodpublicsetUsername(string $value) : \Zend_Service_Twitter

Set username

Parameters
NameTypeDescription
$valuestring
Returns
TypeDescription
\Zend_Service_Twitter
Details
Fluent
This method is part of a fluent interface and will return the same instance  
methodpublicstatusesDestroy(int $id) : \Zend_Service_Twitter_Response

Destroy a status message

Parameters
NameTypeDescription
$idint

ID of status to destroy

Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Zend_Http_Client_Exceptionif HTTP request fails or times out
\Exception\DomainExceptionif unable to decode JSON payload
methodpublicstatusesHomeTimeline( $options = array()) : \Zend_Service_Twitter_Response

Friend Timeline Status

$options may include one or more of the following keys - count: number of tweets to attempt to retrieve, up to 200 - since_id: return results only after the specified tweet id - max_id: return results with an ID less than (older than) or equal to the specified ID - trim_user: when set to true, "t", or 1, user object in tweets will include only author's ID. - contributor_details: when set to true, includes screen_name of each contributor - include_entities: when set to false, entities member will be omitted - exclude_replies: when set to true, will strip replies appearing in the timeline
Parameters
NameTypeDescription
$options
Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Zend_Http_Client_Exceptionif HTTP request fails or times out
\Exception\DomainExceptionif unable to decode JSON payload
methodpublicstatusesMentionsTimeline(array $options = array()) : \Zend_Service_Twitter_Response

Get status replies

$options may include one or more of the following keys - count: number of tweets to attempt to retrieve, up to 200 - since_id: return results only after the specified tweet id - max_id: return results with an ID less than (older than) or equal to the specified ID - trim_user: when set to true, "t", or 1, user object in tweets will include only author's ID. - contributor_details: when set to true, includes screen_name of each contributor - include_entities: when set to false, entities member will be omitted
Parameters
NameTypeDescription
$optionsarray
Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Zend_Http_Client_Exceptionif HTTP request fails or times out
\Exception\DomainExceptionif unable to decode JSON payload
methodpublicstatusesSample() : \Zend_Service_Twitter_Response

Public Timeline status

Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Zend_Http_Client_Exceptionif HTTP request fails or times out
\Exception\DomainExceptionif unable to decode JSON payload
methodpublicstatusesShow(int $id) : \Zend_Service_Twitter_Response

Show a single status

Parameters
NameTypeDescription
$idint

Id of status to show

Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Zend_Http_Client_Exceptionif HTTP request fails or times out
\Exception\DomainExceptionif unable to decode JSON payload
methodpublicstatusesUpdate(string $status, null | int $inReplyToStatusId = null) : \Zend_Service_Twitter_Response

Update user's current status

Parameters
NameTypeDescription
$statusstring
$inReplyToStatusIdnull | int
Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Zend_Http_Client_Exceptionif HTTP request fails or times out
\Exception\OutOfRangeExceptionif message is too long
\Exception\InvalidArgumentExceptionif message is empty
\Exception\DomainExceptionif unable to decode JSON payload
Details
Todo
Support additional parameters supported by statuses/update endpoint  
methodpublicstatusesUserTimeline( $options = array()) : \Zend_Service_Twitter_Response

User Timeline status

$options may include one or more of the following keys - user_id: Id of a user for whom to fetch favorites - screen_name: Screen name of a user for whom to fetch favorites - count: number of tweets to attempt to retrieve, up to 200 - since_id: return results only after the specified tweet id - max_id: return results with an ID less than (older than) or equal to the specified ID - trim_user: when set to true, "t", or 1, user object in tweets will include only author's ID. - exclude_replies: when set to true, will strip replies appearing in the timeline - contributor_details: when set to true, includes screen_name of each contributor - include_rts: when set to false, will strip native retweets
Parameters
NameTypeDescription
$options
Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Zend_Http_Client_Exceptionif HTTP request fails or times out
\Exception\DomainExceptionif unable to decode JSON payload
methodpublicusersSearch(string $query, array $options = array()) : \Zend_Service_Twitter_Response

Search users

$options may include any of the following: - page: the page of results to retrieve - count: the number of users to retrieve per page; max is 20 - include_entities: if set to boolean true, include embedded entities
Parameters
NameTypeDescription
$querystring
$optionsarray
Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Zend_Http_Client_Exceptionif HTTP request fails or times out
\Exception\DomainExceptionif unable to decode JSON payload
methodpublicusersShow(int | string $id) : \Zend_Service_Twitter_Response

Show extended information on a user

Parameters
NameTypeDescription
$idint | string

User ID or name

Returns
TypeDescription
\Zend_Service_Twitter_Response
Throws
ExceptionDescription
\Zend_Http_Client_Exceptionif HTTP request fails or times out
\Exception\DomainExceptionif unable to decode JSON payload
methodprotectedvalidInteger( $int) : integer

Protected function to validate that the integer is valid or return a 0

Parameters
NameTypeDescription
$int
Returns
TypeDescription
integer
Throws
ExceptionDescription
\Zend_Http_Client_Exceptionif HTTP request fails or times out
methodprotectedvalidateScreenName(string $name) : string

Validate a screen name using Twitter rules

Parameters
NameTypeDescription
$namestring
Returns
TypeDescription
string
Throws
ExceptionDescription
\Exception\InvalidArgumentException
Documentation was generated by phpDocumentor 2.2.0 .