TripalVocabService_v0_1.inc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. class TripalVocabService_v0_1 extends TripalWebService {
  3. /**
  4. * The human-readable label for this web service.
  5. */
  6. public static $label = 'Vocabulary';
  7. /**
  8. * A bit of text to describe what this service provides.
  9. */
  10. public static $description = 'Provides access to vocabulary terms that are in use by this site.';
  11. /**
  12. * A machine-readable type for this service. This name must be unique
  13. * among all Tripal web services and is used to form the URL to access
  14. * this service.
  15. */
  16. public static $type = 'vocab';
  17. /**
  18. * @see TripalWebService::handleRequest()
  19. */
  20. public function handleRequest() {
  21. $this->resource->addContextItem('vocab', $this->getServicePath());
  22. $this->resource->addContextItem('ApiDocumentation', 'hydra:ApiDocumentation');
  23. $this->resource->addContextItem('supportedClass', 'hydra:supportedClass');
  24. $this->resource->setType('ApiDocumentation');
  25. // Iterate through all of the web services and get their documentation
  26. $services = tripal_get_web_services();
  27. foreach ($services as $service_class) {
  28. tripal_load_include_web_service_class($service_class);
  29. $service = new $service_class($this->base_path);
  30. $supported_classes = $service->getSupportedClasses();
  31. foreach ($supported_classes as $supported) {
  32. $this->resource->addProperty('supportedClass', $supported);
  33. }
  34. }
  35. // Add in the generic supported classes.
  36. $entry_class = new TripalWebServiceResource($this->base_path);
  37. $entry_class->addContextItem('vocab', $this->getServicePath());
  38. $entry_class->addContextItem('label', 'rdfs:label');
  39. $entry_class->setID('vocab:EntryPoint');
  40. $entry_class->setType('hydra:Class');
  41. $entry_class->addProperty('label', 'Entry Point');
  42. $entry_class->addContextItem('description', 'rdfs:comment');
  43. $entry_class->addProperty('description', 'The main entry point or homepage of the API');
  44. $entry_class->addContextItem('subClassOf', array(
  45. "@id" => "rdfs:subClassOf",
  46. "@type" => "@id"
  47. ));
  48. $entry_class->addProperty('subClassOf', NULL);
  49. $entry_class->addContextItem('supportedOperation', 'hydra:supportedOperation');
  50. $entry_class->addContextItem('supportedProperty', 'hydra:supportedProperty');
  51. $operations = array();
  52. $get_op = new TripalWebServiceResource($this->getServicePath());
  53. $get_op->addContextItem('method', 'hydra:method');
  54. $get_op->addProperty('method', 'GET');
  55. $get_op->addContextItem('statusCodes', 'hydra:statusCodes');
  56. $get_op->addProperty('statusCodes', array());
  57. $get_op->addContextItem('label', 'rdfs:label');
  58. $get_op->addProperty('label', "The APIs main entry point.");
  59. $get_op->addContextItem('description', 'rdfs:comment');
  60. $get_op->addProperty('description', NULL);
  61. $get_op->addContextItem('expects', array(
  62. "@id" => "hydra:expects",
  63. "@type" => "@id"
  64. ));
  65. $get_op->addProperty('expects', NULL);
  66. $get_op->addContextItem('returns', array(
  67. "@id" => "hydra:returns",
  68. "@type" => "@id"
  69. ));
  70. $get_op->addProperty('returns', "vocab:EntryPoint");
  71. $get_op->setID('_:entry_point');
  72. $get_op->setType('hydra:Operation');
  73. $operations[] = $get_op;
  74. $entry_class->addProperty('supportedOperation', $operations);
  75. $this->resource->addProperty('supportedClass', $entry_class);
  76. }
  77. }