web/lib/Zend/Service/Twitter.php
author Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
Thu, 07 May 2015 15:16:02 +0200
changeset 1230 68c69c656a2c
parent 807 877f952ae2bd
permissions -rwxr-xr-x
upgrade Zend
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     1
<?php
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     2
/**
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     3
 * Zend Framework
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     4
 *
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     5
 * LICENSE
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     6
 *
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     7
 * This source file is subject to the new BSD license that is bundled
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     8
 * with this package in the file LICENSE.txt.
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     9
 * It is also available through the world-wide-web at this URL:
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    10
 * http://framework.zend.com/license/new-bsd
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    11
 * If you did not receive a copy of the license and are unable to
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    12
 * obtain it through the world-wide-web, please send an email
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    13
 * to license@zend.com so we can send you a copy immediately.
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    14
 *
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    15
 * @category   Zend
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    16
 * @package    Zend_Service
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    17
 * @subpackage Twitter
1230
68c69c656a2c upgrade Zend
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 807
diff changeset
    18
 * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    19
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
1230
68c69c656a2c upgrade Zend
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 807
diff changeset
    20
 * @version    $Id$
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    21
 */
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    22
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    23
/**
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    24
 * @see Zend_Http_Client
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    25
 */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    26
require_once 'Zend/Http/Client.php';
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    27
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    28
/**
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    29
 * @see Zend_Http_CookieJar
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    30
 */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    31
require_once 'Zend/Http/CookieJar.php';
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    32
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    33
/**
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    34
 * @see Zend_Oauth_Consumer
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    35
 */
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    36
require_once 'Zend/Oauth/Consumer.php';
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    37
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    38
/**
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    39
 * @see Zend_Oauth_Token_Access
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    40
 */
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    41
require_once 'Zend/Oauth/Token/Access.php';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    42
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    43
/**
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    44
 * @see Zend_Service_Twitter_Response
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    45
 */
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    46
require_once 'Zend/Service/Twitter/Response.php';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    47
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    48
/**
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    49
 * @category   Zend
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    50
 * @package    Zend_Service
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    51
 * @subpackage Twitter
1230
68c69c656a2c upgrade Zend
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 807
diff changeset
    52
 * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    53
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    54
 */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    55
