Permalink
Browse files

more docs

  • Loading branch information...
1 parent 936370e commit 29661348456f0a4d48e8efe1d10560913546a480 @squallstar squallstar committed Feb 17, 2017
Showing with 244 additions and 0 deletions.
  1. +141 −0 docs/API/fliplet-datasources.md
  2. +103 −0 docs/API/fliplet-media.md
@@ -0,0 +1,141 @@
+# Fliplet DataSources JS APIs
+
+The `fliplet-datasources` package contains the following namespaces:
+
+- [Data Sources](#data-sources)
+
+---
+
+## Data Sources
+
+### Get the list of data sources for the current organization
+
+```js
+Fliplet.DataSources.get().then(function (dataSources) {});
+```
+
+### Create a new data source
+
+```js
+Fliplet.DataSources.create({
+ name: 'foo',
+ organizationId: 1 // optional
+}).then(function (dataSource) {
+
+});
+```
+
+### Connect to a data source, given its ID
+
+```js
+// All options are optional
+var options = {
+ offline: true/false // By default on native platform it connects to offline DB. Set this option to false to connect to api's
+
+}
+Fliplet.DataSources.connect(1, options).then(function (connection) {
+ // check below for usages of the connection
+});
+```
+
+Once you get a connection, you can use the following methods to find, insert, update and delete data.
+
+### Select records from a data source
+
+```js
+connection.find({
+ where: { name: 'John' }
+}).then(function (records) {
+
+});
+```
+
+### Query a data source
+
+```js
+// All options are optional
+var options = {
+ type: "select" // select(default)/update/delete
+ where: { name: 'John' },
+ attributes: ["name", "country"],
+ dataSourceEntryId: 123
+};
+connection.query(options).then(function (records) {
+
+});
+```
+
+### Find a record by its ID
+
+```js
+connection.findById(1).then(function (record) {
+
+});
+```
+
+### Replace the contents of the data source with new records
+
+```js
+connection.replaceWith([
+ { id: 1, name: 'Alice' },
+ { id: 2, name: 'Bob', email: 'bob@example.org' }
+]).then(function onComplete() {
+
+});
+```
+
+### Insert an array of new records into a data source
+
+```js
+connection.append([
+ { id: 3, name: 'Nick' },
+ { id: 4, name: 'Ian', email: 'ian@example.org' }
+]).then(function onComplete() {
+
+});
+```
+
+### Insert a single record into the data source
+
+```js
+connection.insert({
+ id: 3,
+ name: 'Bill'
+});
+```
+
+You can also pass a `FormData` object to upload files using a multipart request. When uploading files, you can also specify the MediaFolder where files should be stored to:
+
+```js
+connection.insert(FormData, {
+ mediaFolderId: 123
+});
+```
+
+### Update a record
+
+```js
+connection.update(123, {
+ name: 'Bill'
+});
+```
+
+You can also pass a `FormData` object to upload files using a multipart request. When uploading files, you can also specify the MediaFolder where files should be stored to:
+
+```js
+connection.update(123, FormData, {
+ mediaFolderId: 456
+});
+```
+
+### Import a file into the data sources
+
+```js
+connection.import(FormData).then(function onSuccess() {});
+```
+
+### Remove a record by its ID
+
+```js
+connection.removeById(1).then(function onRemove() {});
+```
@@ -0,0 +1,103 @@
+# Fliplet Media JS APIs
+
+The `fliplet-media` package contains the following namespaces:
+
+- [Folders](#folders)
+- [Files](#files)
+
+---
+
+## Folders
+
+### Get the list of folders belonging to an organization or an app
+
+```js
+// By default, belonging to the current app.
+// If not set, to the current organization
+Fliplet.Media.Folders().then(function (folders) {});
+
+// Belonging to an organization
+Fliplet.Media.Folders({ organizationId: 1 }).then(function (folders) {});
+
+// Belonging to an app
+Fliplet.Media.Folders({ appid: 1 }).then(function (folders) {});
+```
+
+### Create a new folder
+
+```js
+// Create a folder belonging to the current app
+Fliplet.Media.Folders.create({ name: 'foo' }).then(function (folder) { });
+```
+
+### Delete a folder
+
+```js
+// Delete a folder given its id
+Fliplet.Media.Folders.delete(1).then(function onComplete() { });
+```
+
+## Files
+
+### Upload one or more files
+
+Files can be added using the standard HTML APIs for [FormData](https://developer.mozilla.org/en/docs/Web/API/FormData).
+
+```js
+Fliplet.Media.Files.upload({
+ data: FormData,
+ folderId: 1 // optional folderId
+}).then(function (files) {
+
+});
+```
+
+### Delete a file
+
+```js
+// Delete a file given its id
+Fliplet.Media.Files.delete(2).then(function onComplete() { });
+```
+
+### Get images to offline cache
+Size options see [GM Resize docs](http://aheckmann.github.io/gm/docs.html#resize)
+files attribute on the param is an array of objects containing `name` and any other data you find useful.
+```js
+Fliplet.Media.Files.getCachedImages({
+ folderId: 456,
+ files: [{ name: 'John.jpg' }, { name: 'Alice.jpg' }],
+ size: '80x80>',
+ onProgress: function onProgress (file, data) {
+ /*
+ file = { name: 'John.jpg' }
+ data = {
+ id: 1,
+ name: 'John.jpg',
+ fileName: '1-80x80>-John.jpg',
+ path: 'url-to-your-file'
+ updatedAt: '2016-12-14T12:14:24.019Z'
+ }
+ */
+
+ // this is the best place to update the src of your img tags
+ // since the function will be called every time an image has been
+ // downloaded to the device storage
+ }
+}).then(function onFinish (images) {
+ /*
+ images [
+ {
+ file: { name: 'John.jpg'},
+ data: {
+ id: 1,
+ name: 'John.jpg',
+ fileName: '1-80x80>-John.jpg',
+ path: 'url-to-your-file'
+ updatedAt: '2016-12-14T12:14:24.019Z'
+ }
+ }
+ ]
+ */
+})
+
+```

0 comments on commit 2966134

Please sign in to comment.