You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1002 B

  1. # p3k-websub
  2. ## Usage
  3. ### Initialize the client
  4. ```php
  5. $http = new p3k\HTTP('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) p3k-websub/0.1.0 example');
  6. $client = new p3k\WebSub\Client($http);
  7. ```
  8. ### Discover the hub and self URLs for a topic URL
  9. ```php
  10. // Returns false unless both hub and self were found
  11. $endpoints = $client->discover($topic);
  12. // $endpoints['hub']
  13. // $endpoints['self']
  14. ```
  15. ### Send the subscription request
  16. ```php
  17. $secret = p3k\random_string(32);
  18. $id = p3k\random_string(32);
  19. $callback = 'http://localhost:8080/subscriber.php?id='.$id;
  20. $subscription = $client->subscribe($endpoints['hub'], $endpoints['self'], $callback, [
  21. 'lease_seconds' => 300,
  22. 'secret' => $secret
  23. ]);
  24. ```
  25. ### Verify the signature
  26. ```php
  27. $signature = $_SERVER['HTTP_X_HUB_SIGNATURE'];
  28. $document = file_get_contents('php://input');
  29. $valid = p3k\WebSub\Client::verify_signature($document, $signature, $secret);
  30. ```
  31. ## License
  32. Copyright 2017 by Aaron Parecki
  33. Available under the MIT license.