PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/external/podio-php/README.markdown

https://github.com/fabianmu/shodio
Markdown | 95 lines | 63 code | 32 blank | 0 comment | 0 complexity | c8b32ecc6c320cb142e49c53e349a5d9 MD5 | raw file
  1. # About
  2. This is a PHP Client for interacting with the Podio API. Almost all parts of the Podio API is covered in this client. To get started include PodioAPI.php in your script:
  3. require_once('/path/to/podio-php/PodioAPI.php');
  4. # Dependencies
  5. The Podio PHP client depends on two PEAR Packages:
  6. * HTTP\_Request2: [http://pear.php.net/package/HTTP_Request2/](http://pear.php.net/package/HTTP_Request2/)
  7. * Log: [http://pear.php.net/package/Log/](http://pear.php.net/package/Log/)
  8. Both must be present in your PHP include path. If you have PEAR installed you can install these packages using the "pear install" command.
  9. # Constructing API client instance and authentication
  10. You will working with three classes:
  11. * **PodioOAuth:** Handles authentication with the API server and holds your OAuth tokens.
  12. * **PodioAPI:** Handles all communication with the API server. This is where you will spend most of your time.
  13. * **PodioBaseAPI:** A base class, you need to create an instance of this to hold your API credentials.
  14. Before you can make any API calls you need to obtain an OAuth access token. You do this by creating instances of `PodioBaseAPI` and `PodioOAuth` and call the `getAccessToken` method:
  15. require_once('/path/to/podio-php/PodioAPI.php');
  16. $oauth = PodioOAuth::instance();
  17. $baseAPI = PodioBaseAPI::instance($server, $client_id, $client_secret, $upload_end_point);
  18. // Obtain access token
  19. $oauth->getAccessToken('password', array('username' => $username, 'password' => $password));
  20. print $oauth->access_token; // Your access token
  21. // Woohoo! Now it's time to make API calls!
  22. # Making API calls
  23. To make API calls you use the `PodioAPI` class. This is contains references to all areas of the Podio API. See each area to see individual methods and their arguments.
  24. For example: If I want to post a new status message _'Posted from the PHP Client'_ to a space I would call the `create` method in the `status` area like so:
  25. $api = new PodioAPI();
  26. // $space_id is the id for the space I want to post the status message on
  27. $response = $api->status->create($space_id, 'Posted from the PHP Client');
  28. if ($response) {
  29. print 'The id for the status message is: '.$response['status_id'];
  30. }
  31. The Podio API always returns data in JSON and the PHP client automatically decodes this and places responses into associative arrays for easy traversal.
  32. # Handling file uploads
  33. If you wish to upload a file, for example to status messages, comments, items, widgets etc., you will use the `upload` method in the `api` area:
  34. $response = $api->api->upload($path_to_file, $filename_to_display);
  35. if ($response) {
  36. print 'File uploaded. The file id is: '.$response['result']['file_id'];
  37. }
  38. # Logging
  39. By default all logging happens in the PHP error log. You can overwrite this behaviour with the `setLogHandler` method on the `PodioBaseAPI` class. For example, you can log to a specific file:
  40. $baseAPI->setLogHandler('file', '/path/to/log/file/podio_log.log');
  41. You can see which log handlers are available in the [PEAR Log documentation](http://www.indelible.org/php/Log/guide.html).
  42. # API reference
  43. The PHP Client is documented using Doxygen. For your convenience a Doxygen configuration file has been included in the repository. To generate an API reference:
  44. * Install Doxygen if you haven't: [http://doxygen.org/](http://doxygen.org/)
  45. * Navigate to the podio-php folder and run `doxygen .doxygen`
  46. * The API reference will now be available in the `docs` folder
  47. # Full example: Posting status message with an image
  48. require_once('/path/to/podio-php/PodioAPI.php');
  49. $server = 'https://api.podio.com:443';
  50. $client_id = 'MY_OAUTH_CLIENT_ID';
  51. $client_secret = 'MY_OAUTH_CLIENT_SECRET';
  52. $upload_end_point = 'https://upload.podio.com/upload.php';
  53. $oauth = PodioOAuth::instance();
  54. $baseAPI = PodioBaseAPI::instance($server, $client_id, $client_secret, $upload_end_point);
  55. // Obtain access token
  56. $username = 'MY_USERNAME';
  57. $password = 'MY_PASSWORD';
  58. $oauth->getAccessToken('password', array('username' => $username, 'password' => $password));
  59. // Upload file
  60. $file = $api->api->upload('/path/to/myimage.png', 'myimage.png');
  61. // Post status message
  62. $space_id = MY_SPACE_ID;
  63. $api->status->create($space_id, 'This has an image attached', array((int)$file['result']['file_id']));