Updated SDKs

This commit is contained in:
Eldad Fux 2020-04-14 17:13:19 +03:00
parent 22022fff5b
commit 573e153057
18 changed files with 134 additions and 127 deletions

View file

@ -5,10 +5,6 @@ sdk
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
;
let promise = sdk.storage.getFileDownload('[FILE_ID]');
let result = sdk.storage.getFileDownload('[FILE_ID]');
promise.then(function (response) {
console.log(response); // Success
}, function (error) {
console.log(error); // Failure
});
console.log(result); // Resource URL

View file

@ -5,10 +5,6 @@ sdk
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
;
let promise = sdk.storage.getFilePreview('[FILE_ID]');
let result = sdk.storage.getFilePreview('[FILE_ID]');
promise.then(function (response) {
console.log(response); // Success
}, function (error) {
console.log(error); // Failure
});
console.log(result); // Resource URL

View file

@ -5,10 +5,6 @@ sdk
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
;
let promise = sdk.storage.getFileView('[FILE_ID]');
let result = sdk.storage.getFileView('[FILE_ID]');
promise.then(function (response) {
console.log(response); // Success
}, function (error) {
console.log(error); // Failure
});
console.log(result); // Resource URL

View file

@ -765,10 +765,13 @@
payload['failure'] = failure;
}
return http
.get(path, {
'content-type': 'application/json',
}, payload);
payload['project'] = config.project;
payload['key'] = config.key;
let query = Object.keys(payload).map(key => key + '=' + encodeURIComponent(payload[key])).join('&');
window.location = config.endpoint + path + ((query) ? '?' + query : '');
},
/**
@ -3182,7 +3185,7 @@
*
* @param {string} fileId
* @throws {Error}
* @return {Promise}
* @return {string}
*/
getFileDownload: function(fileId) {
if(fileId === undefined) {
@ -3193,10 +3196,13 @@
let payload = {};
return http
.get(path, {
'content-type': 'application/json',
}, payload);
payload['project'] = config.project;
payload['key'] = config.key;
let query = Object.keys(payload).map(key => key + '=' + encodeURIComponent(payload[key])).join('&');
return config.endpoint + path + ((query) ? '?' + query : '');
},
/**
@ -3214,7 +3220,7 @@
* @param {string} background
* @param {string} output
* @throws {Error}
* @return {Promise}
* @return {string}
*/
getFilePreview: function(fileId, width = 0, height = 0, quality = 100, background = '', output = '') {
if(fileId === undefined) {
@ -3245,10 +3251,13 @@
payload['output'] = output;
}
return http
.get(path, {
'content-type': 'application/json',
}, payload);
payload['project'] = config.project;
payload['key'] = config.key;
let query = Object.keys(payload).map(key => key + '=' + encodeURIComponent(payload[key])).join('&');
return config.endpoint + path + ((query) ? '?' + query : '');
},
/**
@ -3260,7 +3269,7 @@
* @param {string} fileId
* @param {string} as
* @throws {Error}
* @return {Promise}
* @return {string}
*/
getFileView: function(fileId, as = '') {
if(fileId === undefined) {
@ -3275,10 +3284,13 @@
payload['as'] = as;
}
return http
.get(path, {
'content-type': 'application/json',
}, payload);
payload['project'] = config.project;
payload['key'] = config.key;
let query = Object.keys(payload).map(key => key + '=' + encodeURIComponent(payload[key])).join('&');
return config.endpoint + path + ((query) ? '?' + query : '');
}
};

View file

