MIGRATION.rst 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. ############################
  2. Migrate from legacy wrappers
  3. ############################
  4. This guide specifically targets developers comming from the legacy wrappers
  5. previously distributed on https://api.ovh.com/g934.first_step_with_api. It
  6. highligts the main evolutions between these 2 major version as well as some
  7. tips to help with the migration. If you have any further questions, feel free
  8. to drop a mail on api@ml.ovh.net (api-subscribe@ml.ovh.net to subscribe).
  9. Installation
  10. ============
  11. Legacy wrappers were distributed as zip files for direct integration into
  12. final projects. This new version is fully integrated with Composer standard
  13. distribution channels.
  14. Recommended way to add ``php-ovh`` to a project: add ``ovh`` to a
  15. ``composer.json`` file at the root of the project.
  16. .. code::
  17. # file: composer.json
  18. "require": {
  19. "ovh/ovh": "dev-master"
  20. }
  21. To refresh the dependencies, just run:
  22. .. code:: bash
  23. composer install
  24. Usage
  25. =====
  26. Import and the client class
  27. ---------------------------
  28. The new PHP wrapper use composer to manage project dependencies. If you
  29. want to use the client class, usage of namespace is more confortable
  30. with PSR-4 autoloading system. You can find more informations about
  31. `autoloading <https://getcomposer.org/doc/01-basic-usage.md#autoloading>`_
  32. Legacy method:
  33. **************
  34. .. code:: php
  35. require('OvhApi/OvhApi.php');
  36. New method:
  37. ***********
  38. .. code:: php
  39. use \Ovh\Api;
  40. Instanciate a new client
  41. ------------------------
  42. Legacy method:
  43. **************
  44. .. code:: php
  45. $client = OvhApi(OVH_API_EU, 'app key', 'app secret', 'consumer key');
  46. New method:
  47. ***********
  48. .. code:: php
  49. $client = Client('app key', 'app secret', 'ovh-eu', 'consumer key');
  50. Similarly, ``OVH_API_CA`` has been replaced by ``'ovh-ca'``.
  51. Use the client
  52. --------------
  53. Legacy method:
  54. **************
  55. .. code:: php
  56. # API helpers
  57. $content = (object) array("param_1" => "value_1", "param_2" => "value_2");
  58. $data = $client->get('/my/method?filter_1=value_1&filter_2=value_2');
  59. $data = $client->post('/my/method', $content);
  60. $data = $client->put('/my/method', $content);
  61. $data = $client->delete('/my/method');
  62. New method:
  63. ***********
  64. .. code:: php
  65. # API helpers
  66. $content = (object) array("param_1" => "value_1", "param_2" => "value_2");
  67. $data = $client->get('/my/method?filter_1=value_1&filter_2=value_2');
  68. $data = $client->post('/my/method', $content);
  69. $data = $client->put('/my/method', $content);
  70. $data = $client->delete('/my/method');