EnginioClient

Client interface to access Enginio service More...

Import Statement: import Enginio .

Properties

Signals

Methods

  • EnginioReply downloadUrl(QJSValue object)
  • EnginioReply fullTextSearch(QJSValue query)
  • EnginioReply remove(QJSValue query, Operation operation)
  • EnginioReply update(QJSValue query, Operation operation)
  • EnginioReply uploadFile(QJSValue object, QUrl file)

Detailed Description

import Enginio 1.0

EnginioClient is the heart of the QML API for Enginio. It is used for all communication with the Enginio backend. EnginioModel compliments it to make handling of multiple objects simple.

The backend is identified by backend ID.

EnginioClient {
    id: client
    backendId: "YOUR_BACKEND_ID" // from Enginio Dashboard
}

Once the backend is configured, it is possible to run queries by calling query on EnginioClient. For example to get all objects stored with the type "objects.image" run this query:

EnginioClient {
    // ...
    Component.onCompleted: query({"objectType": "objects.image"})
}

EnginioClient gives you a convenient way to handle the responses to your queryies as well:

EnginioClient {
    // ...
    onFinished: console.log("Engino request finished." + reply.data)
    onError: console.log("Enginio error " + reply.errorCode + ": " + reply.errorString)
}

Property Documentation

authenticationState : Enginio::AuthenticationState

The state of the authentication.

Enginio provides convenient user management. The authentication state reflects whether the current user is authenticated.

See also identity and EnginioOAuth2Authentication.


backendId : string

Enginio backend ID. This can be obtained from the Enginio dashboard.


identity : EnginioIdentity

Property that represents a user. Setting the property will create an asynchronous authentication request, the result of it updates authenticationState

It is allowed to assign a null pointer to the property to terminate the session.

See also authenticationState, sessionAuthenticated, sessionAuthenticationError, and EnginioOAuth2Authentication.


Signal Documentation

error(QJSValue reply)

This signal is emitted when a reply finishes and contains an error.


finished(QJSValue reply)

This signal is emitted when a reply finishes.

Note: that this signal is alwasy emitted, independent of whether the reply finished successfully or not.


sessionAuthenticated(QJSValue reply)

Emitted when a user logs in.

The signal is emitted after a user was successfully logged into the backend. From that point on, all communication with the backend will be using these credentials. The reply contains the information about the login and the user, the details may be different depending on used authentication method, but a typical reply may look like that:

{
  "access_token": "...",              // oauth2 access token
  "refresh_token": "...",             // oauth2 refresh token
  "token_type": "bearer",             // oauth2 token type
  "expires_in": 28799,                // oautth2 token expiry date
  "enginio_data": {
    "user": {
      "id": "...",                    // this user Id
      "createdAt": "...",             // when the user was created
      "creator": {                    // who created the user
        "id": "creatorId",
        "objectType": "users"
      },
      "email": "user@user.com",       // the user's email address
      "firstName": "John",            // the user's first name
      "lastName": "Foo",              // the user's last name
      "objectType": "users",
      "updatedAt": "2013-11-25T14:54:58.957Z",
      "username": "JohnFoo"           // the user's login
    },
    "usergroups": []                  // usergroups to which the user belongs
  }
}

See also EnginioClient::sessionAuthenticationError(), EnginioReply, and EnginioOAuth2Authentication.


sessionAuthenticationError(QJSValue reply) const

Emitted when a user login fails.

The reply contains the details about why the login failed.

See also EnginioClient::sessionAuthenticated(), EnginioReply, EnginioClientConnection::identity, and EnginioOAuth2Authentication.


sessionTerminated() const

Emitted when a user logs out.

See also EnginioOAuth2Authentication.


Method Documentation

EnginioReply downloadUrl(QJSValue object)

Get the download URL for a file

var downloadData = {
    "id": uploadReply.data.id,
}
var downloadReply = enginio.downloadUrl(downloadData)

The response contains the download URL and the duration how long the URL will be valid.

downloadReply.data.expiringUrl
downloadReply.data.expiresAt

See also uploadFile().


EnginioReply fullTextSearch(QJSValue query)

Perform a full text search on the database

The query is an object sent to the backend to perform a fulltext search. Note that the search requires the searched properties to be indexed (on the server, configureable in the backend).

Returns EnginioReply containing the status and the result once it is finished.

See also EnginioReply, EnginioClient::create(), EnginioClient::query(), EnginioClient::update(), EnginioClient::remove(), and JSON request structure.


EnginioReply remove(QJSValue query, Operation operation)

Remove an object from the database.

Returns EnginioReply containing the status once it is finished.


EnginioReply update(QJSValue query, Operation operation)

Update an object in the database.

To update access control list of an object the JSON loook like this:

{
      "id": "objectId",
      "objectType": "objects.objectType",
      "access": { "read": ["id": "userId", "objectTypes": "users"],
                   "update": ["id": "userId", "objectTypes": "users"],
                   "admin": ["id": "userId", "objectTypes": "users"] }
}

Returns EnginioReply containing the status of the query and the data once it is finished.


EnginioReply uploadFile(QJSValue object, QUrl file)

Stores a file attached to an object in Enginio

Each uploaded file needs to be associated with an object in the database.

Note: The upload will only work with the propper server setup: in the dashboard create a property of the type that you will use. Set this property to be a reference to files.

In order to upload a file, first create an object:

var fileObject = {
    "objectType": AppConfig.testObjectType,
    "title": "Example object with file attachment",
}
var reply = enginio.create(fileObject);

Then do the actual upload:

var objectId = reply.data.id
var uploadData = {
    "file":{
        "fileName":"test.png"
    },
    "targetFileProperty": {
        "objectType": AppConfig.testObjectType,
        "id": objectId,
        "propertyName": "fileAttachment"
    },
}
var uploadReply = enginio.uploadFile(uploadData, fileName)

Note: There is no need to directly delete files. Instead when the object that contains the link to the file gets deleted, the file will automatically be deleted as well.

See also downloadUrl().