class Zend_Service_Twitter
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    56
{
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    57
    /**
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    58
     * Base URI for all API calls
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    59
     */
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    60
    const API_BASE_URI = 'https://api.twitter.com/1.1/';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    61
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    62
    /**
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    63
     * OAuth Endpoint
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    64
     */
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    65
    const OAUTH_BASE_URI = 'https://api.twitter.com/oauth';
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    66
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    67
    /**
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    68
     * 246 is the current limit for a status message, 140 characters are displayed
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    69
     * initially, with the remainder linked from the web UI or client. The limit is
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    70
     * applied to a html encoded UTF-8 string (i.e. entities are counted in the limit
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    71
     * which may appear unusual but is a security measure).
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    72
     *
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    73
     * This should be reviewed in the future...
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    74
     */
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    75
    const STATUS_MAX_CHARACTERS = 246;
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    76
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    77
    /**
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    78
     * @var array
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    79
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    80
    protected $cookieJar;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    81
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    82
    /**
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    83
     * Date format for 'since' strings
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    84
     *
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    85
     * @var string
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    86
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    87
    protected $dateFormat = 'D, d M Y H:i:s T';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    88
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    89
    /**
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    90
     * @var Zend_Http_Client
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    91
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    92
    protected $httpClient = null;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    93
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    94
    /**
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    95
     * Current method type (for method proxying)
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    96
     *
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    97
     * @var string
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    98
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
    99
    protected $methodType;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   100
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   101
    /**
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   102
     * Oauth Consumer
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   103
     *
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   104
     * @var Zend_Oauth_Consumer
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   105
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   106
    protected $oauthConsumer = null;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   107
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   108
    /**
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   109
     * Types of API methods
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   110
     *
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   111
     * @var array
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   112
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   113
    protected $methodTypes = array(
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   114
        'account',
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   115
        'application',
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   116
        'blocks',
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   117
        'directmessages',
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   118
        'favorites',
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   119
        'friendships',
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   120
        'search',
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   121
        'statuses',
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   122
        'users',
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   123
    );
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   124
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   125
    /**
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   126
     * Options passed to constructor
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   127
     *
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   128
     * @var array
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   129
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   130
    protected $options = array();
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   131
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   132
    /**
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   133
     * Username
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   134
     *
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   135
     * @var string
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   136
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   137
    protected $username;
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   138
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   139
    /**
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   140
     * Constructor
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   141
     *
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   142
     * @param  null|array|Zend_Config $options
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   143
     * @param  null|Zend_Oauth_Consumer $consumer
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   144
     * @param  null|Zend_Http_Client $httpClient
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   145
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   146
    public function __construct($options = null, Zend_Oauth_Consumer $consumer = null, Zend_Http_Client $httpClient = null)
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   147
    {
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   148
        if ($options instanceof Zend_Config) {
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   149
            $options = $options->toArray();
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   150
        }
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   151
        if (!is_array($options)) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   152
            $options = array();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   153
        }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   154
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   155
        $this->options = $options;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   156
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   157
        if (isset($options['username'])) {
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   158
            $this->setUsername($options['username']);
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   159
        }
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   160
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   161
        $accessToken = false;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   162
        if (isset($options['accessToken'])) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   163
            $accessToken = $options['accessToken'];
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   164
        } elseif (isset($options['access_token'])) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   165
            $accessToken = $options['access_token'];
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   166
        }
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   167
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   168
        $oauthOptions = array();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   169
        if (isset($options['oauthOptions'])) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   170
            $oauthOptions = $options['oauthOptions'];
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   171
        } elseif (isset($options['oauth_options'])) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   172
            $oauthOptions = $options['oauth_options'];
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   173
        }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   174
        $oauthOptions['siteUrl'] = self::OAUTH_BASE_URI;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   175
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   176
        $httpClientOptions = array();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   177
        if (isset($options['httpClientOptions'])) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   178
            $httpClientOptions = $options['httpClientOptions'];
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   179
        } elseif (isset($options['http_client_options'])) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   180
            $httpClientOptions = $options['http_client_options'];
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   181
        }
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   182
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   183
        // If we have an OAuth access token, use the HTTP client it provides
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   184
        if ($accessToken && is_array($accessToken)
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   185
            && (isset($accessToken['token']) && isset($accessToken['secret']))
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   186
        ) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   187
            $token = new Zend_Oauth_Token_Access();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   188
            $token->setToken($accessToken['token']);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   189
            $token->setTokenSecret($accessToken['secret']);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   190
            $accessToken = $token;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   191
        }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   192
        if ($accessToken && $accessToken instanceof Zend_Oauth_Token_Access) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   193
            $oauthOptions['token'] = $accessToken;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   194
            $this->setHttpClient($accessToken->getHttpClient($oauthOptions, self::OAUTH_BASE_URI, $httpClientOptions));
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   195
            return;
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   196
        }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   197
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   198
        // See if we were passed an http client
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   199
        if (isset($options['httpClient']) && null === $httpClient) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   200
            $httpClient = $options['httpClient'];
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   201
        } elseif (isset($options['http_client']) && null === $httpClient) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   202
            $httpClient = $options['http_client'];
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   203
        }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   204
        if ($httpClient instanceof Zend_Http_Client) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   205
            $this->httpClient = $httpClient;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   206
        } else {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   207
            $this->setHttpClient(new Zend_Http_Client(null, $httpClientOptions));
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   208
        }
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   209
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   210
        // Set the OAuth consumer
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   211
        if ($consumer === null) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   212
            $consumer = new Zend_Oauth_Consumer($oauthOptions);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   213
        }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   214
        $this->oauthConsumer = $consumer;
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   215
    }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   216
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   217
    /**
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   218
     * Proxy service methods
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   219
     *
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   220
     * @param  string $type
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   221
     * @return Twitter
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   222
     * @throws Exception\DomainException If method not in method types list
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   223
     */
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   224
    public function __get($type)
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   225
    {
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   226
        $type = strtolower($type);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   227
        $type = str_replace('_', '', $type);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   228
        if (!in_array($type, $this->methodTypes)) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   229
            require_once 'Zend/Service/Twitter/Exception.php';
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   230
            throw new Zend_Service_Twitter_Exception(
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   231
                'Invalid method type "' . $type . '"'
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   232
            );
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   233
        }
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   234
        $this->methodType = $type;
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   235
        return $this;
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   236
    }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   237
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   238
    /**
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   239
     * Method overloading
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   240
     *
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   241
     * @param  string $method
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   242
     * @param  array $params
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   243
     * @return mixed
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   244
     * @throws Exception\BadMethodCallException if unable to find method
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   245
     */
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   246
    public function __call($method, $params)
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   247
    {
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   248
        if (method_exists($this->oauthConsumer, $method)) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   249
            $return = call_user_func_array(array($this->oauthConsumer, $method), $params);
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   250
            if ($return instanceof Zend_Oauth_Token_Access) {
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   251
                $this->setHttpClient($return->getHttpClient($this->options));
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   252
            }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   253
            return $return;
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   254
        }
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   255
        if (empty($this->methodType)) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   256
            require_once 'Zend/Service/Twitter/Exception.php';
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   257
            throw new Zend_Service_Twitter_Exception(
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   258
                'Invalid method "' . $method . '"'
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   259
            );
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   260
        }
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   261
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   262
        $test = str_replace('_', '', strtolower($method));
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   263
        $test = $this->methodType . $test;
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   264
        if (!method_exists($this, $test)) {
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   265
            require_once 'Zend/Service/Twitter/Exception.php';
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   266
            throw new Zend_Service_Twitter_Exception(
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   267
                'Invalid method "' . $test . '"'
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   268
            );
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   269
        }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   270
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   271
        return call_user_func_array(array($this, $test), $params);
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   272
    }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   273
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   274
    /**
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   275
     * Set HTTP client
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   276
     *
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   277
     * @param Zend_Http_Client $client
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   278
     * @return self
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   279
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   280
    public function setHttpClient(Zend_Http_Client $client)
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   281
    {
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   282
        $this->httpClient = $client;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   283
        $this->httpClient->setHeaders(array('Accept-Charset' => 'ISO-8859-1,utf-8'));
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   284
        return $this;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   285
    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   286
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   287
    /**
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   288
     * Get the HTTP client
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   289
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   290
     * Lazy loads one if none present
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   291
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   292
     * @return Zend_Http_Client
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   293
     */
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   294
    public function getHttpClient()
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   295
    {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   296
        if (null === $this->httpClient) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   297
            $this->setHttpClient(new Zend_Http_Client());
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   298
        }
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   299
        return $this->httpClient;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   300
    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   301
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   302
    /**
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   303
     * Retrieve username
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   304
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   305
     * @return string
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   306
     */
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   307
    public function getUsername()
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   308
    {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   309
        return $this->username;
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   310
    }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   311
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   312
    /**
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   313
     * Set username
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   314
     *
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   315
     * @param  string $value
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   316
     * @return self
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   317
     */
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   318
    public function setUsername($value)
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   319
    {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   320
        $this->username = $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   321
        return $this;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   322
    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   323
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   324
    /**
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   325
     * Checks for an authorised state
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   326
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   327
     * @return bool
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   328
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   329
    public function isAuthorised()
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   330
    {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   331
        if ($this->getHttpClient() instanceof Zend_Oauth_Client) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   332
            return true;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   333
        }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   334
        return false;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   335
    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   336
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   337
    /**
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   338
     * Verify Account Credentials
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   339
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   340
     * @throws Zend_Http_Client_Exception if HTTP request fails or times out
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   341
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   342
     * @return Zend_Service_Twitter_Response
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   343
     */
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   344
    public function accountVerifyCredentials()
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   345
    {
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   346
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   347
        $response = $this->get('account/verify_credentials');
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   348
        return new Zend_Service_Twitter_Response($response);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   349
    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   350
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   351
    /**
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   352
     * Returns the number of api requests you have left per hour.
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   353
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   354
     * @todo   Have a separate payload object to represent rate limits
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   355
     * @throws Zend_Http_Client_Exception if HTTP request fails or times out
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   356
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   357
     * @return Zend_Service_Twitter_Response
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   358
     */
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   359
    public function applicationRateLimitStatus()
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   360
    {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   361
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   362
        $response = $this->get('application/rate_limit_status');
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   363
        return new Zend_Service_Twitter_Response($response);
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   364
    }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   365
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   366
    /**
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   367
     * Blocks the user specified in the ID parameter as the authenticating user.
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   368
     * Destroys a friendship to the blocked user if it exists.
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   369
     *
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   370
     * @param  integer|string $id       The ID or screen name of a user to block.
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   371
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   372
     * @return Zend_Service_Twitter_Response
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   373
     */
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   374
    public function blocksCreate($id)
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   375
    {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   376
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   377
        $path     = 'blocks/create';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   378
        $params   = $this->createUserParameter($id, array());
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   379
        $response = $this->post($path, $params);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   380
        return new Zend_Service_Twitter_Response($response);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   381
    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   382
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   383
    /**
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   384
     * Un-blocks the user specified in the ID parameter for the authenticating user
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   385
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   386
     * @param  integer|string $id       The ID or screen_name of the user to un-block.
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   387
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   388
     * @return Zend_Service_Twitter_Response
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   389
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   390
    public function blocksDestroy($id)
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   391
    {
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   392
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   393
        $path   = 'blocks/destroy';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   394
        $params = $this->createUserParameter($id, array());
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   395
        $response = $this->post($path, $params);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   396
        return new Zend_Service_Twitter_Response($response);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   397
    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   398
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   399
    /**
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   400
     * Returns an array of user ids that the authenticating user is blocking
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   401
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   402
     * @param  integer $cursor  Optional. Specifies the cursor position at which to begin listing ids; defaults to first "page" of results.
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   403
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   404
     * @return Zend_Service_Twitter_Response
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   405
     */
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   406
    public function blocksIds($cursor = -1)
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   407
    {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   408
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   409
        $path = 'blocks/ids';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   410
        $response = $this->get($path, array('cursor' => $cursor));
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   411
        return new Zend_Service_Twitter_Response($response);
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   412
    }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   413
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   414
    /**
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   415
     * Returns an array of user objects that the authenticating user is blocking
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   416
     *
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   417
     * @param  integer $cursor  Optional. Specifies the cursor position at which to begin listing ids; defaults to first "page" of results.
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   418
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   419
     * @return Zend_Service_Twitter_Response
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   420
     */
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   421
    public function blocksList($cursor = -1)
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   422
    {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   423
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   424
        $path = 'blocks/list';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   425
        $response = $this->get($path, array('cursor' => $cursor));
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   426
        return new Zend_Service_Twitter_Response($response);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   427
    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   428
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   429
    /**
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   430
     * Destroy a direct message
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   431
     *
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   432
     * @param  int $id ID of message to destroy
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   433
     * @throws Zend_Http_Client_Exception if HTTP request fails or times out
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   434
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   435
     * @return Zend_Service_Twitter_Response
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   436
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   437
    public function directMessagesDestroy($id)
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   438
    {
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   439
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   440
        $path     = 'direct_messages/destroy';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   441
        $params   = array('id' => $this->validInteger($id));
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   442
        $response = $this->post($path, $params);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   443
        return new Zend_Service_Twitter_Response($response);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   444
    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   445
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   446
    /**
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   447
     * Retrieve direct messages for the current user
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   448
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   449
     * $options may include one or more of the following keys
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   450
     * - count: return page X of results
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   451
     * - since_id: return statuses only greater than the one specified
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   452
     * - max_id: return statuses with an ID less than (older than) or equal to that specified
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   453
     * - include_entities: setting to false will disable embedded entities
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   454
     * - skip_status:setting to true, "t", or 1 will omit the status in returned users
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   455
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   456
     * @param  array $options
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   457
     * @throws Zend_Http_Client_Exception if HTTP request fails or times out
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   458
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   459
     * @return Zend_Service_Twitter_Response
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   460
     */
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   461
    public function directMessagesMessages(array $options = array())
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   462
    {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   463
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   464
        $path   = 'direct_messages';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   465
        $params = array();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   466
        foreach ($options as $key => $value) {
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   467
            switch (strtolower($key)) {
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   468
                case 'count':
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   469
                    $params['count'] = (int) $value;
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   470
                    break;
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   471
                case 'since_id':
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   472
                    $params['since_id'] = $this->validInteger($value);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   473
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   474
                case 'max_id':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   475
                    $params['max_id'] = $this->validInteger($value);
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   476
                    break;
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   477
                case 'include_entities':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   478
                    $params['include_entities'] = (bool) $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   479
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   480
                case 'skip_status':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   481
                    $params['skip_status'] = (bool) $value;
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   482
                    break;
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   483
                default:
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   484
                    break;
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   485
            }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   486
        }
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   487
        $response = $this->get($path, $params);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   488
        return new Zend_Service_Twitter_Response($response);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   489
    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   490
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   491
    /**
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   492
     * Send a direct message to a user
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   493
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   494
     * @param  int|string $user User to whom to send message
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   495
     * @param  string $text Message to send to user
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   496
     * @throws Exception\InvalidArgumentException if message is empty
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   497
     * @throws Exception\OutOfRangeException if message is too long
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   498
     * @throws Zend_Http_Client_Exception if HTTP request fails or times out
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   499
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   500
     * @return Zend_Service_Twitter_Response
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   501
     */
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   502
    public function directMessagesNew($user, $text)
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   503
    {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   504
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   505
        $path = 'direct_messages/new';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   506
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   507
        $len = iconv_strlen($text, 'UTF-8');
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   508
        if (0 == $len) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   509
            require_once 'Zend/Service/Twitter/Exception.php';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   510
            throw new Zend_Service_Twitter_Exception(
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   511
                'Direct message must contain at least one character'
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   512
            );
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   513
        } elseif (140 < $len) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   514
            require_once 'Zend/Service/Twitter/Exception.php';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   515
            throw new Zend_Service_Twitter_Exception(
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   516
                'Direct message must contain no more than 140 characters'
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   517
            );
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   518
        }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   519
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   520
        $params         = $this->createUserParameter($user, array());
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   521
        $params['text'] = $text;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   522
        $response       = $this->post($path, $params);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   523
        return new Zend_Service_Twitter_Response($response);
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   524
    }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   525
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   526
    /**
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   527
     * Retrieve list of direct messages sent by current user
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   528
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   529
     * $options may include one or more of the following keys
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   530
     * - count: return page X of results
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   531
     * - page: return starting at page
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   532
     * - since_id: return statuses only greater than the one specified
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   533
     * - max_id: return statuses with an ID less than (older than) or equal to that specified
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   534
     * - include_entities: setting to false will disable embedded entities
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   535
     *
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   536
     * @param  array $options
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   537
     * @throws Zend_Http_Client_Exception if HTTP request fails or times out
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   538
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   539
     * @return Zend_Service_Twitter_Response
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   540
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   541
    public function directMessagesSent(array $options = array())
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   542
    {
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   543
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   544
        $path   = 'direct_messages/sent';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   545
        $params = array();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   546
        foreach ($options as $key => $value) {
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   547
            switch (strtolower($key)) {
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   548
                case 'count':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   549
                    $params['count'] = (int) $value;
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   550
                    break;
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   551
                case 'page':
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   552
                    $params['page'] = (int) $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   553
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   554
                case 'since_id':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   555
                    $params['since_id'] = $this->validInteger($value);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   556
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   557
                case 'max_id':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   558
                    $params['max_id'] = $this->validInteger($value);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   559
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   560
                case 'include_entities':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   561
                    $params['include_entities'] = (bool) $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   562
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   563
                default:
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   564
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   565
            }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   566
        }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   567
        $response = $this->get($path, $params);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   568
        return new Zend_Service_Twitter_Response($response);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   569
    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   570
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   571
    /**
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   572
     * Mark a status as a favorite
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   573
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   574
     * @param  int $id Status ID you want to mark as a favorite
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   575
     * @throws Zend_Http_Client_Exception if HTTP request fails or times out
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   576
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   577
     * @return Zend_Service_Twitter_Response
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   578
     */
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   579
    public function favoritesCreate($id)
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   580
    {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   581
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   582
        $path     = 'favorites/create';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   583
        $params   = array('id' => $this->validInteger($id));
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   584
        $response = $this->post($path, $params);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   585
        return new Zend_Service_Twitter_Response($response);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   586
    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   587
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   588
    /**
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   589
     * Remove a favorite
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   590
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   591
     * @param  int $id Status ID you want to de-list as a favorite
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   592
     * @throws Zend_Http_Client_Exception if HTTP request fails or times out
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   593
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   594
     * @return Zend_Service_Twitter_Response
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   595
     */
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   596
    public function favoritesDestroy($id)
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   597
    {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   598
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   599
        $path     = 'favorites/destroy';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   600
        $params   = array('id' => $this->validInteger($id));
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   601
        $response = $this->post($path, $params);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   602
        return new Zend_Service_Twitter_Response($response);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   603
    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   604
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   605
    /**
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   606
     * Fetch favorites
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   607
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   608
     * $options may contain one or more of the following:
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   609
     * - user_id: Id of a user for whom to fetch favorites
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   610
     * - screen_name: Screen name of a user for whom to fetch favorites
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   611
     * - count: number of tweets to attempt to retrieve, up to 200
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   612
     * - since_id: return results only after the specified tweet id
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   613
     * - max_id: return results with an ID less than (older than) or equal to the specified ID
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   614
     * - include_entities: when set to false, entities member will be omitted
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   615
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   616
     * @param  array $params
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   617
     * @throws Zend_Http_Client_Exception if HTTP request fails or times out
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   618
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   619
     * @return Zend_Service_Twitter_Response
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   620
     */
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   621
    public function favoritesList(array $options = array())
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   622
    {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   623
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   624
        $path = 'favorites/list';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   625
        $params = array();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   626
        foreach ($options as $key => $value) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   627
            switch (strtolower($key)) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   628
                case 'user_id':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   629
                    $params['user_id'] = $this->validInteger($value);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   630
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   631
                case 'screen_name':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   632
                    $params['screen_name'] = $value;
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   633
                    break;
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   634
                case 'count':
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   635
                    $params['count'] = (int) $value;
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   636
                    break;
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   637
                case 'since_id':
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   638
                    $params['since_id'] = $this->validInteger($value);
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   639
                    break;
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   640
                case 'max_id':
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   641
                    $params['max_id'] = $this->validInteger($value);
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   642
                    break;
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   643
                case 'include_entities':
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   644
                    $params['include_entities'] = (bool) $value;
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   645
                    break;
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   646
                default:
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   647
                    break;
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   648
            }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   649
        }
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   650
        $response = $this->get($path, $params);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   651
        return new Zend_Service_Twitter_Response($response);
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   652
    }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   653
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   654
    /**
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   655
     * Create friendship
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   656
     *
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   657
     * @param  int|string $id User ID or name of new friend
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   658
     * @param  array $params Additional parameters to pass
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   659
     * @throws Zend_Http_Client_Exception if HTTP request fails or times out
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   660
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   661
     * @return Zend_Service_Twitter_Response
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   662
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   663
    public function friendshipsCreate($id, array $params = array())
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   664
    {
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   665
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   666
        $path    = 'friendships/create';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   667
        $params  = $this->createUserParameter($id, $params);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   668
        $allowed = array(
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   669
            'user_id'     => null,
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   670
            'screen_name' => null,
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   671
            'follow'      => null,
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   672
        );
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   673
        $params = array_intersect_key($params, $allowed);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   674
        $response = $this->post($path, $params);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   675
        return new Zend_Service_Twitter_Response($response);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   676
    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   677
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   678
    /**
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   679
     * Destroy friendship
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   680
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   681
     * @param  int|string $id User ID or name of friend to remove
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   682
     * @throws Zend_Http_Client_Exception if HTTP request fails or times out
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   683
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   684
     * @return Zend_Service_Twitter_Response
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   685
     */
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   686
    public function friendshipsDestroy($id)
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   687
    {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   688
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   689
        $path     = 'friendships/destroy';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   690
        $params   = $this->createUserParameter($id, array());
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   691
        $response = $this->post($path, $params);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   692
        return new Zend_Service_Twitter_Response($response);
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   693
    }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   694
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   695
    /**
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   696
     * Search tweets
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   697
     *
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   698
     * $options may include any of the following:
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   699
     * - geocode: a string of the form "latitude, longitude, radius"
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   700
     * - lang: restrict tweets to the two-letter language code
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   701
     * - locale: query is in the given two-letter language code
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   702
     * - result_type: what type of results to receive: mixed, recent, or popular
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   703
     * - count: number of tweets to return per page; up to 100
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   704
     * - until: return tweets generated before the given date
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   705
     * - since_id: return resutls with an ID greater than (more recent than) the given ID
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   706
     * - max_id: return results with an ID less than (older than) the given ID
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   707
     * - include_entities: whether or not to include embedded entities
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   708
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   709
     * @param  string $query
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   710
     * @param  array $options
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   711
     * @throws Zend_Http_Client_Exception if HTTP request fails or times out
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   712
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   713
     * @return Zend_Service_Twitter_Response
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   714
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   715
    public function searchTweets($query, array $options = array())
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   716
    {
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   717
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   718
        $path = 'search/tweets';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   719
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   720
        $len = iconv_strlen($query, 'UTF-8');
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   721
        if (0 == $len) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   722
            require_once 'Zend/Service/Twitter/Exception.php';
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   723
            throw new Zend_Service_Twitter_Exception(
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   724
                'Query must contain at least one character'
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   725
            );
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   726
        }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   727
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   728
        $params = array('q' => $query);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   729
        foreach ($options as $key => $value) {
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   730
            switch (strtolower($key)) {
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   731
                case 'geocode':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   732
                    if (!substr_count($value, ',') !== 2) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   733
                        require_once 'Zend/Service/Twitter/Exception.php';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   734
                        throw new Zend_Service_Twitter_Exception(
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   735
                            '"geocode" must be of the format "latitude,longitude,radius"'
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   736
                        );
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   737
                    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   738
                    list($latitude, $longitude, $radius) = explode(',', $value);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   739
                    $radius = trim($radius);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   740
                    if (!preg_match('/^\d+(mi|km)$/', $radius)) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   741
                        require_once 'Zend/Service/Twitter/Exception.php';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   742
                        throw new Zend_Service_Twitter_Exception(
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   743
                            'Radius segment of "geocode" must be of the format "[unit](mi|km)"'
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   744
                        );
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   745
                    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   746
                    $latitude  = (float) $latitude;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   747
                    $longitude = (float) $longitude;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   748
                    $params['geocode'] = $latitude . ',' . $longitude . ',' . $radius;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   749
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   750
                case 'lang':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   751
                    if (strlen($value) > 2) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   752
                        require_once 'Zend/Service/Twitter/Exception.php';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   753
                        throw new Zend_Service_Twitter_Exception(
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   754
                            'Query language must be a 2 character string'
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   755
                        );
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   756
                    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   757
                    $params['lang'] = strtolower($value);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   758
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   759
                case 'locale':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   760
                    if (strlen($value) > 2) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   761
                        require_once 'Zend/Service/Twitter/Exception.php';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   762
                        throw new Zend_Service_Twitter_Exception(
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   763
                            'Query locale must be a 2 character string'
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   764
                        );
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   765
                    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   766
                    $params['locale'] = strtolower($value);
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   767
                    break;
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   768
                case 'result_type':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   769
                    $value = strtolower($value);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   770
                    if (!in_array($value, array('mixed', 'recent', 'popular'))) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   771
                        require_once 'Zend/Service/Twitter/Exception.php';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   772
                        throw new Zend_Service_Twitter_Exception(
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   773
                            'result_type must be one of "mixed", "recent", or "popular"'
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   774
                        );
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   775
                    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   776
                    $params['result_type'] = $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   777
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   778
                case 'count':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   779
                    $value = (int) $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   780
                    if (1 > $value || 100 < $value) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   781
                        require_once 'Zend/Service/Twitter/Exception.php';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   782
                        throw new Zend_Service_Twitter_Exception(
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   783
                            'count must be between 1 and 100'
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   784
                        );
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   785
                    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   786
                    $params['count'] = $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   787
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   788
                case 'until':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   789
                    if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $value)) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   790
                        require_once 'Zend/Service/Twitter/Exception.php';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   791
                        throw new Zend_Service_Twitter_Exception(
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   792
                            '"until" must be a date in the format YYYY-MM-DD'
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   793
                        );
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   794
                    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   795
                    $params['until'] = $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   796
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   797
                case 'since_id':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   798
                    $params['since_id'] = $this->validInteger($value);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   799
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   800
                case 'max_id':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   801
                    $params['max_id'] = $this->validInteger($value);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   802
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   803
                case 'include_entities':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   804
                    $params['include_entities'] = (bool) $value;
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   805
                    break;
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   806
                default:
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   807
                    break;
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   808
            }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   809
        }
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   810
        $response = $this->get($path, $params);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   811
        return new Zend_Service_Twitter_Response($response);
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   812
    }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   813
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   814
    /**
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   815
     * Destroy a status message
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   816
     *
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   817
     * @param  int $id ID of status to destroy
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   818
     * @throws Zend_Http_Client_Exception if HTTP request fails or times out
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   819
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   820
     * @return Zend_Service_Twitter_Response
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   821
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   822
    public function statusesDestroy($id)
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   823
    {
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   824
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   825
        $path = 'statuses/destroy/' . $this->validInteger($id);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   826
        $response = $this->post($path);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   827
        return new Zend_Service_Twitter_Response($response);
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   828
    }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   829
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   830
    /**
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   831
     * Friend Timeline Status
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   832
     *
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   833
     * $options may include one or more of the following keys
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   834
     * - count: number of tweets to attempt to retrieve, up to 200
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   835
     * - since_id: return results only after the specified tweet id
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   836
     * - max_id: return results with an ID less than (older than) or equal to the specified ID
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   837
     * - trim_user: when set to true, "t", or 1, user object in tweets will include only author's ID.
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   838
     * - contributor_details: when set to true, includes screen_name of each contributor
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   839
     * - include_entities: when set to false, entities member will be omitted
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   840
     * - exclude_replies: when set to true, will strip replies appearing in the timeline
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   841
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   842
     * @param  array $params
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   843
     * @throws Zend_Http_Client_Exception if HTTP request fails or times out
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   844
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   845
     * @return Zend_Service_Twitter_Response
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   846
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   847
    public function statusesHomeTimeline(array $options = array())
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   848
    {
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   849
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   850
        $path = 'statuses/home_timeline';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   851
        $params = array();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   852
        foreach ($options as $key => $value) {
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   853
            switch (strtolower($key)) {
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   854
                case 'count':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   855
                    $params['count'] = (int) $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   856
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   857
                case 'since_id':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   858
                    $params['since_id'] = $this->validInteger($value);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   859
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   860
                case 'max_id':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   861
                    $params['max_id'] = $this->validInteger($value);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   862
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   863
                case 'trim_user':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   864
                    if (in_array($value, array(true, 'true', 't', 1, '1'))) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   865
                        $value = true;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   866
                    } else {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   867
                        $value = false;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   868
                    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   869
                    $params['trim_user'] = $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   870
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   871
                case 'contributor_details:':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   872
                    $params['contributor_details:'] = (bool) $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   873
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   874
                case 'include_entities':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   875
                    $params['include_entities'] = (bool) $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   876
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   877
                case 'exclude_replies':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   878
                    $params['exclude_replies'] = (bool) $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   879
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   880
                default:
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   881
                    break;
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   882
            }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   883
        }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   884
        $response = $this->get($path, $params);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   885
        return new Zend_Service_Twitter_Response($response);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   886
    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   887
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   888
    /**
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   889
     * Get status replies
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   890
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   891
     * $options may include one or more of the following keys
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   892
     * - count: number of tweets to attempt to retrieve, up to 200
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   893
     * - since_id: return results only after the specified tweet id
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   894
     * - max_id: return results with an ID less than (older than) or equal to the specified ID
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   895
     * - trim_user: when set to true, "t", or 1, user object in tweets will include only author's ID.
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   896
     * - contributor_details: when set to true, includes screen_name of each contributor
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   897
     * - include_entities: when set to false, entities member will be omitted
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   898
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   899
     * @param  array $options
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   900
     * @throws Zend_Http_Client_Exception if HTTP request fails or times out
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   901
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   902
     * @return Zend_Service_Twitter_Response
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   903
     */
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   904
    public function statusesMentionsTimeline(array $options = array())
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   905
    {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   906
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   907
        $path   = 'statuses/mentions_timeline';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   908
        $params = array();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   909
        foreach ($options as $key => $value) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   910
            switch (strtolower($key)) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   911
                case 'count':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   912
                    $params['count'] = (int) $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   913
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   914
                case 'since_id':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   915
                    $params['since_id'] = $this->validInteger($value);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   916
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   917
                case 'max_id':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   918
                    $params['max_id'] = $this->validInteger($value);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   919
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   920
                case 'trim_user':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   921
                    if (in_array($value, array(true, 'true', 't', 1, '1'))) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   922
                        $value = true;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   923
                    } else {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   924
                        $value = false;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   925
                    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   926
                    $params['trim_user'] = $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   927
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   928
                case 'contributor_details:':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   929
                    $params['contributor_details:'] = (bool) $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   930
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   931
                case 'include_entities':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   932
                    $params['include_entities'] = (bool) $value;
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   933
                    break;
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   934
                default:
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   935
                    break;
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   936
            }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   937
        }
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   938
        $response = $this->get($path, $params);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   939
        return new Zend_Service_Twitter_Response($response);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   940
    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   941
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   942
    /**
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   943
     * Public Timeline status
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   944
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   945
     * @throws Zend_Http_Client_Exception if HTTP request fails or times out
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   946
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   947
     * @return Zend_Service_Twitter_Response
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   948
     */
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   949
    public function statusesSample()
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   950
    {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   951
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   952
        $path = 'statuses/sample';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   953
        $response = $this->get($path);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   954
        return new Zend_Service_Twitter_Response($response);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   955
    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   956
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   957
    /**
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   958
     * Show a single status
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   959
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   960
     * @param  int $id Id of status to show
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   961
     * @throws Zend_Http_Client_Exception if HTTP request fails or times out
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   962
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   963
     * @return Zend_Service_Twitter_Response
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   964
     */
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   965
    public function statusesShow($id)
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   966
    {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   967
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   968
        $path = 'statuses/show/' . $this->validInteger($id);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   969
        $response = $this->get($path);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   970
        return new Zend_Service_Twitter_Response($response);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   971
    }
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   972
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   973
    /**
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   974
     * Update user's current status
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   975
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   976
     * @todo   Support additional parameters supported by statuses/update endpoint
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   977
     * @param  string $status
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   978
     * @param  null|int $inReplyToStatusId
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   979
     * @throws Zend_Http_Client_Exception if HTTP request fails or times out
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   980
     * @throws Exception\OutOfRangeException if message is too long
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   981
     * @throws Exception\InvalidArgumentException if message is empty
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   982
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   983
     * @return Zend_Service_Twitter_Response
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   984
     */
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   985
    public function statusesUpdate($status, $inReplyToStatusId = null)
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   986
    {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   987
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   988
        $path = 'statuses/update';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   989
        $len = iconv_strlen(htmlspecialchars($status, ENT_QUOTES, 'UTF-8'), 'UTF-8');
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   990
        if ($len > self::STATUS_MAX_CHARACTERS) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   991
            require_once 'Zend/Service/Twitter/Exception.php';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   992
            throw new Zend_Service_Twitter_Exception(
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   993
                'Status must be no more than '
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   994
                . self::STATUS_MAX_CHARACTERS
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   995
                . ' characters in length'
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   996
            );
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   997
        } elseif (0 == $len) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   998
            require_once 'Zend/Service/Twitter/Exception.php';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
   999
            throw new Zend_Service_Twitter_Exception(
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1000
                'Status must contain at least one character'
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1001
            );
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1002
        }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1003
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1004
        $params = array('status' => $status);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1005
        $inReplyToStatusId = $this->validInteger($inReplyToStatusId);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1006
        if ($inReplyToStatusId) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1007
            $params['in_reply_to_status_id'] = $inReplyToStatusId;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1008
        }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1009
        $response = $this->post($path, $params);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1010
        return new Zend_Service_Twitter_Response($response);
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1011
    }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1012
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1013
    /**
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1014
     * User Timeline status
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1015
     *
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1016
     * $options may include one or more of the following keys
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1017
     * - user_id: Id of a user for whom to fetch favorites
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1018
     * - screen_name: Screen name of a user for whom to fetch favorites
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1019
     * - count: number of tweets to attempt to retrieve, up to 200
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1020
     * - since_id: return results only after the specified tweet id
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1021
     * - max_id: return results with an ID less than (older than) or equal to the specified ID
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1022
     * - trim_user: when set to true, "t", or 1, user object in tweets will include only author's ID.
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1023
     * - exclude_replies: when set to true, will strip replies appearing in the timeline
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1024
     * - contributor_details: when set to true, includes screen_name of each contributor
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1025
     * - include_rts: when set to false, will strip native retweets
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1026
     *
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1027
     * @throws Zend_Http_Client_Exception if HTTP request fails or times out
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1028
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1029
     * @return Zend_Service_Twitter_Response
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1030
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1031
    public function statusesUserTimeline(array $options = array())
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1032
    {
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1033
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1034
        $path = 'statuses/user_timeline';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1035
        $params = array();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1036
        foreach ($options as $key => $value) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1037
            switch (strtolower($key)) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1038
                case 'user_id':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1039
                    $params['user_id'] = $this->validInteger($value);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1040
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1041
                case 'screen_name':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1042
                    $params['screen_name'] = $this->validateScreenName($value);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1043
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1044
                case 'count':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1045
                    $params['count'] = (int) $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1046
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1047
                case 'since_id':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1048
                    $params['since_id'] = $this->validInteger($value);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1049
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1050
                case 'max_id':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1051
                    $params['max_id'] = $this->validInteger($value);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1052
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1053
                case 'trim_user':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1054
                    if (in_array($value, array(true, 'true', 't', 1, '1'))) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1055
                        $value = true;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1056
                    } else {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1057
                        $value = false;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1058
                    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1059
                    $params['trim_user'] = $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1060
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1061
                case 'contributor_details:':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1062
                    $params['contributor_details:'] = (bool) $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1063
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1064
                case 'exclude_replies':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1065
                    $params['exclude_replies'] = (bool) $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1066
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1067
                case 'include_rts':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1068
                    $params['include_rts'] = (bool) $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1069
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1070
                default:
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1071
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1072
            }
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1073
        }
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1074
        $response = $this->get($path, $params);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1075
        return new Zend_Service_Twitter_Response($response);
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1076
    }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1077
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1078
    /**
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1079
     * Search users
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1080
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1081
     * $options may include any of the following:
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1082
     * - page: the page of results to retrieve
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1083
     * - count: the number of users to retrieve per page; max is 20
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1084
     * - include_entities: if set to boolean true, include embedded entities
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1085
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1086
     * @param  string $query
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1087
     * @param  array $options
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1088
     * @throws Zend_Http_Client_Exception if HTTP request fails or times out
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1089
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1090
     * @return Zend_Service_Twitter_Response
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1091
     */
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1092
    public function usersSearch($query, array $options = array())
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1093
    {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1094
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1095
        $path = 'users/search';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1096
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1097
        $len = iconv_strlen($query, 'UTF-8');
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1098
        if (0 == $len) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1099
            require_once 'Zend/Service/Twitter/Exception.php';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1100
            throw new Zend_Service_Twitter_Exception(
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1101
                'Query must contain at least one character'
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1102
            );
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1103
        }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1104
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1105
        $params = array('q' => $query);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1106
        foreach ($options as $key => $value) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1107
            switch (strtolower($key)) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1108
                case 'count':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1109
                    $value = (int) $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1110
                    if (1 > $value || 20 < $value) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1111
                        require_once 'Zend/Service/Twitter/Exception.php';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1112
                        throw new Zend_Service_Twitter_Exception(
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1113
                            'count must be between 1 and 20'
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1114
                        );
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1115
                    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1116
                    $params['count'] = $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1117
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1118
                case 'page':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1119
                    $params['page'] = (int) $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1120
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1121
                case 'include_entities':
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1122
                    $params['include_entities'] = (bool) $value;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1123
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1124
                default:
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1125
                    break;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1126
            }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1127
        }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1128
        $response = $this->get($path, $params);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1129
        return new Zend_Service_Twitter_Response($response);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1130
    }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1131
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1132
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1133
    /**
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1134
     * Show extended information on a user
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1135
     *
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1136
     * @param  int|string $id User ID or name
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1137
     * @throws Zend_Http_Client_Exception if HTTP request fails or times out
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1138
     * @throws Exception\DomainException if unable to decode JSON payload
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1139
     * @return Zend_Service_Twitter_Response
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1140
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1141
    public function usersShow($id)
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1142
    {
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1143
        $this->init();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1144
        $path     = 'users/show';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1145
        $params   = $this->createUserParameter($id, array());
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1146
        $response = $this->get($path, $params);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1147
        return new Zend_Service_Twitter_Response($response);
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1148
    }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1149
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1150
    /**
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1151
     * Initialize HTTP authentication
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1152
     *
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1153
     * @return void
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1154
     * @throws Exception\DomainException if unauthorised
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1155
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1156
    protected function init()
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1157
    {
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1158
        if (!$this->isAuthorised() && $this->getUsername() !== null) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1159
            require_once 'Zend/Service/Twitter/Exception.php';
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1160
            throw new Zend_Service_Twitter_Exception(
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1161
                'Twitter session is unauthorised. You need to initialize '
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1162
                . __CLASS__ . ' with an OAuth Access Token or use '
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1163
                . 'its OAuth functionality to obtain an Access Token before '
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1164
                . 'attempting any API actions that require authorisation'
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1165
            );
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1166
        }
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1167
        $client = $this->getHttpClient();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1168
        $client->resetParameters();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1169
        if (null === $this->cookieJar) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1170
            $cookieJar = $client->getCookieJar();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1171
            if (null === $cookieJar) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1172
                $cookieJar = new Zend_Http_CookieJar();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1173
            }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1174
            $this->cookieJar = $cookieJar;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1175
            $this->cookieJar->reset();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1176
        } else {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1177
            $client->setCookieJar($this->cookieJar);
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1178
        }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1179
    }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1180
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1181
    /**
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1182
     * Protected function to validate that the integer is valid or return a 0
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1183
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1184
     * @param  $int
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1185
     * @throws Zend_Http_Client_Exception if HTTP request fails or times out
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1186
     * @return integer
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1187
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1188
    protected function validInteger($int)
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1189
    {
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1190
        if (preg_match("/(\d+)/", $int)) {
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1191
            return $int;
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1192
        }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1193
        return 0;
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1194
    }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1195
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1196
    /**
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1197
     * Validate a screen name using Twitter rules
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1198
     *
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1199
     * @param string $name
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1200
     * @return string
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1201
     * @throws Exception\InvalidArgumentException
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1202
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1203
    protected function validateScreenName($name)
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1204
    {
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1205
        if (!preg_match('/^[a-zA-Z0-9_]{0,20}$/', $name)) {
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1206
            require_once 'Zend/Service/Twitter/Exception.php';
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1207
            throw new Zend_Service_Twitter_Exception(
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1208
                'Screen name, "' . $name
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1209
                . '" should only contain alphanumeric characters and'
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1210
                . ' underscores, and not exceed 15 characters.');
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1211
        }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1212
        return $name;
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1213
    }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1214
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1215
    /**
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1216
     * Call a remote REST web service URI
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1217
     *
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1218
     * @param  string $path The path to append to the URI
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1219
     * @param  Zend_Http_Client $client
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1220
     * @throws Zend_Http_Client_Exception
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1221
     * @return void
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1222
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1223
    protected function prepare($path, Zend_Http_Client $client)
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1224
    {
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1225
        $client->setUri(self::API_BASE_URI . $path . '.json');
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1226
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1227
        /**
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1228
         * Do this each time to ensure oauth calls do not inject new params
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1229
         */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1230
        $client->resetParameters();
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1231
    }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1232
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1233
    /**
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1234
     * Performs an HTTP GET request to the $path.
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1235
     *
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1236
     * @param string $path
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1237
     * @param array  $query Array of GET parameters
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1238
     * @throws Zend_Http_Client_Exception
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1239
     * @return Zend_Http_Response
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1240
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1241
    protected function get($path, array $query = array())
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1242
    {
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1243
        $client = $this->getHttpClient();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1244
        $this->prepare($path, $client);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1245
        $client->setParameterGet($query);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1246
        $response = $client->request(Zend_Http_Client::GET);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1247
        return $response;
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1248
    }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1249
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1250
    /**
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1251
     * Performs an HTTP POST request to $path.
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1252
     *
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1253
     * @param string $path
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1254
     * @param mixed $data Raw data to send
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1255
     * @throws Zend_Http_Client_Exception
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1256
     * @return Zend_Http_Response
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1257
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1258
    protected function post($path, $data = null)
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1259
    {
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1260
        $client = $this->getHttpClient();
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1261
        $this->prepare($path, $client);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1262
        $response = $this->performPost(Zend_Http_Client::POST, $data, $client);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1263
        return $response;
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1264
    }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1265
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1266
    /**
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1267
     * Perform a POST or PUT
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1268
     *
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1269
     * Performs a POST or PUT request. Any data provided is set in the HTTP
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1270
     * client. String data is pushed in as raw POST data; array or object data
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1271
     * is pushed in as POST parameters.
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1272
     *
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1273
     * @param mixed $method
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1274
     * @param mixed $data
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1275
     * @return Zend_Http_Response
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1276
     */
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1277
    protected function performPost($method, $data, Zend_Http_Client $client)
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1278
    {
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1279
        if (is_string($data)) {
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1280
            $client->setRawData($data);
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1281
        } elseif (is_array($data) || is_object($data)) {
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1282
            $client->setParameterPost((array) $data);
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1283
        }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1284
        return $client->request($method);
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1285
    }
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1286
807
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1287
    /**
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1288
     * Create a parameter representing the user
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1289
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1290
     * Determines if $id is an integer, and, if so, sets the "user_id" parameter.
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1291
     * If not, assumes the $id is the "screen_name".
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1292
     *
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1293
     * @param  int|string $id
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1294
     * @param  array $params
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1295
     * @return array
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1296
     */
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1297
    protected function createUserParameter($id, array $params)
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1298
    {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1299
        if ($this->validInteger($id)) {
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1300
            $params['user_id'] = $id;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1301
            return $params;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1302
        }
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1303
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1304
        $params['screen_name'] = $this->validateScreenName($id);
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1305
        return $params;
877f952ae2bd update Zend and twitter oauth end point
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 207
diff changeset
  1306
    }
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
  1307
}