1
0
Fork 0
mirror of synced 2024-06-28 19:20:25 +12:00

Updated SDKs

This commit is contained in:
eldadfux 2019-09-20 21:44:32 +03:00
parent f4e447dc35
commit 26f2586d7f
19 changed files with 129 additions and 143 deletions

View file

@ -18,6 +18,7 @@ use Auth\Auth;
use Database\Document;
use Database\Validator\Authorization;
use Event\Event;
use Utopia\Validator\WhiteList;
/**
* Configuration files
@ -435,9 +436,10 @@ $utopia->get('/v1/proxy')
$utopia->get('/v1/open-api-2.json')
->label('scope', 'public')
->label('docs', false)
->param('platform', 'client' , function () {return new WhiteList(['client', 'server']);}, 'Choose target platform.', true)
->param('extensions', 0 , function () {return new Range(0, 1);}, 'Show extra data.', true)
->action(
function($extensions) use ($response, $request, $utopia, $domain, $version, $services) {
function($platform, $extensions) use ($response, $request, $utopia, $domain, $version, $services) {
function fromCamelCase($input) {
preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches);
@ -452,6 +454,40 @@ $utopia->get('/v1/open-api-2.json')
return str_replace([' ', '_'], '-', strtolower(preg_replace('/([a-zA-Z])(?=[A-Z])/', '$1-', $input)));
}
$auth = [
'client' => [
],
'server' => [
'Key' => [
'type' => 'apiKey',
'name' => 'X-Appwrite-Key',
'description' => 'Your Appwrite project secret key. You can can create a new API key from your Appwrite console API keys dashboard.',
'in' => 'header',
],
],
'all' => [
'Project' => [
'type' => 'apiKey',
'name' => 'X-Appwrite-Project',
'description' => 'Your Appwrite project ID. You can find your project ID in your Appwrite console project settings.',
'in' => 'header',
],
'Locale' => [
'type' => 'apiKey',
'name' => 'X-Appwrite-Locale',
'description' => '',
'in' => 'header',
],
'Mode' => [
'type' => 'apiKey',
'name' => 'X-Appwrite-Mode',
'description' => '',
'in' => 'header',
],
]
];
/*$scopes = [
'client' => [
'name' => 'Client',
@ -505,58 +541,24 @@ $utopia->get('/v1/open-api-2.json')
'schemes' => ['https'],
'consumes' => ['application/json', 'multipart/form-data'],
'produces' => ['application/json'],
'securityDefinitions' => [
'Project' => [
'type' => 'apiKey',
'name' => 'X-Appwrite-Project',
'description' => 'Your Appwrite project ID. You can find your project ID in your Appwrite console project settings.',
'in' => 'header',
],
'Key' => [
'type' => 'apiKey',
'name' => 'X-Appwrite-Key',
'description' => 'Your Appwrite project secret key. You can can create a new API key from your Appwrite console API keys dashboard.',
'in' => 'header',
],
'Locale' => [
'type' => 'apiKey',
'name' => 'X-Appwrite-Locale',
'description' => '',
'in' => 'header',
],
'Mode' => [
'type' => 'apiKey',
'name' => 'X-Appwrite-Mode',
'description' => '',
'in' => 'header',
],
],
'securityDefinitions' => [],
'paths' => [],
'definitions' => array (
'Pet' =>
array (
'required' =>
array (
0 => 'id',
1 => 'name',
),
'properties' =>
array (
'id' =>
array (
'type' => 'integer',
'format' => 'int64',
),
'name' =>
array (
'type' => 'string',
),
'tag' =>
array (
'type' => 'string',
),
),
),
'definitions' => [
'Pet' => [
'required' => ['id', 'name'],
'properties' => [
'id' => [
'type' => 'integer',
'format' => 'int64',
],
'name' => [
'type' => 'string',
],
'tag' => [
'type' => 'string',
],
],
],
'Pets' =>
array (
'type' => 'array',
@ -585,13 +587,21 @@ $utopia->get('/v1/open-api-2.json')
),
),
),
),
],
'externalDocs' => [
'description' => 'Full API docs, specs and tutorials',
'url' => $request->getServer('REQUEST_SCHEME', 'https') . '://' . $domain . '/docs'
]
];
foreach ($auth['all'] as $key => $value) {
$output['securityDefinitions'][$key] = $value;
}
foreach ($auth[$platform] as $key => $value) {
$output['securityDefinitions'][$key] = $value;
}
foreach ($utopia->getRoutes() as $key => $method) {
foreach ($method as $route) { /* @var $route \Utopia\Route */
if(!$route->getLabel('docs', true)) {
@ -687,9 +697,8 @@ $utopia->get('/v1/open-api-2.json')
//$node['format'] = 'json';
break;
case 'Storage\Validators\File':
$consumes[] = ['multipart/form-data'];
$consumes[] = 'multipart/form-data';
$node['type'] = 'file';
$temp['consumes'] = ['multipart/form-data'];
break;
case 'Utopia\Validator\ArrayList':
$node['type'] = 'array';

View file

@ -31,14 +31,6 @@ class Client {
}
/// Your Appwrite project secret key. You can can create a new API key from your Appwrite console API keys dashboard.
Client setKey(value) {
this.addHeader('X-Appwrite-Key', value);
return this;
}
Client setLocale(value) {
this.addHeader('X-Appwrite-Locale', value);

View file

@ -5,7 +5,7 @@ sdk
setKey('')
;
let promise = sdk.projects.createWebhook('[PROJECT_ID]', '[NAME]', [], '[URL]', 1);
let promise = sdk.projects.createWebhook('[PROJECT_ID]', '[NAME]', [], '[URL]', 0);
promise.then(function (response) {
console.log(response);

View file

@ -5,7 +5,7 @@ sdk
setKey('')
;
let promise = sdk.projects.updateTask('[PROJECT_ID]', '[TASK_ID]', '[NAME]', 'play', '', 0, 'GET', 'https://example.com');
let promise = sdk.projects.updateTask('[PROJECT_ID]', '[TASK_ID]', '[NAME]', 'play', '', 1, 'GET', 'https://example.com');
promise.then(function (response) {
console.log(response);

View file

@ -4,7 +4,6 @@
let config = {
endpoint: 'https://appwrite.test/v1',
project: '',
key: '',
locale: '',
mode: '',
};
@ -38,25 +37,6 @@
return this;
};
/**
* Set Key
*
* Your Appwrite project secret key. You can can create a new API key from
\ * your Appwrite console API keys dashboard.
*
* @param value string
*
* @return this
*/
let setKey = function (value)
{
http.addGlobalHeader('X-Appwrite-Key', value);
config.key = value;
return this;
};
/**
* Set Locale
*
@ -3013,7 +2993,6 @@
return {
setEndpoint: setEndpoint,
setProject: setProject,
setKey: setKey,
setLocale: setLocale,
setMode: setMode,
account: account,

View file

@ -1,4 +1,4 @@
(function(window){window.Appwrite=function(){let config={endpoint:'https://appwrite.test/v1',project:'',key:'',locale:'',mode:'',};let setEndpoint=function(endpoint){config.endpoint=endpoint;return this};let setProject=function(value){http.addGlobalHeader('X-Appwrite-Project',value);config.project=value;return this};let setKey=function(value){http.addGlobalHeader('X-Appwrite-Key',value);config.key=value;return this};let setLocale=function(value){http.addGlobalHeader('X-Appwrite-Locale',value);config.locale=value;return this};let setMode=function(value){http.addGlobalHeader('X-Appwrite-Mode',value);config.mode=value;return this};let http=function(document){let globalParams=[],globalHeaders=[];let addParam=function(url,param,value){let a=document.createElement('a'),regex=/(?:\?|&amp;|&)+([^=]+)(?:=([^&]*))*/g;let match,str=[];a.href=url;param=encodeURIComponent(param);while(match=regex.exec(a.search))if(param!==match[1])str.push(match[1]+(match[2]?"="+match[2]:""));str.push(param+(value?"="+encodeURIComponent(value):""));a.search=str.join("&");return a.href};let buildQuery=function(params){let str=[];for(let p in params){if(Array.isArray(params[p])){for(let index=0;index<params[p].length;index++){let param=params[p][index];str.push(encodeURIComponent(p+'[]')+"="+encodeURIComponent(param))}}else{str.push(encodeURIComponent(p)+"="+encodeURIComponent(params[p]))}}
(function(window){window.Appwrite=function(){let config={endpoint:'https://appwrite.test/v1',project:'',locale:'',mode:'',};let setEndpoint=function(endpoint){config.endpoint=endpoint;return this};let setProject=function(value){http.addGlobalHeader('X-Appwrite-Project',value);config.project=value;return this};let setLocale=function(value){http.addGlobalHeader('X-Appwrite-Locale',value);config.locale=value;return this};let setMode=function(value){http.addGlobalHeader('X-Appwrite-Mode',value);config.mode=value;return this};let http=function(document){let globalParams=[],globalHeaders=[];let addParam=function(url,param,value){let a=document.createElement('a'),regex=/(?:\?|&amp;|&)+([^=]+)(?:=([^&]*))*/g;let match,str=[];a.href=url;param=encodeURIComponent(param);while(match=regex.exec(a.search))if(param!==match[1])str.push(match[1]+(match[2]?"="+match[2]:""));str.push(param+(value?"="+encodeURIComponent(value):""));a.search=str.join("&");return a.href};let buildQuery=function(params){let str=[];for(let p in params){if(Array.isArray(params[p])){for(let index=0;index<params[p].length;index++){let param=params[p][index];str.push(encodeURIComponent(p+'[]')+"="+encodeURIComponent(param))}}else{str.push(encodeURIComponent(p)+"="+encodeURIComponent(params[p]))}}
return str.join("&")};let addGlobalHeader=function(key,value){globalHeaders[key]={key:key.toLowerCase(),value:value.toLowerCase()}};let addGlobalParam=function(key,value){globalParams.push({key:key,value:value})};addGlobalHeader('x-sdk-version','appwrite:javascript:v1.0.20');addGlobalHeader('content-type','');let call=function(method,path,headers={},params={},progress=null){let i;path=config.endpoint+path;if(-1===['GET','POST','PUT','DELETE','TRACE','HEAD','OPTIONS','CONNECT','PATCH'].indexOf(method)){throw new Error('var method must contain a valid HTTP method name')}
if(typeof path!=='string'){throw new Error('var path must be of type string')}
if(typeof headers!=='object'){throw new Error('var headers must be of type object')}
@ -166,4 +166,4 @@ let path='/users/{userId}/sessions'.replace(new RegExp('{userId}','g'),userId);r
if(sessionId===undefined){throw new Error('Missing required parameter: "sessionId"')}
let path='/users/{userId}/sessions/:session'.replace(new RegExp('{userId}','g'),userId);return http.delete(path,{'content-type':'application/json'},{'sessionId':sessionId})},updateUserStatus:function(userId,status){if(userId===undefined){throw new Error('Missing required parameter: "userId"')}
if(status===undefined){throw new Error('Missing required parameter: "status"')}
let path='/users/{userId}/status'.replace(new RegExp('{userId}','g'),userId);return http.patch(path,{'content-type':'application/json'},{'status':status})}};return{setEndpoint:setEndpoint,setProject:setProject,setKey:setKey,setLocale:setLocale,setMode:setMode,account:account,auth:auth,avatars:avatars,database:database,locale:locale,projects:projects,storage:storage,teams:teams,users:users}}})(window)
let path='/users/{userId}/status'.replace(new RegExp('{userId}','g'),userId);return http.patch(path,{'content-type':'application/json'},{'status':status})}};return{setEndpoint:setEndpoint,setProject:setProject,setLocale:setLocale,setMode:setMode,account:account,auth:auth,avatars:avatars,database:database,locale:locale,projects:projects,storage:storage,teams:teams,users:users}}})(window)

