"
+ }, {
+ name: "addVideo",
+ post: "classes/videos"
+ }],
+ onError: function(e, retry) {
+ alert("There was an error connecting to the server, check your network connection and retry.");
+ retry();
+ },
+ onLoad: function(e, callback) {
+ callback(e);
+ }
+});
+```
+
+4. Use the configured methods in your React components:
+
+```javascript
+api.getVideos().then(videos => {
+ // do stuff with the videos
+}).catch(error => {
+ console.error(error);
+});
+```
+
## License
diff --git a/reste.js b/reste.js
index 97378a9..acd2ff1 100644
--- a/reste.js
+++ b/reste.js
@@ -377,15 +377,15 @@ function main() {
};
reste.createCollection = function (name, content) {
- if (!Alloy.Collections[name]) {
- Alloy.Collections[name] = new Backbone.Collection();
+ if (!reste.Collections[name]) {
+ reste.Collections[name] = new Backbone.Collection();
}
if (content instanceof Array) {
- Alloy.Collections[name].reset(content);
+ reste.Collections[name].reset(content);
- Alloy.Collections[name].fetch = function () {
- Alloy.Collections[name].trigger('change');
+ reste.Collections[name].fetch = function () {
+ reste.Collections[name].trigger('change');
};
} else {
throw 'No Array specified for createCollection';
@@ -415,10 +415,10 @@ function main() {
if (args.collections) {
args.collections.forEach((collection) => {
- Alloy.Collections[collection.name] = Alloy.Collections[collection.name] || new Backbone.Collection();
- Alloy.Collections[collection.name]._type = args.name;
- Alloy.Collections[collection.name]._name = collection.name;
- Alloy.Collections[collection.name].model = model;
+ reste.Collections[collection.name] = reste.Collections[collection.name] || new Backbone.Collection();
+ reste.Collections[collection.name]._type = args.name;
+ reste.Collections[collection.name]._name = collection.name;
+ reste.Collections[collection.name].model = model;
});
}
};
@@ -447,7 +447,7 @@ function main() {
if (options.success) options.success(response[collectionConfig.content]);
- Alloy.Collections[collectionConfig.name].trigger('sync');
+ reste.Collections[collectionConfig.name].trigger('sync');
} else {
response.forEach((item) => {
item.id = item[modelConfig.id];
@@ -455,7 +455,7 @@ function main() {
if (options.success) options.success(response);
- Alloy.Collections[collectionConfig.name].trigger('sync');
+ reste.Collections[collectionConfig.name].trigger('sync');
}
}
}, (response) => {
diff --git a/tests/alloy.test.js b/tests/alloy.test.js
new file mode 100644
index 0000000..075b415
--- /dev/null
+++ b/tests/alloy.test.js
@@ -0,0 +1,73 @@
+const reste = require('../reste');
+const assert = require('assert');
+
+describe('RESTe Alloy (Titanium) Tests', function() {
+ let api;
+
+ beforeEach(function() {
+ api = new reste();
+ api.config({
+ debug: true,
+ errorsAsObjects: true,
+ autoValidateParams: false,
+ validatesSecureCertificate: false,
+ timeout: 4000,
+ url: "https://api.parse.com/1/",
+ requestHeaders: {
+ "X-Parse-Application-Id": "APPID",
+ "X-Parse-REST-API-Key": "RESTID",
+ "Content-Type": "application/json"
+ },
+ methods: [{
+ name: "courses",
+ post: "functions/getCourses",
+ onError: function(e, callback, globalOnError){
+ console.error("There was an error getting the courses!");
+ }
+ }, {
+ name: "getVideos",
+ get: "classes/videos"
+ }, {
+ name: "getVideoById",
+ get: "classes/videos/"
+ }, {
+ name: "addVideo",
+ post: "classes/videos"
+ }],
+ onError: function(e, retry) {
+ console.error("There was an error connecting to the server, check your network connection and retry.");
+ retry();
+ },
+ onLoad: function(e, callback) {
+ callback(e);
+ }
+ });
+ });
+
+ it('should fetch videos', function(done) {
+ api.getVideos().then(videos => {
+ assert(Array.isArray(videos), 'Expected videos to be an array');
+ done();
+ }).catch(error => {
+ done(error);
+ });
+ });
+
+ it('should fetch video by id', function(done) {
+ api.getVideoById({ videoId: "fUAM4ZFj9X" }).then(video => {
+ assert(video, 'Expected video to be defined');
+ done();
+ }).catch(error => {
+ done(error);
+ });
+ });
+
+ it('should add a video', function(done) {
+ api.addVideo({ body: { categoryId: 1, name: "My Video" } }).then(video => {
+ assert(video, 'Expected video to be defined');
+ done();
+ }).catch(error => {
+ done(error);
+ });
+ });
+});
diff --git a/tests/node.test.js b/tests/node.test.js
new file mode 100644
index 0000000..214f525
--- /dev/null
+++ b/tests/node.test.js
@@ -0,0 +1,73 @@
+const reste = require('../reste');
+const assert = require('assert');
+
+describe('RESTe Node Tests', function() {
+ let api;
+
+ beforeEach(function() {
+ api = new reste();
+ api.config({
+ debug: true,
+ errorsAsObjects: true,
+ autoValidateParams: false,
+ validatesSecureCertificate: false,
+ timeout: 4000,
+ url: "https://api.parse.com/1/",
+ requestHeaders: {
+ "X-Parse-Application-Id": "APPID",
+ "X-Parse-REST-API-Key": "RESTID",
+ "Content-Type": "application/json"
+ },
+ methods: [{
+ name: "courses",
+ post: "functions/getCourses",
+ onError: function(e, callback, globalOnError){
+ console.error("There was an error getting the courses!");
+ }
+ }, {
+ name: "getVideos",
+ get: "classes/videos"
+ }, {
+ name: "getVideoById",
+ get: "classes/videos/"
+ }, {
+ name: "addVideo",
+ post: "classes/videos"
+ }],
+ onError: function(e, retry) {
+ console.error("There was an error connecting to the server, check your network connection and retry.");
+ retry();
+ },
+ onLoad: function(e, callback) {
+ callback(e);
+ }
+ });
+ });
+
+ it('should fetch videos', function(done) {
+ api.getVideos().then(videos => {
+ assert(Array.isArray(videos), 'Expected videos to be an array');
+ done();
+ }).catch(error => {
+ done(error);
+ });
+ });
+
+ it('should fetch video by id', function(done) {
+ api.getVideoById({ videoId: "fUAM4ZFj9X" }).then(video => {
+ assert(video, 'Expected video to be defined');
+ done();
+ }).catch(error => {
+ done(error);
+ });
+ });
+
+ it('should add a video', function(done) {
+ api.addVideo({ body: { categoryId: 1, name: "My Video" } }).then(video => {
+ assert(video, 'Expected video to be defined');
+ done();
+ }).catch(error => {
+ done(error);
+ });
+ });
+});
diff --git a/tests/react.test.js b/tests/react.test.js
new file mode 100644
index 0000000..73c3f69
--- /dev/null
+++ b/tests/react.test.js
@@ -0,0 +1,73 @@
+const reste = require('../reste');
+const assert = require('assert');
+
+describe('RESTe React Tests', function() {
+ let api;
+
+ beforeEach(function() {
+ api = new reste();
+ api.config({
+ debug: true,
+ errorsAsObjects: true,
+ autoValidateParams: false,
+ validatesSecureCertificate: false,
+ timeout: 4000,
+ url: "https://api.parse.com/1/",
+ requestHeaders: {
+ "X-Parse-Application-Id": "APPID",
+ "X-Parse-REST-API-Key": "RESTID",
+ "Content-Type": "application/json"
+ },
+ methods: [{
+ name: "courses",
+ post: "functions/getCourses",
+ onError: function(e, callback, globalOnError){
+ console.error("There was an error getting the courses!");
+ }
+ }, {
+ name: "getVideos",
+ get: "classes/videos"
+ }, {
+ name: "getVideoById",
+ get: "classes/videos/"
+ }, {
+ name: "addVideo",
+ post: "classes/videos"
+ }],
+ onError: function(e, retry) {
+ console.error("There was an error connecting to the server, check your network connection and retry.");
+ retry();
+ },
+ onLoad: function(e, callback) {
+ callback(e);
+ }
+ });
+ });
+
+ it('should fetch videos', function(done) {
+ api.getVideos().then(videos => {
+ assert(Array.isArray(videos), 'Expected videos to be an array');
+ done();
+ }).catch(error => {
+ done(error);
+ });
+ });
+
+ it('should fetch video by id', function(done) {
+ api.getVideoById({ videoId: "fUAM4ZFj9X" }).then(video => {
+ assert(video, 'Expected video to be defined');
+ done();
+ }).catch(error => {
+ done(error);
+ });
+ });
+
+ it('should add a video', function(done) {
+ api.addVideo({ body: { categoryId: 1, name: "My Video" } }).then(video => {
+ assert(video, 'Expected video to be defined');
+ done();
+ }).catch(error => {
+ done(error);
+ });
+ });
+});