Overview

Packages

  • Service
    • Twitter

Classes

  • Horde_Service_Twitter
  • Horde_Service_Twitter_Account
  • Horde_Service_Twitter_Auth
  • Horde_Service_Twitter_Auth_Oauth
  • Horde_Service_Twitter_Exception
  • Horde_Service_Twitter_Request
  • Horde_Service_Twitter_Request_Oauth
  • Horde_Service_Twitter_Statuses
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Horde_Service_Twitter_Statuses class for updating, retrieving user statuses.
  4:  *
  5:  * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * @author Michael J. Rubinsky <mrubinsk@horde.org>
  8:  * @license  http://www.horde.org/licenses/bsd BSD
  9:  * @category Horde
 10:  * @package Service_Twitter
 11:  */
 12: class Horde_Service_Twitter_Statuses
 13: {
 14:     /**
 15:      * Endpoint for status api requests
 16:      *
 17:      * @var string
 18:      */
 19:     private $_endpoint = 'https://api.twitter.com/1/statuses/';
 20: 
 21:     /**
 22:      * Format to use json or xml
 23:      *
 24:      * @var string
 25:      */
 26:     private $_format = 'json';
 27: 
 28:     /**
 29:      * Constructor
 30:      *
 31:      * @param Horde_Service_Twitter $twitter
 32:      */
 33:     public function __construct($twitter)
 34:     {
 35:         $this->_twitter = $twitter;
 36:     }
 37: 
 38:     /**
 39:      * Obtain the requested status
 40:      *
 41:      * @return string  The method call results.
 42:      */
 43:     public function show($id)
 44:     {
 45:         $url = $this->_endpoint . 'show.' . $this->_format;
 46:         return $this->_twitter->request->post($url, array('id' => $id));
 47:     }
 48: 
 49:     /**
 50:      * Destroy the specified status update, obviously only if the current user
 51:      * is the author of the update.
 52:      *
 53:      * http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses%C2%A0destroy
 54:      *
 55:      * @param string $id  The status id
 56:      *
 57:      * @return string
 58:      */
 59:     public function destroy($id)
 60:     {
 61:         $url = $this->_endpoint . 'destroy.' . $this->_format;
 62:         return $this->_twitter->request->post($url, array('id' => $id));
 63:     }
 64: 
 65:     /**
 66:      * Update the current user's status.
 67:      *
 68:      * @param string $status  The new status text.
 69:      * @param array $params   Any additional parameters.
 70:      *   <pre>
 71:      *     in_reply_to_status_id  - the status id this tweet is in response to.
 72:      *   </pre>
 73:      *
 74:      * @return string
 75:      */
 76:     public function update($status, $params = array())
 77:     {
 78:         $url = $this->_endpoint . 'update.' . $this->_format;
 79:         $params['status'] = $status;
 80: 
 81:         return $this->_twitter->request->post($url, $params);
 82:     }
 83: 
 84:     /**
 85:      * Obtain the friendsTimeline.
 86:      *
 87:      * http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses-friends_timeline
 88:      *
 89:      * NOTE: According to the API docs, this method is deprecated and will be
 90:      * going away in a future version of the API. This is to be replaced by
 91:      * home_timeline.
 92:      *
 93:      * http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses-home_timeline
 94:      *
 95:      * @param array $params  Parameters for the friends_timeline call
 96:      *   <pre>
 97:      *     since_id         - Only tweets more recent the indicated tweet id
 98:      *     max_id           - Only tweets older then the indeicated tweet id
 99:      *     count            - Only return this many tweets (twitter limit = 200)
100:      *     page             - The page number to return (note there are
101:      *                        pagination limits)
102:      *     include_rts      - Include retweets
103:      *     include_entities - Include twitter entities (will be mandatory in
104:      *                        future twitter api release).
105:      *   </pre>
106:      *
107:      * @return string
108:      */
109:     public function friendsTimeline($params = array())
110:     {
111:         $url = $this->_endpoint . 'friends_timeline.' . $this->_format;
112:         return $this->_twitter->request->get($url, $params);
113:     }
114: 
115:     /**
116:      * Returns the 20 most recent statuses, including retweets, posted by the
117:      * authenticating user and that user's friends. This is the equivalent of
118:      * /timeline/home on the Web.
119:      *
120:      * http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses-home_timeline
121:      *
122:      * @param array $params  Parameters for the friends_timeline call
123:      *   <pre>
124:      *     since_id   - Only tweets more recent the indicated tweet id
125:      *     max_id     - Only tweets older then the indeicated tweet id
126:      *     count      - Only return this many tweets (twitter limit = 200)
127:      *     page       - The page number to return (note there are pagination limits)
128:      *   </pre>
129:      *
130:      * @return string
131:      */
132:     public function homeTimeline($params = array())
133:     {
134:         $url = $this->_endpoint . 'home_timeline.' . $this->_format;
135:         return $this->_twitter->request->get($url, $params);
136:     }
137: 
138:     /**
139:      * Returns the 20 most recent retweets posted by the authenticating user.
140:      *
141:      * @param array $params  Parameters for the friends_timeline call
142:      *   <pre>
143:      *     since_id   - Only tweets more recent the indicated tweet id
144:      *     max_id     - Only tweets older then the indeicated tweet id
145:      *     count      - Only return this many tweets (twitter limit = 200)
146:      *     page       - The page number to return (note there are pagination limits)
147:      *   </pre>
148:      *
149:      * @return string
150:      */
151:     public function retweetedByMe($params = array())
152:     {
153:         $url = $this->_endpoint . 'retweeted_by_me.' . $this->_format;
154:         return $this->_twitter->request->get($url, $params);
155:     }
156: 
157:     /**
158:      * Returns the 20 most recent retweets posted by the authenticating user's
159:      * friends.
160:      *
161:      * @param array $params  Parameters for the friends_timeline call
162:      *   <pre>
163:      *     since_id   - Only tweets more recent the indicated tweet id
164:      *     max_id     - Only tweets older then the indeicated tweet id
165:      *     count      - Only return this many tweets (twitter limit = 200)
166:      *     page       - The page number to return (note there are pagination limits)
167:      *   </pre>
168:      *
169:      * @return string
170:      */
171:     public function retweetedToMe($params = array())
172:     {
173:         $url = $this->_endpoint . 'retweetedToMe.' . $this->_format;
174:         return $this->_twitter->request->get($url, $params);
175:     }
176: 
177:     /**
178:      * Returns the 20 most recent tweets of the authenticated user that have
179:      * been retweeted by others.
180:      *
181:      * @param array $params  Parameters for the friends_timeline call
182:      *   <pre>
183:      *     since_id   - Only tweets more recent the indicated tweet id
184:      *     max_id     - Only tweets older then the indeicated tweet id
185:      *     count      - Only return this many tweets (twitter limit = 200)
186:      *     page       - The page number to return (note there are pagination limits)
187:      *   </pre>
188:      *
189:      * @return string
190:      */
191:     public function retweetsOfMe($params = array())
192:     {
193:         $url = $this->_endpoint . 'retweets_of_me.' . $this->_format;
194:         return $this->_twitter->request->get($url, $params);
195:     }
196: 
197:     /**
198:      * Retweets a tweet. Requires the id parameter of the tweet you are
199:      * retweeting. Request must be a POST or PUT.
200:      * Returns the original tweet with retweet details embedded.
201:      *
202:      * @params string id  The id for the tweet that is being retweeted.
203:      *
204:      * @return string
205:      */
206:     public function retweet($id)
207:     {
208:         $url = $this->_endpoint . 'retweet/' . $id .  '.' . $this->_format;
209: 
210:         return $this->_twitter->request->post($url, array());
211:     }
212: 
213:     /**
214:      * Obtain the last 20 tweets from the public timeline. This is cached every
215:      * 60 seconds on Twitter's servers so we should eventually ensure this is
216:      * only actually requested every 60 seconds or greater.
217:      *
218:      * @return string
219:      */
220:     public function publicTimeline()
221:     {
222:         $url = $this->_endpoint . 'public_timeline.' . $this->_format;
223:         return $this->_twitter->request->get($url);
224:     }
225: 
226:     /**
227:      * Obtain the friendsTimeline.
228:      *
229:      * http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses-user_timeline
230:      *
231:      * @param array $params  Parameters for the friends_timeline call
232:      *   <pre>
233:      *     id         - For this user id or screen name.
234:      *                  Current user if left out.
235:      *     user_id    - Specfies the ID of the user for whom to return the
236:      *                  user_timeline. Helpful for disambiguating when a valid
237:      *                  user ID is also a valid screen name.
238:      *     screen_id  - Specfies the screen name of the user for whom to return
239:      *                  the user_timeline. Helpful for disambiguating when a
240:      *                  valid screen name is also a user ID.
241:      *     since_id   - Only tweets more recent the indicated tweet id
242:      *     max_id     - Only tweets older then the indeicated tweet id
243:      *     count      - Only return this many tweets (twitter limit = 200)
244:      *     page       - The page number to return (note there are pagination limits)
245:      *   </pre>
246:      *
247:      * @return string
248:      */
249:     public function userTimeline($params = array())
250:     {
251:         $url = $this->_endpoint . 'user_timeline.' . $this->_format;
252:         return $this->_twitter->request->get($url, $params);
253:     }
254: 
255:     /**
256:      * Obtain most recent 'mentions' for the current user. (i.e. all messages
257:      * that contain @username in the text).
258:      *
259:      * http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses-mentions
260:      *
261:      * @param array $params  Parameters for the friends_timeline call
262:      *   <pre>
263:      *     since_id   - Only tweets more recent the indicated tweet id
264:      *     max_id     - Only tweets older then the indeicated tweet id
265:      *     count      - Only return this many tweets (twitter limit = 200)
266:      *     page       - The page number to return (note there are pagination limits)
267:      *   </pre>
268:      *
269:      * @return string
270:      */
271:     public function mentions($params = array())
272:     {
273:         $url = $this->_endpoint . 'mentions.' . $this->_format;
274:         return $this->_twitter->request->get($url, $params);
275:     }
276: 
277:     /**
278:      * Returns a user's friends, each with current status inline. They are
279:      * ordered by the order in which they were added as friends, 100 at a time.
280:      *
281:      * http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses%C2%A0friends
282:      *
283:      * @param array $params  Parameters for the friends_timeline call
284:      *   <pre>
285:      *     id         - For this user id or screen name.
286:      *                  Current user if left out.
287:      *     user_id    - Specfies the ID of the user for whom to return the
288:      *                  user_timeline. Helpful for disambiguating when a valid
289:      *                  user ID is also a valid screen name.
290:      *     screen_id  - Specfies the screen name of the user for whom to return
291:      *                  the user_timeline. Helpful for disambiguating when a
292:      *                  valid screen name is also a user ID.
293:      *     page       - The page number to return (note there are pagination limits)
294:      *   </pre>
295:      * @return unknown_type
296:      */
297:     public function friends($params = array())
298:     {
299:         $url = $this->_endpoint . 'friends.' . $this->_format;
300:         return $this->_twitter->request->get($url, $params);
301:     }
302: 
303:     /**
304:      * Returns a user's followers, each with current status inline. They are
305:      * ordered by the order in which they were added as friends, 100 at a time.
306:      *
307:      * http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses%C2%A0friends
308:      *
309:      * @param array $params  Parameters for the friends_timeline call
310:      *   <pre>
311:      *     id         - For this user id or screen name.
312:      *                  Current user if left out.
313:      *     user_id    - Specfies the ID of the user for whom to return the
314:      *                  user_timeline. Helpful for disambiguating when a valid
315:      *                  user ID is also a valid screen name.
316:      *     screen_id  - Specfies the screen name of the user for whom to return
317:      *                  the user_timeline. Helpful for disambiguating when a
318:      *                  valid screen name is also a user ID.
319:      *     page       - The page number to return (note there are pagination limits)
320:      *   </pre>
321:      * @return unknown_type
322:      */
323:     public function followers($params = array())
324:     {
325:         $url = $this->_endpoint . 'followers.' . $this->_format;
326:         return $this->_twitter->request->get($url, $params);
327:     }
328: 
329: }
330: 
API documentation generated by ApiGen