From 75b6118b9f31a0aeace726393e7c777c0bbe44ef Mon Sep 17 00:00:00 2001 From: j Date: Sat, 22 Jun 2024 08:16:30 +0000 Subject: [PATCH] Update API --- API.md | 301 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 147 insertions(+), 154 deletions(-) diff --git a/API.md b/API.md index 0cbaaaa..47b6950 100644 --- a/API.md +++ b/API.md @@ -1,155 +1,148 @@ -## API -[Documents, pandora*, 0xdb2*)]TOC(heading=Design - -### Documentation -Each instance of Pan.do/ra comes with its build in API documentation. You find it by navigation to /api/ with a browser. -I.e. current API can be found at - -### Using the API -To use the API you can use Ox.App if you use Ox.js, or look at [pandora_client](https://wiki.0x2620.org/browser/pandora_client/pandora_client/*init*.py#L331) for how this can be used from python. Eventually we hope to describe this section in more detail. - - - -### Examples - - -#### PHP -``` -url = $url; - } - public function _request($action, $data) { - $content = array( - 'action' => $action, - 'data' => json_encode($data) - ); - $options = array( - 'http' => array( - 'header' => "Content-type: application/x-www-form-urlencoded\r\n", - 'method' => 'POST', - 'content' => http_build_query($content), - ), - ); - $context = stream_context_create($options); - $result = json_decode(file_get_contents($this->url, false, $context)); - return $result; - } -} -l -$api = new API('http://archive.arabdigitalexpression.org/api/'); - -$result = $api->_request('find', array( - "query"=>array( - "conditions"=>array(array("key"=>"*", "value"=>"paris", "operator"=>'=')) - ), - "keys"=>array("title", 'id'), - "range"=> array(0, 10), - "sort"=>array(array("key"=>"title", "operator"=>"+")) -)); - -var_dump($result); - -``` - -#### JavaScript -``` - - - - - - - - -``` - -Or using OxJS -``` - - - - - - - - - -``` - -#### Python - -Using python-ox (install with **easy_install ox**) - -``` -import ox - -api = ox.API('http://archive.arabdigitalexpression.org/api/') - -item = api.find({'query':{conditions:[{'key': '*', 'value':'test', 'operator':'='}], 'operator':'&'}, 'keys': ['location']}) - -``` - -Add all items in list 'j:Example' to groups a, b and c -``` -#!/usr/bin/python -import ox - -username=ADD_USER -password=ADD_PASSWORD -groups = ['a', 'b', 'c'] -list_id = 'j:Example' - -api = ox.API('http://kjc-sv030.kjc.uni-heidelberg.de/api/') -api.signin(username=username, password=password) -for i in api.find({'query': { - 'conditions': [{'key': 'list', 'value': list_id}]}, - 'keys': ['id', 'groups'], - 'range': [0, 10000] -})['data']['items']: - if i['groups'] != groups: - print id - api.edit({'id': i['id'], 'groups': groups}) +## API +[Documents, pandora*, 0xdb2*)]TOC(heading=Design + +### Documentation +Each instance of Pan.do/ra comes with its build in API documentation. You find it by navigation to /api/ with a browser. +I.e. current API can be found at + +### Using the API +To use the API you can use Ox.App if you use Ox.js, or look at [pandora_client](https://wiki.0x2620.org/browser/pandora_client/pandora_client/*init*.py#L331) for how this can be used from python. Eventually we hope to describe this section in more detail. + + + +### Examples + + +#### PHP +``` +url = $url; + } + public function _request($action, $data) { + $content = array( + 'action' => $action, + 'data' => json_encode($data) + ); + $options = array( + 'http' => array( + 'header' => "Content-type: application/x-www-form-urlencoded\r\n", + 'method' => 'POST', + 'content' => http_build_query($content), + ), + ); + $context = stream_context_create($options); + $result = json_decode(file_get_contents($this->url, false, $context)); + return $result; + } +} +l +$api = new API('http://archive.arabdigitalexpression.org/api/'); + +$result = $api->_request('find', array( + "query"=>array( + "conditions"=>array(array("key"=>"*", "value"=>"paris", "operator"=>'=')) + ), + "keys"=>array("title", 'id'), + "range"=> array(0, 10), + "sort"=>array(array("key"=>"title", "operator"=>"+")) +)); + +var_dump($result); + +``` + +#### JavaScript +``` + + + + + + + + +``` + +Or using OxJS +``` + + + + + + + + + +``` + +#### Python + +Using python-ox (install with **easy_install ox**) + +``` +import ox + +api = ox.API('http://archive.arabdigitalexpression.org/api/') + +item = api.find({'query':{conditions:[{'key': '*', 'value':'test', 'operator':'='}], 'operator':'&'}, 'keys': ['location']}) + +``` + +Add all items in list 'j:Example' to groups a, b and c +``` +#!/usr/bin/python +import ox + +username=ADD_USER +password=ADD_PASSWORD +groups = ['a', 'b', 'c'] +list_id = 'j:Example' + +api = ox.API('http://kjc-sv030.kjc.uni-heidelberg.de/api/') +api.signin(username=username, password=password) +for i in api.find({'query': { + 'conditions': [{'key': 'list', 'value': list_id}]}, + 'keys': ['id', 'groups'], + 'range': [0, 10000] +})['data']['items']: + if i['groups'] != groups: + print id + api.edit({'id': i['id'], 'groups': groups}) ``` \ No newline at end of file