-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparstangular.js
More file actions
97 lines (81 loc) · 3.39 KB
/
Copy pathparstangular.js
File metadata and controls
97 lines (81 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* @license Parstangular v0.1.0
* (c) 2014 Arcnovus, Inc. http://parstangular.com
* License: MIT
*
* Parstangular is a simple Restangular wrapper for the Parse.com REST API.
*/
/**
* This is an object in which to place your Parse.com configuration settings.
* Make sure to put your Parse App Id and Rest Api Key below.
* You can probably leave the BASE_URL property as is, unless Parse
* has introduced a new version of their API that you intend to use.
*/
var parseConfig = {};
parseConfig.APP_ID = 'YOUR-APP-ID-GOES-HERE';
parseConfig.API_KEY = 'YOUR-REST-API-KEY-GOES-HERE';
parseConfig.BASE_URL = 'https://api.parse.com/1/';
/** The Parstangular module is the main module that houses our Parstangular goodness **/
var ParseApiModule = angular.module("Parstangular", ['restangular']);
/** Throw our Parse configuration object into the mix **/
ParseApiModule.constant("PARSE_CONFIG", parseConfig);
/** Configure the RestangularProvider **/
ParseApiModule.config(function (RestangularProvider) {
// Now let's configure the response extractor for each request
RestangularProvider.setResponseExtractor(function (response, operation, what, url) {
// This is a get for a list
var newResponse;
if (operation === "getList") {
// Parse always wraps the results in an array called 'results' so here's where we tell Restangular about that
newResponse = response.results;
}
return newResponse;
});
});
/** A factory that returns a Parsified version of Restangular **/
ParseApiModule.factory('ParseService', ['Restangular', 'PARSE_CONFIG',
function (Restangular, parseConfig) {
/** An instance of Restangular that has been configured to work with Parse **/
var ParseApi = Restangular.withConfig(function (RestangularConfigurer) {
RestangularConfigurer.setBaseUrl(parseConfig.BASE_URL);
RestangularConfigurer.setDefaultHeaders({
'X-Parse-Application-Id': parseConfig.APP_ID,
'X-Parse-REST-API-Key': parseConfig.API_KEY
});
RestangularConfigurer.setRestangularFields({
id: "objectId",
createdAt: "createdAt",
updatedAt: "updatedAt"
});
});
/** A helper function to reference the Rest path to your Parse objects **/
ParseApi.Class = function (objName) {
return this.all('classes').all(objName);
};
/** A helper function to reference the Parse users path **/
ParseApi.User = function () {
return this.all('users');
};
/** A helper function to get the currently logged in Parse User **/
ParseApi.getCurrentUser = function () {
return this.User.one('me').get();
};
/** A helper function Parse Login **/
ParseApi.login = function (username, password) {
var credentials = {
"username": username,
"password": password
};
return this.one('login').get(credentials);
};
ParseApi.signUp = function (userObj) {
return this.User.post(userObj);
};
ParseApi.requestPasswordReset = function (email) {
var emailObj = {
"email": email
};
return this.one('requestPasswordReset').post(emailObj);
};
return ParseApi;
}]);