Browse Source

Added Web Services Module

Stephen Ficklin 9 years ago
parent
commit
03416e85d4

+ 62 - 0
tripal_ws/includes/tripal_ws.rest.inc

@@ -0,0 +1,62 @@
+<?php
+
+function tripal_ws_rest() {
+
+  global $base_url;
+
+  // Set some initial variables.
+  $response = array();
+  $result = array();
+  $status = 'success';
+  $version = 'v0.1';
+  $message = '';
+  $api_url = "$base_url/ws/bio-data/$version";
+  $page_limit = 25;
+  $pager_id = 0;
+
+  // Lump everything ito a try block so that if there is a problem we can
+  // throw an error and have that returned in the response.
+  try {
+    // Get the list of published terms (these are the bundle IDs)
+    $bundles = db_select('tripal_bundle', 'tb')
+      ->fields('tb')
+      ->execute();
+    $terms = array();
+    while ($bundle = $bundles->fetchObject()) {
+      $cvterm_id = preg_replace('/^bio-data_/', '', $bundle->bundle);
+      if ($cvterm_id) {
+        $cvterm = chado_generate_var('cvterm', array('cvterm_id' => $cvterm_id));
+        $terms[$cvterm->name] = $cvterm;
+      }
+    }
+    ksort($terms);
+    $result['content_types'] = array();
+    foreach ($terms as $name => $cvterm) {
+      $result['content_types'][$name] = array(
+        'vocabulary' => $cvterm->cv_id->name,
+        'namespace' => $cvterm->dbxref_id->db_id->name,
+      );
+    }
+  }
+  catch (Exception $e) {
+    watchdog('tripal_ws', $e->getMessage(), array(), WATCHDOG_ERROR);
+    $message = $e->getMessage();
+    $status = 'error';
+    $result = array();
+  }
+
+  // The responses follow the same format as the AGAVE API with a
+  // status, message, version and all data in the "result" object.
+  $response['status']  = $status;
+  $response['message'] = $message;
+  $response['version'] = $version;
+  $response['source'] = array(
+    'site_name' => variable_get('site_name', "Unspecified"),
+    'site_url' => $base_url,
+    'site_slogan' => variable_get('site_slogan', "Unspecified"),
+    'site_email' =>  variable_get('site_mail', "Unspecified"),
+  );
+  $response['result']  = $result;
+  print drupal_json_output($response);
+}
+

+ 14 - 0
tripal_ws/tripal_ws.info

@@ -0,0 +1,14 @@
+name = Tripal Web Services
+description = Exposes Tripal Entites as RESTful web services.
+core = 7.x
+project = tripal
+package = Tripal
+version = 7.x-3.0
+configure = admin/tripal/chado/tripal_ws
+
+dependencies[] = tripal_core
+dependencies[] = tripal_views
+dependencies[] = tripal_db
+dependencies[] = tripal_cv
+dependencies[] = tripal_fields
+dependencies[] = tripal_entities

+ 0 - 0
tripal_ws/tripal_ws.install


+ 21 - 0
tripal_ws/tripal_ws.module

@@ -0,0 +1,21 @@
+<?php
+
+/**
+ * Implements hook_menu().
+ * Defines all menu items needed by Tripal Core
+ *
+ * @ingroup tripal_ws
+ */
+function tripal_ws_menu() {
+
+  // Web Services API callbacks.
+  $items['ws/bio-data/v0.1'] = array(
+    'title' => 'Tripal Entities Web Services API v0.1',
+    'page callback' => 'tripal_ws_rest',
+    'access arguments' => array('access content'),
+    'file' => '/includes/tripal_ws.rest.inc',
+    'type' => MENU_CALLBACK,
+  );
+
+  return $items;
+}