dmart

Creator: coderz1093

Last updated:

0 purchases

dmart Image
dmart Images

Languages

Categories

Add to Cart

Description:

dmart

Dart client for Dmart #
A Dart implementation of the Dmart that depends on dio.
APIs #

void initDmart({bool isDioVerbose = false}) - Initializes the Dio networking instance.
Future<dynamic> getManifest() - Retrieves the Dmart manifest.
Future<dynamic> getSettings() - Retrieves the Dmart settings.
Future<(LoginResponse?, Error?)> login(LoginRequest loginRequest) - Authenticates a user and returns login information.
Future<(CreateUserResponse?, Error?)> createUser(CreateUserRequest createUserRequest) - Creates a new user.
Future<(ApiResponse?, Error?)> logout() - Logs the user out.
Future<(ProfileResponse?, Error?)> getProfile() - Retrieves the current user's profile.
Future<(ApiQueryResponse?, Error?)> query(QueryRequest query, {String scope = "managed"}) - Executes a query against the Dmart backend.
Future<(ActionResponse?, Error?)> request(ActionRequest action) - Performs an action on the Dmart system.
Future<(ResponseEntry?, Error?)> retrieveEntry(RetrieveEntryRequest request, {String scope = "managed"}) - Fetches a specific entry from Dmart.
Future<(ActionResponse?, Error?)> createSpace(ActionRequest action) - Creates a new space.
Future<(ApiQueryResponse?, Error?)> getSpaces() - Retrieves a list of spaces.
Future<dynamic> getPayload(GetPayloadRequest request) - Retrieves payload data.
Future<(ApiQueryResponse?, Error?)> progressTicket(ProgressTicketRequest request) - Updates a progress ticket.
Future<(Response?, Error?)> createAttachment({required String shortname, required String entitySubpath, required File payloadFile, required String spaceName, bool isActive = true, String resourceType = "media"}) - Uploads an attachment.
Future<(ActionResponse?, Error?)> submit(String spaceName, String schemaShortname, String subpath, Map<String, dynamic> record) - Submits a record (log/feedback) to Dmart.
String getAttachmentUrl(String resourceType, String spaceName, String subpath, String parentShortname, String shortname, String ext) - Constructs an attachment URL.

Basic Usage #

Always initialize the Dmart instance before using it.

Dmart.initDmart();
// Or with dio verbose for debugging purposes
Dmart.initDmart(isDioVerbose: true);
copied to clipboard

Getting manifests and settings

// Get manifests
var (respManifests, _) = await Dmart.getManifest();
// Get settings
var (respSettings, _) = await Dmart.getSettings();
copied to clipboard

User creation

final CreateUserAttributes createUserAttributes = CreateUserAttributes(
displayname: Displayname(en: 'test'),
invitation: 'ABC',
password: '@Jimmy123_',
roles: ['super_admin'],
);
var (responseCreateUser, error) = await Dmart.createUser(CreateUserRequest(
shortname: 'jimmy',
attributes: createUserAttributes,
));
copied to clipboard

User login

// By using shortname and password
var (responseLogin, _) = await Dmart.login(
LoginRequest(shortname: 'jimmy', password: '@Jimmy123_'),
);

// By using email or msisdn instead of shortname
LoginRequest.withEmail
LoginRequest.withMsisdn

// By passing directly a token
Dmart.token = 'xxx.yyy.zzz';
copied to clipboard

Get user profile

var (respProfile, _) = await Dmart.getProfile();
copied to clipboard

Get all spaces

var (respSpaces, _) = await Dmart.getSpaces();
copied to clipboard

Create a space

ActionRequest createSpaceActionRequest = ActionRequest(
spaceName: 'my_space',
requestType: RequestType.create,
records: [
ActionRequestRecord(
resourceType: ResourceType.space,
shortname: 'my_space',
subpath: '/',
attributes: {
'displayname': {'en': 'Space'},
'shortname': 'space',
},
),
]);

var (respCreateSpace, _) = await Dmart.createSpace(createSpaceActionRequest);
copied to clipboard

Querying a subpath

var (respQuery, _) = await Dmart.query(
QueryRequest(
queryType: QueryType.subpath,
spaceName: 'management',
subpath: 'users',
retrieveJsonPayload: true,
),
);
for (var record in respQuery?.records ?? []) {
print(record.shortname);
}
copied to clipboard
*Retrieve entry
var (respEntry, _) = await Dmart.retrieveEntry(
RetrieveEntryRequest(
resourceType: ResourceType.user,
spaceName: 'management',
subpath: 'users',
shortname: 'jimmy',
retrieveJsonPayload: true,
)
);
copied to clipboard

Get entry payload

var (respEntryPayload, _) = await Dmart.getPayload(GetPayloadRequest(
resourceType: ResourceType.content,
spaceName: 'myspace',
subpath: 'mysubpath',
shortname: 'myentry'
));
copied to clipboard

Content creation

// folder creation
ActionRequestRecord actionRequestRecord = ActionRequestRecord(
resourceType: ResourceType.folder,
subpath: '/',
shortname: 'my_subpath',
attributes: subpathAttributes,
);
ActionRequest action = ActionRequest(
spaceName: 'my_space',
requestType: RequestType.create,
records: [actionRequestRecord],
);
var (respRequestFolder, err) = await Dmart.request(action);

// content creation
ActionRequestRecord actionRequestRecord = ActionRequestRecord(
resourceType: ResourceType.content,
subpath: 'my_subpath',
shortname: 'my_content',
attributes: {
"is_active": true,
"relationships": [],
"payload": {
"content_type": "json",
"schema_shortname": null,
"body": {
"isAlive": true
}
}
},
);
ActionRequest action = ActionRequest(
spaceName: 'my_space',
requestType: RequestType.create,
records: [actionRequestRecord],
);
var (respRequestContent, err) = await Dmart.request(action);

// attachment creation
ActionRequestRecord actionRequestRecord = ActionRequestRecord(
resourceType: ResourceType.json,
subpath: 'my_subpath/my_content',
shortname: 'auto',
attributes: {
"is_active": true,
"payload": {
"content_type": "json",
"schema_shortname": null,
"body": {
"attachmentName": "my attachment",
"isImportant": "very important"
}
}
},
);
ActionRequest action = ActionRequest(
spaceName: 'my_space',
requestType: RequestType.create,
records: [actionRequestRecord],
);
var (respRequestAttachment, err) = await Dmart.request(action);
copied to clipboard

Progress a ticket

var (respProgression, _) = await Dmart.progressTicket(
ProgressTicketRequest(
spaceName: "myspace",
subpath: "test",
shortname: "myticket",
action: "rejected",
)
);
copied to clipboard

Create attachment

File img = File("/path/to/myimg.jpg");
var (respAttachmentCreation, _) = await Dmart.createAttachment(
spaceName: "myspace",
entitySubpath: "mysubpath",
entityShortname: "myshortname",
attachmentShortname: "auto",
attachmentBinary: img,
);
copied to clipboard

Get attachment url

String attachmentURL = await Dmart.getAttachmentUrl(
spaceName: "myspace",
entitySubpath: "mysubpath",
entityShortname: "myshortname",
attachmentShortname: "myAttachment",
);
copied to clipboard

Submit an entry

var (respSubmitEntry, _) = await Dmart.submit(
"applications",
"log",
"logs",
{
"shortname": "myentry",
"resource_type": ResourceType.content.name,
"state": "awesome entry it is !"
},
);
copied to clipboard

Logout

var (respLogout, _) = await Dmart.logout();
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.