@ -48,7 +48,7 @@ if(password){payload.password=password}
return http.post(path,{'content-type':'application/json',},payload)},deleteSessions:function(){let path='/account/sessions';let payload={};return http.delete(path,{'content-type':'application/json',},payload)},createOAuth2Session:function(provider,success='https://localhost:2444/auth/oauth2/success',failure='https://localhost:2444/auth/oauth2/failure'){if(provider===undefined){throw new Error('Missing required parameter: "provider"')}
let path='/account/sessions/oauth2/{provider}'.replace(new RegExp('{provider}','g'),provider);let payload={};if(success){payload.success=success}
if(failure){payload.failure=failure}
return http.get(path,{'content-type':'application/json',},payload)},deleteSession:function(sessionId){if(sessionId===undefined){throw new Error('Missing required parameter: "sessionId"')}
payload.project=config.project;payload.key=config.key;let query=Object.keys(payload).map(key=>key+'='+encodeURIComponent(payload[key])).join('&');window.location=config.endpoint+path+((query)?'?'+query:'')},deleteSession:function(sessionId){if(sessionId===undefined){throw new Error('Missing required parameter: "sessionId"')}
let path='/account/sessions/{sessionId}'.replace(new RegExp('{sessionId}','g'),sessionId);let payload={};return http.delete(path,{'content-type':'application/json',},payload)},createVerification:function(url){if(url===undefined){throw new Error('Missing required parameter: "url"')}
let path='/account/verification';let payload={};if(url){payload.url=url}
return http.post(path,{'content-type':'application/json',},payload)},updateVerification:function(userId,secret){if(userId===undefined){throw new Error('Missing required parameter: "userId"')}
@ -297,15 +297,15 @@ let path='/storage/files/{fileId}'.replace(new RegExp('{fileId}','g'),fileId);le
if(write){payload.write=write}
return http.put(path,{'content-type':'application/json',},payload)},deleteFile:function(fileId){if(fileId===undefined){throw new Error('Missing required parameter: "fileId"')}
let path='/storage/files/{fileId}'.replace(new RegExp('{fileId}','g'),fileId);let payload={};return http.delete(path,{'content-type':'application/json',},payload)},getFileDownload:function(fileId){if(fileId===undefined){throw new Error('Missing required parameter: "fileId"')}
let path='/storage/files/{fileId}/download'.replace(new RegExp('{fileId}','g'),fileId);let payload={};return http.get(path,{'content-type':'application/json',},payload)},getFilePreview:function(fileId,width=0,height=0,quality=100,background='',output=''){if(fileId===undefined){throw new Error('Missing required parameter: "fileId"')}
let path='/storage/files/{fileId}/download'.replace(new RegExp('{fileId}','g'),fileId);let payload={};payload.project=config.project;payload.key=config.key;let query=Object.keys(payload).map(key=>key+'='+encodeURIComponent(payload[key])).join('&');return config.endpoint+path+((query)?'?'+query:'')},getFilePreview:function(fileId,width=0,height=0,quality=100,background='',output=''){if(fileId===undefined){throw new Error('Missing required parameter: "fileId"')}
let path='/storage/files/{fileId}/preview'.replace(new RegExp('{fileId}','g'),fileId);let payload={};if(width){payload.width=width}
if(height){payload.height=height}
if(quality){payload.quality=quality}
if(background){payload.background=background}
if(output){payload.output=output}
return http.get(path,{'content-type':'application/json',},payload)},getFileView:function(fileId,as=''){if(fileId===undefined){throw new Error('Missing required parameter: "fileId"')}
payload.project=config.project;payload.key=config.key;let query=Object.keys(payload).map(key=>key+'='+encodeURIComponent(payload[key])).join('&');return config.endpoint+path+((query)?'?'+query:'')},getFileView:function(fileId,as=''){if(fileId===undefined){throw new Error('Missing required parameter: "fileId"')}
let path='/storage/files/{fileId}/view'.replace(new RegExp('{fileId}','g'),fileId);let payload={};if(as){payload.as=as}
return http.get(path,{'content-type':'application/json',},payload)}};let teams={list:function(search='',limit=25,offset=0,orderType='ASC'){let path='/teams';let payload={};if(search){payload.search=search}
payload.project=config.project;payload.key=config.key;let query=Object.keys(payload).map(key=>key+'='+encodeURIComponent(payload[key])).join('&');return config.endpoint+path+((query)?'?'+query:'')}};let teams={list:function(search='',limit=25,offset=0,orderType='ASC'){let path='/teams';let payload={};if(search){payload.search=search}
if(limit){payload.limit=limit}
if(offset){payload.offset=offset}
if(orderType){payload.orderType=orderType}

View file

@ -1,3 +1,4 @@
import 'dart:io';
import 'package:appwrite/appwrite.dart';
// Init SDK

View file

@ -8,13 +8,8 @@ client
.setProject('5df5acd0d48c2') // Your project ID
;
Future result = storage.getFileDownload(
String result = storage.getFileDownload(
fileId: '[FILE_ID]',
);
result
.then((response) {
print(response);
}).catchError((error) {
print(error);
});
print(result); // Resource URL string

View file

@ -8,13 +8,8 @@ client
.setProject('5df5acd0d48c2') // Your project ID
;
Future result = storage.getFilePreview(
String result = storage.getFilePreview(
fileId: '[FILE_ID]',
);
result
.then((response) {
print(response);
}).catchError((error) {
print(error);
});
print(result); // Resource URL string

View file

@ -8,13 +8,8 @@ client
.setProject('5df5acd0d48c2') // Your project ID
;
Future result = storage.getFileView(
String result = storage.getFileView(
fileId: '[FILE_ID]',
);
result
.then((response) {
print(response);
}).catchError((error) {
print(error);
});
print(result); // Resource URL string

View file

@ -1,7 +1,9 @@
import 'dart:io';
import 'package:dio/dio.dart';
import 'package:meta/meta.dart';
import 'package:flutter_web_auth/flutter_web_auth.dart';
import "../client.dart";
import '../enums.dart';
@ -303,19 +305,31 @@ class Account extends Service {
/// first. Use the success and failure arguments to provide a redirect URL's
/// back to your app when login is completed.
///
Future<Response> createOAuth2Session({@required String provider, String success = 'https://localhost:2444/auth/oauth2/success', String failure = 'https://localhost:2444/auth/oauth2/failure'}) {
Future createOAuth2Session({@required String provider, String success = 'https://localhost:2444/auth/oauth2/success', String failure = 'https://localhost:2444/auth/oauth2/failure'}) {
final String path = '/account/sessions/oauth2/{provider}'.replaceAll(RegExp('{provider}'), provider);
final Map<String, dynamic> params = {
'success': success,
'failure': failure,
'project': client.config['project'],
};
final Map<String, String> headers = {
'content-type': 'application/json',
};
Uri endpoint = Uri.parse(client.endPoint);
Uri url = new Uri(scheme: endpoint.scheme,
host: endpoint.host,
port: endpoint.port,
path: endpoint.path + path,
queryParameters:params,
);
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
return FlutterWebAuth.authenticate(
url: url.toString(),
callbackUrlScheme: "appwrite-callback"
).then((value) {
Uri url = Uri.parse(value);
List<Cookie> cookies = [new Cookie(url.queryParameters['key'], url.queryParameters['secret'])];
client.cookieJar.saveFromResponse(Uri.parse(client.endPoint), cookies);
});
}
/// Delete Account Session

View file

@ -117,17 +117,22 @@ class Storage extends Service {
/// 'Content-Disposition: attachment' header that tells the browser to start
/// downloading the file to user downloads directory.
///
Future<Response> getFileDownload({@required String fileId}) {
String getFileDownload({@required String fileId}) {
final String path = '/storage/files/{fileId}/download'.replaceAll(RegExp('{fileId}'), fileId);
final Map<String, dynamic> params = {
'project': client.config['project'],
};
final Map<String, String> headers = {
'content-type': 'application/json',
};
Uri endpoint = Uri.parse(client.endPoint);
Uri url = new Uri(scheme: endpoint.scheme,
host: endpoint.host,
port: endpoint.port,
path: endpoint.path + path,
queryParameters:params,
);
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
return url.toString();
}
/// Get File Preview
@ -137,7 +142,7 @@ class Storage extends Service {
/// and spreadsheets, will return the file icon image. You can also pass query
/// string arguments for cutting and resizing your preview image.
///
Future<Response> getFilePreview({@required String fileId, int width = 0, int height = 0, int quality = 100, String background = '', String output = ''}) {
String getFilePreview({@required String fileId, int width = 0, int height = 0, int quality = 100, String background = '', String output = ''}) {
final String path = '/storage/files/{fileId}/preview'.replaceAll(RegExp('{fileId}'), fileId);
final Map<String, dynamic> params = {
@ -146,13 +151,18 @@ class Storage extends Service {
'quality': quality,
'background': background,
'output': output,
'project': client.config['project'],
};
final Map<String, String> headers = {
'content-type': 'application/json',
};
Uri endpoint = Uri.parse(client.endPoint);
Uri url = new Uri(scheme: endpoint.scheme,
host: endpoint.host,
port: endpoint.port,
path: endpoint.path + path,
queryParameters:params,
);
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
return url.toString();
}
/// Get File for View
@ -160,17 +170,22 @@ class Storage extends Service {
/// Get file content by its unique ID. This endpoint is similar to the download
/// method but returns with no 'Content-Disposition: attachment' header.
///
Future<Response> getFileView({@required String fileId, String as = ''}) {
String getFileView({@required String fileId, String as = ''}) {
final String path = '/storage/files/{fileId}/view'.replaceAll(RegExp('{fileId}'), fileId);
final Map<String, dynamic> params = {
'as': as,
'project': client.config['project'],
};
final Map<String, String> headers = {
'content-type': 'application/json',
};
Uri endpoint = Uri.parse(client.endPoint);
Uri url = new Uri(scheme: endpoint.scheme,
host: endpoint.host,
port: endpoint.port,
path: endpoint.path + path,
queryParameters:params,
);
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
return url.toString();
}
}

View file

@ -1,6 +1,6 @@
name: appwrite
version: 0.1.0
description: Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API
description: Appwrite is an open-source self-hosted backend as a service that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API
homepage: https://appwrite.io
repository: https://github.com/appwrite/sdk-for-dart
issue_tracker: https://github.com/appwrite/sdk-generator/issues
@ -14,7 +14,7 @@ dependencies:
dio: ^3.0.0
cookie_jar: ^1.0.0
dio_cookie_manager: ^1.0.0
flutter_web_auth: ^0.1.3
flutter_web_auth: ^0.2.0
flutter:
sdk: flutter

View file

@ -4,10 +4,6 @@ sdk
.setProject('5df5acd0d48c2') // Your project ID
;
let promise = sdk.storage.getFileDownload('[FILE_ID]');
let result = sdk.storage.getFileDownload('[FILE_ID]');
promise.then(function (response) {
console.log(response); // Success
}, function (error) {
console.log(error); // Failure
});
console.log(result); // Resource URL

View file

@ -4,10 +4,6 @@ sdk
.setProject('5df5acd0d48c2') // Your project ID
;
let promise = sdk.storage.getFilePreview('[FILE_ID]');
let result = sdk.storage.getFilePreview('[FILE_ID]');
promise.then(function (response) {
console.log(response); // Success
}, function (error) {
console.log(error); // Failure
});
console.log(result); // Resource URL

View file

@ -4,10 +4,6 @@ sdk
.setProject('5df5acd0d48c2') // Your project ID
;
let promise = sdk.storage.getFileView('[FILE_ID]');
let result = sdk.storage.getFileView('[FILE_ID]');
promise.then(function (response) {
console.log(response); // Success
}, function (error) {
console.log(error); // Failure
});
console.log(result); // Resource URL

View file

@ -765,10 +765,11 @@
payload['failure'] = failure;
}
return http
.get(path, {
'content-type': 'application/json',
}, payload);
payload['project'] = config.project;
let query = Object.keys(payload).map(key => key + '=' + encodeURIComponent(payload[key])).join('&');
window.location = config.endpoint + path + ((query) ? '?' + query : '');
},
/**
@ -1698,7 +1699,7 @@
*
* @param {string} fileId
* @throws {Error}
* @return {Promise}
* @return {string}
*/
getFileDownload: function(fileId) {
if(fileId === undefined) {
@ -1709,10 +1710,11 @@
let payload = {};
return http
.get(path, {
'content-type': 'application/json',
}, payload);
payload['project'] = config.project;
let query = Object.keys(payload).map(key => key + '=' + encodeURIComponent(payload[key])).join('&');
return config.endpoint + path + ((query) ? '?' + query : '');
},
/**
@ -1730,7 +1732,7 @@
* @param {string} background
* @param {string} output
* @throws {Error}
* @return {Promise}
* @return {string}
*/
getFilePreview: function(fileId, width = 0, height = 0, quality = 100, background = '', output = '') {
if(fileId === undefined) {
@ -1761,10 +1763,11 @@
payload['output'] = output;
}
return http
.get(path, {
'content-type': 'application/json',
}, payload);
payload['project'] = config.project;
let query = Object.keys(payload).map(key => key + '=' + encodeURIComponent(payload[key])).join('&');
return config.endpoint + path + ((query) ? '?' + query : '');
},
/**
@ -1776,7 +1779,7 @@
* @param {string} fileId
* @param {string} as
* @throws {Error}
* @return {Promise}
* @return {string}
*/
getFileView: function(fileId, as = '') {
if(fileId === undefined) {
@ -1791,10 +1794,11 @@
payload['as'] = as;
}
return http
.get(path, {
'content-type': 'application/json',
}, payload);
payload['project'] = config.project;
let query = Object.keys(payload).map(key => key + '=' + encodeURIComponent(payload[key])).join('&');
return config.endpoint + path + ((query) ? '?' + query : '');
}
};

View file

@ -48,7 +48,7 @@ if(password){payload.password=password}
return http.post(path,{'content-type':'application/json',},payload)},deleteSessions:function(){let path='/account/sessions';let payload={};return http.delete(path,{'content-type':'application/json',},payload)},createOAuth2Session:function(provider,success='https://localhost:2444/auth/oauth2/success',failure='https://localhost:2444/auth/oauth2/failure'){if(provider===undefined){throw new Error('Missing required parameter: "provider"')}
let path='/account/sessions/oauth2/{provider}'.replace(new RegExp('{provider}','g'),provider);let payload={};if(success){payload.success=success}
if(failure){payload.failure=failure}
return http.get(path,{'content-type':'application/json',},payload)},deleteSession:function(sessionId){if(sessionId===undefined){throw new Error('Missing required parameter: "sessionId"')}
payload.project=config.project;let query=Object.keys(payload).map(key=>key+'='+encodeURIComponent(payload[key])).join('&');window.location=config.endpoint+path+((query)?'?'+query:'')},deleteSession:function(sessionId){if(sessionId===undefined){throw new Error('Missing required parameter: "sessionId"')}
let path='/account/sessions/{sessionId}'.replace(new RegExp('{sessionId}','g'),sessionId);let payload={};return http.delete(path,{'content-type':'application/json',},payload)},createVerification:function(url){if(url===undefined){throw new Error('Missing required parameter: "url"')}
let path='/account/verification';let payload={};if(url){payload.url=url}
return http.post(path,{'content-type':'application/json',},payload)},updateVerification:function(userId,secret){if(userId===undefined){throw new Error('Missing required parameter: "userId"')}
@ -128,15 +128,15 @@ let path='/storage/files/{fileId}'.replace(new RegExp('{fileId}','g'),fileId);le
if(write){payload.write=write}
return http.put(path,{'content-type':'application/json',},payload)},deleteFile:function(fileId){if(fileId===undefined){throw new Error('Missing required parameter: "fileId"')}
let path='/storage/files/{fileId}'.replace(new RegExp('{fileId}','g'),fileId);let payload={};return http.delete(path,{'content-type':'application/json',},payload)},getFileDownload:function(fileId){if(fileId===undefined){throw new Error('Missing required parameter: "fileId"')}
let path='/storage/files/{fileId}/download'.replace(new RegExp('{fileId}','g'),fileId);let payload={};return http.get(path,{'content-type':'application/json',},payload)},getFilePreview:function(fileId,width=0,height=0,quality=100,background='',output=''){if(fileId===undefined){throw new Error('Missing required parameter: "fileId"')}
let path='/storage/files/{fileId}/download'.replace(new RegExp('{fileId}','g'),fileId);let payload={};payload.project=config.project;let query=Object.keys(payload).map(key=>key+'='+encodeURIComponent(payload[key])).join('&');return config.endpoint+path+((query)?'?'+query:'')},getFilePreview:function(fileId,width=0,height=0,quality=100,background='',output=''){if(fileId===undefined){throw new Error('Missing required parameter: "fileId"')}
let path='/storage/files/{fileId}/preview'.replace(new RegExp('{fileId}','g'),fileId);let payload={};if(width){payload.width=width}
if(height){payload.height=height}
if(quality){payload.quality=quality}
if(background){payload.background=background}
if(output){payload.output=output}
return http.get(path,{'content-type':'application/json',},payload)},getFileView:function(fileId,as=''){if(fileId===undefined){throw new Error('Missing required parameter: "fileId"')}
payload.project=config.project;let query=Object.keys(payload).map(key=>key+'='+encodeURIComponent(payload[key])).join('&');return config.endpoint+path+((query)?'?'+query:'')},getFileView:function(fileId,as=''){if(fileId===undefined){throw new Error('Missing required parameter: "fileId"')}
let path='/storage/files/{fileId}/view'.replace(new RegExp('{fileId}','g'),fileId);let payload={};if(as){payload.as=as}
return http.get(path,{'content-type':'application/json',},payload)}};let teams={list:function(search='',limit=25,offset=0,orderType='ASC'){let path='/teams';let payload={};if(search){payload.search=search}
payload.project=config.project;let query=Object.keys(payload).map(key=>key+'='+encodeURIComponent(payload[key])).join('&');return config.endpoint+path+((query)?'?'+query:'')}};let teams={list:function(search='',limit=25,offset=0,orderType='ASC'){let path='/teams';let payload={};if(search){payload.search=search}
if(limit){payload.limit=limit}
if(offset){payload.offset=offset}
if(orderType){payload.orderType=orderType}

4
composer.lock generated
View file

@ -1622,7 +1622,7 @@
"source": {
"type": "git",
"url": "https://github.com/appwrite/sdk-generator",
"reference": "8fd05f838db79fb253875cfa68b31f48876acc85"
"reference": "ccab743c1a82aa116456114a66dfefe1976e125a"
},
"require": {
"ext-curl": "*",
@ -1652,7 +1652,7 @@
}
],
"description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms",
"time": "2020-04-12T10:47:23+00:00"
"time": "2020-04-14T14:07:24+00:00"
},
{
"name": "doctrine/instantiator",