Tripal Plant PopGen Submit
tpps.api.inc File Reference

Go to the source code of this file.

Functions

 tpps_api_call ($type, $id=NULL, array $query=array())
 
 tpps_api_check_accession ($accession=NULL)
 
 tpps_api_compress_files ($accession=NULL)
 
 tpps_api_paths ()
 

Detailed Description

Main file for the TPPS API.

This file includes the other TPPS API files, defines required paths that TPPS uses for its api, provides a function which can be used to call the API internally, and a function to verify that a provided accession number has a valid TPPS submission associated with it.

Definition in file tpps.api.inc.

Function Documentation

◆ tpps_api_call()

tpps_api_call (   $type,
  $id = NULL,
array  $query = array() 
)

Performs a TPPS API call.

This function will perform an internal call to the TPPS API. It constructs a TPPS API url, performs a get request, and decodes the resulting JSON object.

Parameters
string$typeThe base API path to be called.
string$idAn id to be passed to the base API path. (Optional)
array$queryAny additional query arguments to be passed to the API.
Returns
mixed The decoded JSON object returned by the API.

Definition at line 120 of file tpps.api.inc.

120  {
121  global $base_url;
122  $path = $base_url . "/tpps/api/$type";
123  if (!empty($id)) {
124  $path .= "/$id";
125  }
126  if (!empty($query)) {
127  $args = array();
128  foreach ($query as $key => $val) {
129  $args[] = "$key=$val";
130  }
131  $path .= "?" . implode("&", $args);
132  }
133  $response = file_get_contents($path);
134  return json_decode($response);
135 }

◆ tpps_api_check_accession()

tpps_api_check_accession (   $accession = NULL)

Verifies an existing TPPS accession number.

If the provided accession has a valid existing TPPS submission, return TRUE. Otherwise, return FALSE.

Parameters
string$accessionThe accession to be verified.
Returns
bool TRUE if there exists a valid TPPS submission, otherwise FALSE.

Definition at line 149 of file tpps.api.inc.

149  {
150  if (empty($accession)) {
151  return FALSE;
152  }
153 
154  return tpps_load_submission($accession) ? TRUE : FALSE;
155 }
tpps_load_submission($accession, $state=TRUE)
Definition: submissions.inc:27

◆ tpps_api_compress_files()

tpps_api_compress_files (   $accession = NULL)

Definition at line 160 of file tpps.api.inc.

160  {
161  $state = tpps_load_submission($accession);
162  if (empty($state)) {
163  throw new Exception('Invalid state accession number');
164  }
165 
166  // TODO.
167 }
tpps_load_submission($accession, $state=TRUE)
Definition: submissions.inc:27

◆ tpps_api_paths()

tpps_api_paths ( )

Defines TPPS API paths.

This function is called from the tpps_menu() function and returns the menu items that TPPS will use for its API. All API paths start with tpps/api/ and return their data as JSON objects. The api paths include: check_accession/<accession number>=""> submission/<accession number>=""> submissions?<arguments> submission_info?<arguments> Details about each of the paths can be found in the inline documentation of this function, as well as the documentation for each of the functions the API calls.

Returns
array An array of menu items.

Definition at line 33 of file tpps.api.inc.

33  {
34  $items = array();
35 
36  // tpps/api/check_accession calls tpps_api_check_accession on a provided
37  // accession number. It will return TRUE for accessions with a valid
38  // TPPS submission and FALSE for all other accessions.
39  $items['tpps/api/check_accession/%'] = array(
40  'title' => 'TPPS Check Accession',
41  'page callback' => 'tpps_api_check_accession',
42  'page arguments' => array(3),
43  'access callback' => 'tpps_access',
44  'access arguments' => array('access content'),
45  'delivery callback' => 'drupal_json_output',
46  'type' => MENU_CALLBACK,
47  );
48 
49  // tpps/api/submission calls tpps_load_submission on a provided accession.
50  // If a valid TPPS submission exists for the accession, it will return the
51  // form_state of the submission.
52  $items['tpps/api/submission/%'] = array(
53  'title' => 'TPPS Raw Submissions',
54  'page callback' => 'tpps_load_submission',
55  'page arguments' => array(3),
56  'access callback' => 'tpps_access',
57  'access arguments' => array('access content'),
58  'delivery callback' => 'drupal_json_output',
59  'type' => MENU_CALLBACK,
60  );
61 
62  // tpps/api/submissions calls tpps_api_submission_query. If no query
63  // conditions are provided, it will return information about all of the
64  // existing valid TPPS submissions. Otherwise, it will filter the submissions
65  // based on the provided conditions. Please see the tpps_api_submission_query
66  // function for more details.
67  $items['tpps/api/submissions'] = array(
68  'title' => 'TPPS Submissions Query',
69  'page callback' => 'tpps_api_submission_query',
70  'page arguments' => array(),
71  'access callback' => 'tpps_access',
72  'access arguments' => array('access content'),
73  'delivery callback' => 'drupal_json_output',
74  'type' => MENU_CALLBACK,
75  );
76 
77  // tpps/api/submission_info calls tpps_api_submission_info. It will return
78  // data on multiple TPPS submissions based on accessions provided in the
79  // API query. The data returned can be specified using the data query
80  // argument. Please see the tpps_api_submission_info function for more
81  // details.
82  $items['tpps/api/submission_info'] = array(
83  'title' => 'TPPS Submission Data',
84  'page callback' => 'tpps_api_submission_info',
85  'page arguments' => array(),
86  'access callback' => 'tpps_access',
87  'access arguments' => array('access content'),
88  'delivery callback' => 'drupal_json_output',
89  'type' => MENU_CALLBACK,
90  );
91 
92  $items['tpps/api/files/%'] = array(
93  'title' => 'TPPS Submission Files Download',
94  'page callback' => 'tpps_api_compress_files',
95  'page arguments' => array(3),
96  'access callback' => 'tpps_access',
97  'access arguments' => array('access tpps details'),
98  'type' => MENU_NORMAL_ITEM,
99  );
100 
101  return $items;
102 }