AngularJS service used to access Salesforce REST calls from within a MobileCaddy application
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
js
scripts
test
.gitignore
.npmignore
.travis.yml
Gruntfile.js
README.md
package.json

README.md

MobileCaddy App Addon - McRest

Overview

AngularJS service used to access Salesforce REST calls from within a MobileCaddy application.

Build Status

Installation

npm install mobilecaddy-app-addon-mcrest

The installation will include the tasks of moving the relevant scripts into the correct place of your MobileCaddy appication project structure. Included in this copying of files will be the relevant unit tests

Setup

  • Ensure that the MobileCaddy appDataUtils is exposed in your project's www/js/services/service.module.js. It should contain these lines;
angular.module('appDataUtils', [])
  .factory('appDataUtils', function() {
    return mobileCaddy.require('mobileCaddy/appDataUtils');
});

And the appDataUtils should be included in this line also;

angular.module('starter.services', ['underscore', 'devUtils', 'vsnUtils', 'smartStoreUtils', 'syncRefresh', 'appDataUtils', 'logger']);

Configuring

You can configure the API version to be used like this. If no API version is set, the default shall be used. This can be run in the .run in the app.js. The format of the version number is strict, and the call will return false if the supplied value is not valid.

McRestService.config({apiVersion: "v41.0"});

Calls Available

For example usage please checkout the MobileCaddy KitchenSink App

query

For SOQL queries

Example

Seardhing for a contact

var soql = "SELECT name, id FROM Contact WHERE name LIKE 'dave'";

McRestService.query(soql).then(function(result){
	console.log("My results", result.records);
}

request

Generic calls

Examples

Getting the latest chatter posts.

var obj = {
	method: 'GET',
	contentType: 'application/json',
	path: '/services/data/v36.0/chatter/feeds/news/me/feed-elements'
};
McRestService.request(obj).then(function(result){
	console.log("getLatestChatter result",
		result.elements[0].actor.displayName,
		result.elements[0].body.text);
});

List Salesforce files

var obj = {
	method: 'GET',
	contentType: 'application/json',
	path: '/services/data/v40.0/connect/files/users/me'
};
McRestService.request(obj).then(function(result){
	console.log("restCall result", result);
	vm.fs = result.files;
});

requestBuffer

Retrieves Salesforce files

Example

var obj = {
	method: 'GET',
	path: myfile.downloadUrl
};
McRestService.requestBuffer(obj).then(function(result){
	console.log("downloadRemote result", result);
	var dataObj = new Blob([result]);
});

upload

Uploads files to Salesforce. Returns an object representing the file on Salesforce, if successful.

Example

McRestService.upload(vm.file).then(function(result){

});