Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
directmessages.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 Direct Messages 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 most recent direct messages sent to the authenticating user.
23  *
24  * @param integer $since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
25  * @param integer $max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
26  * @param integer $count Specifies the number of direct messages to try and retrieve, up to a maximum of 200.
27  * @param boolean $entities When set to true, each tweet will include a node called "entities,". This node offers a variety of metadata
28  * about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
29  * @param boolean $skip_status When set to either true, t or 1 statuses will not be included in the returned user objects.
30  *
31  * @return array The decoded JSON response
32  *
33  * @since 12.3
34  */
35  public function getDirectMessages($since_id = 0, $max_id = 0, $count = 20, $entities = null, $skip_status = null)
36  {
37  // Check the rate limit for remaining hits
38  $this->checkRateLimit('direct_messages');
39 
40  // Set the API path
41  $path = '/direct_messages.json';
42 
43  // Check if since_id is specified.
44  if ($since_id)
45  {
46  $data['since_id'] = $since_id;
47  }
48 
49  // Check if max_id is specified.
50  if ($max_id)
51  {
52  $data['max_id'] = $max_id;
53  }
54 
55  // Check if count is specified.
56  if ($count)
57  {
58  $data['count'] = $count;
59  }
60 
61  // Check if entities is specified.
62  if (!is_null($entities))
63  {
64  $data['include_entities'] = $entities;
65  }
66 
67  // Check if skip_status is specified.
68  if (!is_null($skip_status))
69  {
70  $data['skip_status'] = $skip_status;
71  }
72 
73  // Send the request.
74  return $this->sendRequest($path, 'GET', $data);
75  }
76 
77  /**
78  * Method to get the most recent direct messages sent by the authenticating user.
79  *
80  * @param integer $since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
81  * @param integer $max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
82  * @param integer $count Specifies the number of direct messages to try and retrieve, up to a maximum of 200.
83  * @param integer $page Specifies the page of results to retrieve.
84  * @param boolean $entities When set to true, each tweet will include a node called "entities,". This node offers a variety of metadata
85  * about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
86  *
87  * @return array The decoded JSON response
88  *
89  * @since 12.3
90  */
91  public function getSentDirectMessages($since_id = 0, $max_id = 0, $count = 20, $page = 0, $entities = null)
92  {
93  // Check the rate limit for remaining hits
94  $this->checkRateLimit('direct_messages', 'sent');
95 
96  // Set the API path
97  $path = '/direct_messages/sent.json';
98 
99  // Check if since_id is specified.
100  if ($since_id)
101  {
102  $data['since_id'] = $since_id;
103  }
104 
105  // Check if max_id is specified.
106  if ($max_id)
107  {
108  $data['max_id'] = $max_id;
109  }
110 
111  // Check if count is specified.
112  if ($count)
113  {
114  $data['count'] = $count;
115  }
116 
117  // Check if page is specified.
118  if ($page)
119  {
120  $data['page'] = $page;
121  }
122 
123  // Check if entities is specified.
124  if (!is_null($entities))
125  {
126  $data['include_entities'] = $entities;
127  }
128 
129  // Send the request.
130  return $this->sendRequest($path, 'GET', $data);
131  }
132 
133  /**
134  * Method to send a new direct message to the specified user from the authenticating user.
135  *
136  * @param mixed $user Either an integer containing the user ID or a string containing the screen name.
137  * @param string $text The text of your direct message. Be sure to keep the message under 140 characters.
138  *
139  * @return array The decoded JSON response
140  *
141  * @since 12.3
142  * @throws RuntimeException
143  */
144  public function sendDirectMessages($user, $text)
145  {
146  // Set the API path
147  $path = '/direct_messages/new.json';
148 
149  // Determine which type of data was passed for $user
150  if (is_numeric($user))
151  {
152  $data['user_id'] = $user;
153  }
154  elseif (is_string($user))
155  {
156  $data['screen_name'] = $user;
157  }
158  else
159  {
160  // We don't have a valid entry
161  throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
162  }
163 
164  $data['text'] = $text;
165 
166  // Send the request.
167  return $this->sendRequest($path, 'POST', $data);
168  }
169 
170  /**
171  * Method to get a single direct message, specified by an id parameter.
172  *
173  * @param integer $id The ID of the direct message.
174  *
175  * @return array The decoded JSON response
176  *
177  * @since 12.3
178  */
179  public function getDirectMessagesById($id)
180  {
181  // Check the rate limit for remaining hits
182  $this->checkRateLimit('direct_messages', 'show');
183 
184  // Set the API path
185  $path = '/direct_messages/show.json';
186 
187  $data['id'] = $id;
188 
189  // Send the request.
190  return $this->sendRequest($path, 'GET', $data);
191  }
192 
193  /**
194  * Method to delete the direct message specified in the required ID parameter.
195  *
196  * @param integer $id The ID of the direct message.
197  * @param boolean $entities When set to true, each tweet will include a node called "entities,". This node offers a variety of metadata
198  * about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
199  *
200  * @return array The decoded JSON response
201  *
202  * @since 12.3
203  */
204  public function deleteDirectMessages($id, $entities = null)
205  {
206  // Set the API path
207  $path = '/direct_messages/destroy.json';
208 
209  $data['id'] = $id;
210 
211  // Check if entities is specified.
212  if (!is_null($entities))
213  {
214  $data['include_entities'] = $entities;
215  }
216 
217  // Send the request.
218  return $this->sendRequest($path, 'POST', $data);
219  }
220 }