PageRenderTime 339ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/Server/SWXPHP/2.00/php/services/Identica.php

http://swx-format.googlecode.com/
PHP | 296 lines | 97 code | 52 blank | 147 comment | 3 complexity | 04be0e0aad37a6e852f9824fbf659fa5 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. *
  4. * SWX Identi.ca API by Folkert Hielema
  5. *
  6. * You can call this API using SWX, Amfphp, JSON and XML-RPC.
  7. *
  8. * @author Folkert Hielema
  9. * @copyright 2008 Folkert Hielema All Rights Reserved.
  10. * @link http://tjunar.com
  11. * @link http://swxformat.org
  12. * @link mailto://nederflash@gmail.com
  13. *
  14. **/
  15. // Require base service class
  16. require_once("../BaseService.php");
  17. /**
  18. * SWX Identi.ca API by Folkert Hielema. You can call this API using SWX, Amfphp, JSON and XML-RPC.
  19. **/
  20. class Identica extends BaseService
  21. {
  22. //////////////////////////////////////////////////////////////////////////////////////////
  23. //
  24. // Official Identi.ca API methods: These implement a spinoff from the official twitter API.
  25. // See http://groups.google.com/group/twitter-development-talk/web/api-documentation
  26. // for the full official documentation.
  27. //
  28. //////////////////////////////////////////////////////////////////////////////////////////
  29. //
  30. // Status methods.
  31. //
  32. /**
  33. * Returns the 20 most recent statuses from non-protected users who have set a custom user icon. Does not require authentication.
  34. * @return Array of statuses.
  35. * @author Folkert Hielema
  36. **/
  37. function publicTimeline()
  38. {
  39. $url = 'identi.ca/api/statuses/public_timeline.json';
  40. $response = $this->_jsonCall($url, NULL, 'GET');
  41. return $response;
  42. }
  43. /**
  44. * Returns the 20 most recent statuses posted in the last 24 hours from the authenticating user and that user's friends. It's also possible to request another user's friends_timeline via the id parameter.
  45. *
  46. * @param Your username.
  47. * @param Your password.
  48. * @param (optional) ID or screen name of the user for whom to return the friends_timeline.
  49. * @param (optional) The number of the page you want
  50. *
  51. * @return Array of statuses.
  52. * @author Folkert Hielema
  53. **/
  54. function friendsTimeline($user, $pass, $id = NULL, $count = 50, $page = 0)
  55. {
  56. $url = 'identi.ca/api/statuses/friends_timeline.json';
  57. $vars = array('id' => $id, 'count' => $count, 'page' => $page);
  58. $response = $this->_jsonCall($url, $vars, 'GET', $user, $pass);
  59. return $response;
  60. }
  61. /**
  62. * Returns the 20 most recent statuses posted in the last 24 hours from the authenticating user. It's also possible to request another user's timeline via the id parameter below.
  63. *
  64. *
  65. * @return 20 most recent statuses.
  66. * @author Folkert Hielema
  67. **/
  68. function userTimeline($user, $pass, $id = NULL, $count = 50)
  69. {
  70. $url = 'identi.ca/api/statuses/user_timeline.json';
  71. $vars = array('id' => $id, 'count' => $count);
  72. $response = $this->_jsonCall($url, $vars, 'GET', $user, $pass);
  73. return $response;
  74. }
  75. /**
  76. * Returns a single status, specified by the id parameter below. The status's author will be returned inline.
  77. *
  78. * @param The numerical ID of the status you're trying to retrieve.
  79. *
  80. * @return A single status.
  81. * @author Folkert Hielema
  82. **/
  83. function show($id)
  84. {
  85. $url = "identi.ca/api/statuses/show/$id.json";
  86. $response = $this->_jsonCall($url, NULL, 'GET');
  87. return $response;
  88. }
  89. /**
  90. * Posts a identi.ca update.
  91. *
  92. * @param (str) update message
  93. * @param (str) Your user name
  94. * @param (str) Your password
  95. * @param (optional, str) Source string. If enabled by Twitter, this will appear in the "from" section of the update.
  96. *
  97. * @return (array) Success/failure message.
  98. *
  99. * @author Folkert Hielema
  100. **/
  101. function update($update, $user, $pass, $source = NULL, $reply_id = NULL)
  102. {
  103. $url = 'identi.ca/api/statuses/update.json';
  104. $args = array('status' => $update, 'in_reply_to_status_id' => $reply_id);
  105. if ($source != NULL)
  106. {
  107. $args['source'] = $source;
  108. }
  109. $response = $this->_jsonCall($url, $args, 'POST', $user, $pass);
  110. return $response;
  111. }
  112. /**
  113. * Returns the 20 most recent replies (status updates prefixed with @username posted by users who are friends with the user being replied to) to the authenticating user. Replies are only available to the authenticating user; you can not request a list of replies to another user whether public or protected.
  114. *
  115. * @param (str) Your user name
  116. * @param (str) Your password
  117. * @param (optional, int) Page number
  118. *
  119. * @return 20 most recent replies
  120. * @author Folkert Hielema
  121. **/
  122. function replies($user, $pass, $page = NULL)
  123. {
  124. $url = 'identi.ca/api/statuses/replies.json';
  125. $args = array('page' => $page);
  126. $response = $this->_jsonCall($url, $args, 'POST', $user, $pass);
  127. return $response;
  128. }
  129. //
  130. // User methods.
  131. //
  132. /**
  133. * Gets friends for the passed user.
  134. *
  135. * @param (str) Username.
  136. * @param (str) Password.
  137. * @param (optional) The ID or screen name of a user
  138. *
  139. * @return (array) List of friends.
  140. * @author Folkert Hielema
  141. **/
  142. function friends($user, $pass, $id = NULL, $page = 1)
  143. {
  144. if($id !== NULL)
  145. $url = "identi.ca/api/statuses/friends/$id.json";
  146. else
  147. $url = "identi.ca/api/statuses/friends/$user.json";
  148. $vars = array('page' => $page);
  149. $response = $this->_jsonCall($url, $vars, 'GET', $user, $pass);
  150. return $response;
  151. }
  152. /**
  153. * Gets followers for authenticated user.
  154. *
  155. * @param (str) Your username.
  156. * @param (str) Your password.
  157. *
  158. * @return (array) List of followers.
  159. * @author Folkert Hielema
  160. **/
  161. function followers($user, $pass)
  162. {
  163. $url = 'identi.ca/api/statuses/followers.json';
  164. $response = $this->_jsonCall($url, NULL, 'GET', $user, $pass);
  165. return $response;
  166. }
  167. //
  168. // Friendship methods.
  169. //
  170. /**
  171. * Befriends the user specified in the ID parameter as the authenticating user. Returns the befriended user in the requested format when successful. Returns a string describing the failure condition when unsuccessful.
  172. *
  173. * @param (str) The ID or screen name of the user to befriend.
  174. * @param (str) Your username
  175. * @param (str) Your password
  176. *
  177. * @return Befriended user or error string.
  178. * @author Folkert Hielema
  179. **/
  180. function friendshipCreate($id, $user, $pass)
  181. {
  182. $url = "identi.ca/api/friendships/create/$id.json";
  183. $response = $this->_jsonCall($url, NULL, 'POST', $user, $pass);
  184. return $response;
  185. }
  186. /**
  187. * Discontinues friendship with the user specified in the ID parameter as the authenticating user. Returns the un-friended user in the requested format when successful. Returns a string describing the failure condition when unsuccessful.
  188. *
  189. * @param (str) The ID or screen name of the user with whom to discontinue friendship.
  190. * @param (str) Your username
  191. * @param (str) Your password
  192. *
  193. * @return Un-friended user or error string.
  194. * @author Folkert Hielema
  195. **/
  196. function friendshipDestroy($id, $user, $pass)
  197. {
  198. $url = "identi.ca/api/friendships/destroy/$id.json";
  199. $response = $this->_jsonCall($url, NULL, 'POST', $user, $pass);
  200. return $response;
  201. }
  202. /**
  203. * Test if a friendShip exists between two users
  204. *
  205. * @param (str) Your username
  206. * @param (str) Your password
  207. * @param (str) The ID or screen_name of the first user to test friendship for
  208. * @param (str) The ID or screen_name of the second user to test friendship for
  209. * @author Folkert Hielema
  210. **/
  211. function friendshipExists($user, $pass, $user_a, $user_b)
  212. {
  213. $url = "identi.ca/api/friendships/exists.json";
  214. $args = array('user_a'=>$user_a, 'user_b'=>$user_b);
  215. $response = $this->_jsonCall($url, $args, 'GET', $user, $pass);
  216. return $response;
  217. }
  218. //
  219. // Account methods.
  220. //
  221. /**
  222. * Returns an HTTP 200 OK response code and a format-specific response if authentication was successful. Use this method to test if supplied user credentials are valid with minimal overhead.
  223. *
  224. * @return authorized = "true" on success. null on failure.
  225. * @author Folkert Hielema for Identi.ca/Aral Balkan for Twitter API
  226. **/
  227. function verifyCredentials($user, $pass)
  228. {
  229. $url = 'identi.ca/api/account/verify_credentials.json';
  230. $response = $this->_jsonCall($url, NULL, 'GET', $user, $pass);
  231. return $response;
  232. }
  233. // Help methods
  234. /**
  235. * Returns the string "ok" in requested format with a 200 OK HTTP status code
  236. */
  237. function test()
  238. {
  239. $url = "identi.ca/api/help/test.json";
  240. $response = $this->_jsonCall($url, NULL, 'GET');
  241. return $response;
  242. }
  243. }
  244. ?>