View file

@ -10,7 +10,7 @@ client
setKey('')
;
let promise = projects.updateTask('[PROJECT_ID]', '[TASK_ID]', '[NAME]', 'play', '', 0, 'GET', 'https://example.com');
let promise = projects.updateTask('[PROJECT_ID]', '[TASK_ID]', '[NAME]', 'play', '', 1, 'GET', 'https://example.com');
promise.then(function (response) {
console.log(response);

View file

@ -10,7 +10,7 @@ client
setKey('')
;
let promise = projects.updateWebhook('[PROJECT_ID]', '[WEBHOOK_ID]', '[NAME]', [], '[URL]', 0);
let promise = projects.updateWebhook('[PROJECT_ID]', '[WEBHOOK_ID]', '[NAME]', [], '[URL]', 1);
promise.then(function (response) {
console.log(response);

View file

@ -27,21 +27,6 @@ class Client {
return this;
}
/**
* Set Key
*
* Your Appwrite project secret key. You can can create a new API key from your Appwrite console API keys dashboard.
*
* @param string value
*
* @return self
*/
setKey(value) {
this.addHeader('X-Appwrite-Key', value);
return this;
}
/**
* Set Locale
*
@ -68,6 +53,21 @@ class Client {
return this;
}
/**
* Set Key
*
* Your Appwrite project secret key. You can can create a new API key from your Appwrite console API keys dashboard.
*
* @param string value
*
* @return self
*/
setKey(value) {
this.addHeader('X-Appwrite-Key', value);
return this;
}
/***
* @param bool status
* @return this

View file

@ -12,4 +12,4 @@ $client
$projects = new Projects($client);
$result = $projects->createTask('[PROJECT_ID]', '[NAME]', 'play', '', 0, 'GET', 'https://example.com');
$result = $projects->createTask('[PROJECT_ID]', '[NAME]', 'play', '', 1, 'GET', 'https://example.com');

View file

@ -12,4 +12,4 @@ $client
$projects = new Projects($client);
$result = $projects->createWebhook('[PROJECT_ID]', '[NAME]', [], '[URL]', 1);
$result = $projects->createWebhook('[PROJECT_ID]', '[NAME]', [], '[URL]', 0);

View file

@ -12,4 +12,4 @@ $client
$projects = new Projects($client);
$result = $projects->updateTask('[PROJECT_ID]', '[TASK_ID]', '[NAME]', 'play', '', 0, 'GET', 'https://example.com');
$result = $projects->updateTask('[PROJECT_ID]', '[TASK_ID]', '[NAME]', 'play', '', 1, 'GET', 'https://example.com');

View file

@ -12,4 +12,4 @@ $client
$projects = new Projects($client);
$result = $projects->updateWebhook('[PROJECT_ID]', '[WEBHOOK_ID]', '[NAME]', [], '[URL]', 0);
$result = $projects->updateWebhook('[PROJECT_ID]', '[WEBHOOK_ID]', '[NAME]', [], '[URL]', 1);

View file

@ -63,22 +63,6 @@ class Client
return $this;
}
/**
* Set Key
*
* Your Appwrite project secret key. You can can create a new API key from your Appwrite console API keys dashboard.
*
* @param string $value
*
* @return Client
*/
public function setKey($value)
{
$this->addHeader('X-Appwrite-Key', $value);
return $this;
}
/**
* Set Locale
*
@ -107,6 +91,22 @@ class Client
return $this;
}
/**
* Set Key
*
* Your Appwrite project secret key. You can can create a new API key from your Appwrite console API keys dashboard.
*
* @param string $value
*
* @return Client
*/
public function setKey($value)
{
$this->addHeader('X-Appwrite-Key', $value);
return $this;
}
/***
* @param bool $status

View file

@ -61,7 +61,7 @@ class Storage extends Service
$params['folderId'] = $folderId;
return $this->client->call(Client::METHOD_POST, $path, [
'content-type' => 'Array',
'content-type' => 'multipart/form-data',
], $params);
}

View file

@ -28,12 +28,6 @@ class Client:
self._global_headers['x-appwrite-project'] = value.lower()
return self
def set_key(self, value):
"""Your Appwrite project secret key. You can can create a new API key from your Appwrite console API keys dashboard."""
self._global_headers['x-appwrite-key'] = value.lower()
return self
def set_locale(self, value):
self._global_headers['x-appwrite-locale'] = value.lower()
return self
@ -42,6 +36,12 @@ class Client:
self._global_headers['x-appwrite-mode'] = value.lower()
return self
def set_key(self, value):
"""Your Appwrite project secret key. You can can create a new API key from your Appwrite console API keys dashboard."""
self._global_headers['x-appwrite-key'] = value.lower()
return self
def call(self, method, path='', headers=None, params=None):
if headers is None:
headers = {}

View file

@ -29,7 +29,7 @@ class Storage(Service):
params['folderId'] = folder_id
return self.client.call('post', path, {
'content-type': 'Array',
'content-type': 'multipart/form-data',
}, params)
def get_file(self, file_id):

View file

@ -30,12 +30,6 @@ module Appwrite
return self
end
def set_key(value)
add_header('x-appwrite-key', value)
return self
end
def set_locale(value)
add_header('x-appwrite-locale', value)
@ -48,6 +42,12 @@ module Appwrite
return self
end
def set_key(value)
add_header('x-appwrite-key', value)
return self
end
def set_endpoint(endpoint)
@endpoint = endpoint

View file

@ -36,9 +36,6 @@ $cli
Console::success('Fetching API Spec');
$spec = getSSLPage('https://appwrite.io/v1/open-api-2.json?extensions=1');
$spec = getSSLPage('https://appwrite.test/v1/open-api-2.json?extensions=1');
$clients = [
'php' => [
'version' => 'v1.0.7',
@ -48,6 +45,7 @@ $cli
'gitRepoName' => 'sdk-for-php',
'gitUserName' => 'appwrite',
'warning' => '',
'platform' => 'server',
],
'js' => [
'version' => 'v1.0.20',
@ -57,6 +55,7 @@ $cli
'gitRepoName' => 'sdk-for-js',
'gitUserName' => 'appwrite',
'warning' => '',
'platform' => 'client',
],
'node' => [
'version' => 'v1.0.24',
@ -66,6 +65,7 @@ $cli
'gitRepoName' => 'sdk-for-node',
'gitUserName' => 'appwrite',
'warning' => '',
'platform' => 'server',
],
'python' => [
'version' => 'v1.0.0',
@ -75,6 +75,7 @@ $cli
'gitRepoName' => 'sdk-for-python',
'gitUserName' => 'appwrite',
'warning' => '**WORK IN PROGRESS - NOT READY FOR USAGE - Want to help us improve this client SDK? Send a pull request to Appwrite [SDK generator repository](https://github.com/appwrite/sdk-generator).**',
'platform' => 'server',
],
'ruby' => [
'version' => 'v1.0.0',
@ -84,6 +85,7 @@ $cli
'gitRepoName' => 'sdk-for-ruby',
'gitUserName' => 'appwrite',
'warning' => '**WORK IN PROGRESS - NOT READY FOR USAGE - Want to help us improve this client SDK? Send a pull request to Appwrite [SDK generator repository](https://github.com/appwrite/sdk-generator).**',
'platform' => 'server',
],
'dart' => [
'version' => '0.0.1',
@ -93,10 +95,14 @@ $cli
'gitRepoName' => 'sdk-for-dart',
'gitUserName' => 'appwrite',
'warning' => '**WORK IN PROGRESS - NOT READY FOR USAGE - Want to help us improve this client SDK? Send a pull request to Appwrite [SDK generator repository](https://github.com/appwrite/sdk-generator).**',
'platform' => 'client',
],
];
foreach ($clients as $name => $client) {
$spec = getSSLPage('https://appwrite.io/v1/open-api-2.json?extensions=1&platform=' . $client['platform']);
$spec = getSSLPage('https://appwrite.test/v1/open-api-2.json?extensions=1&platform=' . $client['platform']);
switch ($name) {
case 'php':
$language = new PHP();
@ -206,4 +212,4 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
}
});
$cli->run();
$cli->run();