Last updated:
0 purchases
flutter maya sdk
Client for Maya CMS #
A client for your Maya CMS content.
How Install #
Flutter: #
$ flutter pub add flutter_maya_sdk
copied to clipboard
Pubspec.yaml #
Add a line like this to your package's pubspec.yaml
dependencies:
flutter_maya_sdk: ^0.0.1
copied to clipboard
And run if your editor don't support flutter
flutter pub get
copied to clipboard
And import it #
Now in your Dart code, add
import 'package:flutter_maya_sdk/flutter_maya_sdk.dart';
copied to clipboard
How Initialize #
Minimal #
import 'package:flutter_maya_sdk/flutter_maya_sdk.dart';
// Minimal Initialisation of global instance
Maya.init(
server: Uri.parse("http://[SERVER HOST]"),
token: "[API TOKEN]",
);
// globale instance is accesible by `Maya.instance`
// Or
Maya maya = Maya(
server: Uri.parse("http://[SERVER HOST]"),
token: "[API TOKEN]",
)
copied to clipboard
Maya is not in root web folder #
import 'package:flutter_maya_sdk/flutter_maya_sdk.dart';
// Custom path
Maya.init(
server: Uri.https("[SERVER HOST]"."/Maya/folder"),
// OR
//server: Uri.http("[SERVER HOST]"."/Maya/folder"),
// OR
//server: Uri.parse("http://[SERVER HOST]/Maya/folder"),
token: "[API TOKEN]",
);
// Or
Maya maya = Maya(
server: Uri.parse("http://[SERVER HOST]"),
// OR
//server: Uri.http("[SERVER HOST]"."/Maya/folder"),
// OR
//server: Uri.parse("http://[SERVER HOST]/Maya/folder"),
token: "[API TOKEN]",
)
copied to clipboard
Filter for all request #
import 'package:flutter_maya_sdk/flutter_maya_sdk.dart';
// never get deleted fields
Maya.init(
server: Uri.https("[SERVER HOST]"."/Maya/folder"),
token: "[API TOKEN]",
defaultFilter : {
r"$or" :[
{ "delete" : {$eq : false} },
{ "delete" : {$eq : null} },
{
"delete" : {
r"$exist" : false
}
}
]
}
);
copied to clipboard
(Optional) Declare endpoint #
import 'package:flutter_maya_sdk/flutter_maya_sdk.dart';
// Api declaration
Maya.init(
server: Uri.https("[SERVER HOST]"."/Maya/folder"),
token: "[API TOKEN]",
api : {
// Collection
"myCollection" : {
"collection": "users", // real collection name
"sort": {"login": 1}, // default sort
"fields": [ // get only this fields
"nom",
"prenom",
"parent",
"login",
"enabled",
"_create_by"
]
},
// Form
"myForm" : {
"form": "sendmail" // real form name
},
// Singleton
"mySingleton" : {
"singleton": "configurations" // real singleton name
},
// clollection with virtual properties (map)
"slides" : {
"collection": "collection_name", //collection name in Maya
"limit": 5, // limit when get data from server
"sort": { // sort results
"_o": 1
},
"fields": [ // fields to gets from the server, other will be ignored
"title",
"image",
"description",
"backgroundColor",
"fontColor"
],
"map": { // change value of a property or set a new property in result object
// you can build string from a template
"image": "{{SERVER}}{{image.path}}",
// or map a property's value to another
"body" : "{{description}}"
},
},
}
);
copied to clipboard
How Use #
Read data #
// get all elements
List<Map<String, dynamic>> results = await MayaCollection("api_access").find(
cache: Duration(hours : 1), // [optional] cache result
);
// get first element
Map<String, dynamic> result = await MayaCollection("user").findOne(
filter: {
"login" : "root",
"pwd" : "secret",
r"$or": [
{"disable": false},
{
"disable": {
r"$exists": false,
},
},
],
},
);
// get specific element
Map<String, dynamic> result = await MayaCollection("user").get("[My Super ID]");
// get only some fields
Map<String, dynamic> result = await MayaCollection("user").get("[My Super ID]", fields : ["nom", "prenom"]
);
// get one page of elements
List<Map<String, dynamic>> results = await MayaCollection("api_access").find(
limit : 10,
page : 2
); // page start by 0, also set page to 0 for the first page, page to 1 for the second page
// get filtered elements , you can use page, limit, sort, etc. with filter
List<Map<String, dynamic>> results = await MayaCollection("api_access").find(
filter: {
published : true,
},
);
copied to clipboard
Read undeclared endpoint #
To read an undelared endpoint you can just pass the name and use a prefix to specify the type (form, singleton,collection or custom url)
Prefix
Type
Usage
*
Collection
Maya("my_collection") OR Maya("*my_collection")
@
Singleton
Maya("@my_singleton")
#
Form
Maya("#my_form")
!
Custom Maya Api
Maya("!my/custom/url")
Save data #
// post data to Maya (form and collection)
Map<String, dynamic> data = await MayaCollection("api_access").save(
data : {
published : false,
title : "Cool",
description : "I'm juste a test :-p",
},
);
copied to clipboard
post to a Custom Url #
// post data to a custom Maya url
Map<String, dynamic> data = await MayaApi("!/my/custom/url/gps").save(
data : {
lat : -19.016682,
long : 26.806641,
alt : 15,
},
);
copied to clipboard
Maya urls #
Login as system user #
Map<String, dynamic> user = Maya.instance.login('username','xxpasswordxx')
copied to clipboard
Logout as system user #
bool logout = await Maya.instance.logout()
copied to clipboard
Create / Update user #
Maya.instance.saveSystemUser({...}) // user data (user, name, email, active, group)
copied to clipboard
Get users. #
Maya.instance.systemUsers([Map<String, dynamic> filter]) // (optional) you can pass filter
copied to clipboard
Get assets #
Maya.instance.assets([Map<String, dynamic> filter]) // (optional) you can pass filter
copied to clipboard
Get thumbnail url #
Maya.instance.image(imagePath,
width : width,
height : height,
quality : quality,
domain : domain,
o : o,
base64 : base64,
);
copied to clipboard
Get all singletons #
Maya.listSingletons()
copied to clipboard
Get all collections #
Maya.listCollections();
copied to clipboard
Get collection schema #
Maya("collectionname").schema();
copied to clipboard
Update collection schema #
Maya("collectionname").updateSchema(fields); // fields is List<Map<String,dynamic>>
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.