Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
block.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Twitter
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die();
11 
12 /**
13  * Twitter API Block class for the Joomla Platform.
14  *
15  * @package Joomla.Platform
16  * @subpackage Twitter
17  * @since 12.3
18  */
20 {
21  /**
22  * Method to get the user ids the authenticating user is blocking.
23  *
24  * @param boolean $stringify_ids Provide this option to have ids returned as strings instead.
25  * @param integer $cursor Causes the list of IDs to be broken into pages of no more than 5000 IDs at a time. The number of IDs returned
26  * is not guaranteed to be 5000 as suspended users are filtered out after connections are queried. If no cursor
27  * is provided, a value of -1 will be assumed, which is the first "page."
28  *
29  * @return array The decoded JSON response
30  *
31  * @since 12.3
32  */
33  public function getBlocking($stringify_ids = null, $cursor = null)
34  {
35  // Check the rate limit for remaining hits
36  $this->checkRateLimit('blocks', 'ids');
37 
38  $data = array();
39 
40  // Check if stringify_ids is specified
41  if (!is_null($stringify_ids))
42  {
43  $data['stringify_ids'] = $stringify_ids;
44  }
45 
46  // Check if cursor is specified
47  if (!is_null($stringify_ids))
48  {
49  $data['cursor'] = $cursor;
50  }
51 
52  // Set the API path
53  $path = '/blocks/ids.json';
54 
55  // Send the request.
56  return $this->sendRequest($path, 'GET', $data);
57  }
58 
59  /**
60  * Method to block the specified user from following the authenticating user.
61  *
62  * @param mixed $user Either an integer containing the user ID or a string containing the screen name.
63  * @param boolean $entities When set to either true, t or 1, each tweet will include a node called "entities,". This node offers a
64  * variety of metadata about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
65  * @param boolean $skip_status When set to either true, t or 1 statuses will not be included in the returned user objects.
66  *
67  * @return array The decoded JSON response
68  *
69  * @since 12.3
70  * @throws RuntimeException
71  */
72  public function block($user, $entities = null, $skip_status = null)
73  {
74  // Check the rate limit for remaining hits
75  $this->checkRateLimit('blocks', 'create');
76 
77  // Determine which type of data was passed for $user
78  if (is_numeric($user))
79  {
80  $data['user_id'] = $user;
81  }
82  elseif (is_string($user))
83  {
84  $data['screen_name'] = $user;
85  }
86  else
87  {
88  // We don't have a valid entry
89  throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
90  }
91 
92  // Check if entities is specified
93  if (!is_null($entities))
94  {
95  $data['include_entities'] = $entities;
96  }
97 
98  // Check if skip_statuses is specified
99  if (!is_null($skip_status))
100  {
101  $data['skip_status'] = $skip_status;
102  }
103 
104  // Set the API path
105  $path = '/blocks/create.json';
106 
107  // Send the request.
108  return $this->sendRequest($path, 'POST', $data);
109  }
110 
111  /**
112  * Method to unblock the specified user from following the authenticating user.
113  *
114  * @param mixed $user Either an integer containing the user ID or a string containing the screen name.
115  * @param boolean $entities When set to either true, t or 1, each tweet will include a node called "entities,". This node offers a
116  * variety of metadata about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
117  * @param boolean $skip_status When set to either true, t or 1 statuses will not be included in the returned user objects.
118  *
119  * @return array The decoded JSON response
120  *
121  * @since 12.3
122  * @throws RuntimeException
123  */
124  public function unblock($user, $entities = null, $skip_status = null)
125  {
126  // Check the rate limit for remaining hits
127  $this->checkRateLimit('blocks', 'destroy');
128 
129  // Determine which type of data was passed for $user
130  if (is_numeric($user))
131  {
132  $data['user_id'] = $user;
133  }
134  elseif (is_string($user))
135  {
136  $data['screen_name'] = $user;
137  }
138  else
139  {
140  // We don't have a valid entry
141  throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
142  }
143 
144  // Check if entities is specified
145  if (!is_null($entities))
146  {
147  $data['include_entities'] = $entities;
148  }
149 
150  // Check if skip_statuses is specified
151  if (!is_null($skip_status))
152  {
153  $data['skip_status'] = $skip_status;
154  }
155 
156  // Set the API path
157  $path = '/blocks/destroy.json';
158 
159  // Send the request.
160  return $this->sendRequest($path, 'POST', $data);
161  }
162 }