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