Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

edraj/flutterdmart

Open more actions menu

Repository files navigation

Dart client for Dmart

A Dart implementation of the Dmart that depends on dio.

APIs

Properties:

  • String dmartServerUrl - The base URL of the Dmart instance.
  • String token - The token to be used for authentication.

Methods:

  • void initDmart({Dio? dio, BaseOptions? dioConfig, Iterable<Interceptor> interceptors = const [], bool isDioVerbose = false,}) - Initializes the Dio networking instance.
    • if dio is set:
      • dioConfig will not take effect.
      • isDioVerbose will still extend the interceptor.
      • interceptors will still extend the interceptor.
  • 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<(ApiResponse?, Error?)> otpRequest(SendOTPRequest request) - Sends an OTP request for authentication.
  • Future<(ApiResponse?, Error?)> otpRequestLogin(SendOTPRequest request) - Sends an OTP request for login.
  • Future<(ApiResponse?, Error?)> passwordResetRequest(PasswordResetRequest request) - Sends a password reset request.
  • Future<(ApiResponse?, Error?)> confirmOTP(ConfirmOTPRequest request) - Confirms the OTP for login or password reset.
  • Future<(ApiResponse?, Error?)> userReset(String shortname) - Resets a user's password.
  • Future<(ApiResponse?, Error?)> validatePassword(String password) - Validates the user's password.
  • Future<(ProfileResponse?, Error?)> getProfile() - Retrieves the current user's profile.
  • Future<(ProfileResponse?, Error?)> updateProfile(ActionRequestRecord profile) - Updates the 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.
  • String getMediaTypeFromDmartContentType(DmartContentType.ContentType contentType) - Returns the media type from a Dmart content type.

Basic Usage

  • Always initialize the Dmart instance before using it.
Dmart.initDmart();
// Or with dio verbose for debugging purposes
Dmart.initDmart(isDioVerbose: true);
  • Getting manifests and settings
// Get manifests
var (respManifests, _) = await Dmart.getManifest();
// Get settings
var (respSettings, _) = await Dmart.getSettings();
  • 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,
));
  • 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';
  • Get user profile
var (respProfile, _) = await Dmart.getProfile();
  • Update user profile
var (respProfile, _) = await Dmart.updateProfile(
    ActionRequestRecord(
        shortname: 'dmart',
        resourceType: ResourceType.user,
        subpath: 'users',
        attributes: {'language': 'kurdish'},
    ),
);
  • Get all spaces
var (respSpaces, _) = await Dmart.getSpaces();
  • 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);
  • 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);
}

*Retrieve entry

var (respEntry, _) = await Dmart.retrieveEntry(
  RetrieveEntryRequest(
      resourceType: ResourceType.user,
      spaceName: 'management',
      subpath: 'users',
      shortname: 'jimmy',
      retrieveJsonPayload: true,
  )
);
  • Get entry payload
var (respEntryPayload, _) = await Dmart.getPayload(GetPayloadRequest(
  resourceType: ResourceType.content,
  spaceName: 'myspace',
  subpath: 'mysubpath',
  shortname: 'myentry'
));
  • 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);
  • Progress a ticket
var (respProgression, _) = await Dmart.progressTicket(
  ProgressTicketRequest(
    spaceName: "myspace",
    subpath: "test",
    shortname: "myticket",
    action: "rejected",
  )
);
  • Create attachment
File img = File("/path/to/myimg.jpg");
var (respAttachmentCreation, _) = await Dmart.createAttachment(
    spaceName: "myspace",
    entitySubpath: "mysubpath",
    entityShortname: "myshortname",
    attachmentShortname: "auto",
    attachmentBinary: img,
);
  • Get attachment url
String attachmentURL = await Dmart.getAttachmentUrl(
    spaceName: "myspace",
    entitySubpath: "mysubpath",
    entityShortname: "myshortname",
    attachmentShortname: "myAttachment",
);
  • Submit an entry
var (respSubmitEntry, _) = await Dmart.submit(
    "applications",
    "log",
    "logs",
    {
      "shortname": "myentry",
      "resource_type": ResourceType.content.name,
      "state": "awesome entry it is !"
    },
);
  • Logout
var (respLogout, _) = await Dmart.logout();

About

Flutter client library for DMART

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.