platform 3.1.1 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +1 -3
- data/README.rdoc +140 -3
- data/app/assets/images/platform/help/app_reg.png +0 -0
- data/app/assets/images/platform/help/app_reg_ext.png +0 -0
- data/app/assets/images/platform/help/app_reg_web.png +0 -0
- data/app/assets/images/platform/help/auth_desktop.png +0 -0
- data/app/assets/images/platform/help/auth_iframe.png +0 -0
- data/app/assets/images/platform/help/auth_iphone.png +0 -0
- data/app/assets/images/platform/help/auth_web.png +0 -0
- data/app/assets/images/platform/help/authorize.png +0 -0
- data/app/assets/images/platform/help/ext.png +0 -0
- data/app/assets/images/platform/help/login_desktop.png +0 -0
- data/app/assets/images/platform/help/login_iphone.png +0 -0
- data/app/assets/images/platform/help/login_web.png +0 -0
- data/app/assets/images/platform/help/register_desktop.png +0 -0
- data/app/assets/images/platform/help/register_iphone.png +0 -0
- data/app/assets/javascripts/platform/platform.js +1 -1
- data/app/controllers/platform/api/base_controller.rb +24 -14
- data/app/controllers/platform/apps_controller.rb +16 -0
- data/app/controllers/platform/developer/help_controller.rb +2 -15
- data/app/controllers/platform/oauth_controller.rb +3 -3
- data/app/helpers/platform/admin/categories_helper.rb +1 -1
- data/app/helpers/platform/developer/help_helper.rb +2 -1
- data/app/models/platform/application.rb +2 -0
- data/app/models/platform/developer.rb +2 -0
- data/app/models/platform/logged_exception.rb +1 -1
- data/app/views/platform/admin/clientsdk/index.html.erb +12 -12
- data/app/views/platform/apps/_search_apps_module.html.erb +1 -1
- data/app/views/platform/apps/settings.html.erb +77 -0
- data/app/views/platform/developer/api_explorer/options.html.erb +0 -2
- data/app/views/platform/developer/dashboard/index.html.erb +1 -1
- data/app/views/platform/developer/help/_navigation.html.erb +1 -1
- data/app/views/platform/developer/help/oauth_client_side.html.erb +17 -15
- data/app/views/platform/developer/help/oauth_extensions.html.erb +1 -1
- data/app/views/platform/developer/help/oauth_mobile.html.erb +12 -12
- data/app/views/platform/developer/help/oauth_server_side.html.erb +6 -6
- data/app/views/platform/developer/help/sdk_ios.html.erb +3 -3
- data/app/views/platform/developer/help/sdk_js.html.erb +13 -185
- data/app/views/platform/developer/info/_basic_info.html.erb +1 -1
- data/app/views/platform/developer/info/_header.html.erb +3 -3
- data/app/views/platform/developer/registration/index.html.erb +30 -30
- data/app/views/platform/oauth/_authorization_box.html.erb +6 -7
- data/app/views/platform/oauth/_authorization_popup.html.erb +1 -1
- data/app/views/platform/oauth/authorize_desktop.html.erb +1 -76
- data/config/routes.rb +2 -4
- data/lib/generators/platform/proxy_generator.rb +78 -0
- data/lib/generators/platform/templates/config/platform/api/0/platform.yml +55 -0
- data/lib/generators/platform/templates/config/platform/api/0/platform_application.yml +37 -0
- data/lib/generators/platform/templates/config/platform/api/0/platform_developer.yml +22 -0
- data/{config → lib/generators/platform/templates/config}/platform/config.yml +22 -19
- data/{config → lib/generators/platform/templates/config}/platform/data/default_applications.yml +0 -0
- data/{config → lib/generators/platform/templates/config}/platform/data/default_categories.yml +0 -0
- data/{config → lib/generators/platform/templates/config}/platform/data/default_permissions.yml +0 -0
- data/{config → lib/generators/platform/templates/config}/platform/site/features.yml +0 -0
- data/lib/platform.rb +23 -0
- data/lib/platform/api/proxy/base.rb +5 -2
- data/lib/platform/cache.rb +1 -1
- data/lib/platform/config.rb +20 -3
- data/lib/platform/engine.rb +23 -0
- data/lib/platform/exception.rb +1 -1
- data/lib/platform/extensions/action_view_extension.rb +25 -0
- data/lib/platform/helper.rb +1 -1
- data/lib/platform/logger.rb +1 -1
- data/lib/platform/random_password_generator.rb +1 -1
- data/lib/platform/simple_string_permissions.rb +1 -1
- data/lib/platform/version.rb +24 -1
- data/lib/tasks/platform.rake +1 -1
- data/platform.gemspec +1 -1
- data/test/dummy/.pryrc +15 -0
- data/test/dummy/app/controllers/api/base_controller.rb +0 -1
- data/test/dummy/app/controllers/api/bookmarks_controller.rb +6 -1
- data/{app/controllers/platform/developer/resources_controller.rb → test/dummy/app/controllers/api/platform_controller.rb} +16 -2
- data/test/dummy/app/controllers/api/users_controller.rb +1 -0
- data/test/dummy/app/controllers/login_controller.rb +2 -1
- data/test/dummy/app/models/user.rb +8 -0
- data/test/dummy/app/views/layouts/_header.html.erb +1 -0
- data/test/dummy/app/views/layouts/blank.html.erb +24 -0
- data/test/dummy/app/views/layouts/mobile.html.erb +68 -0
- data/test/dummy/app/views/login/index.html.erb +1 -2
- data/test/dummy/app/views/login/register.html.erb +3 -3
- data/test/dummy/config/application.rb +1 -1
- data/test/dummy/config/platform/api/1/bookmark.yml +23 -3
- data/test/dummy/config/platform/api/1/platform.yml +55 -0
- data/test/dummy/config/platform/api/1/platform_application.yml +37 -0
- data/test/dummy/config/platform/api/1/platform_developer.yml +22 -0
- data/test/dummy/config/platform/api/1/user.yml +1 -1
- data/test/dummy/config/platform/config.yml +5 -4
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config/tr8n/config.yml +1 -1
- data/test/dummy/lib/platform/api/platform_application_proxy_0.rb +28 -0
- data/test/dummy/lib/platform/api/platform_developer_proxy_0.rb +19 -0
- metadata +72 -65
- data/app/assets/images/platform/help/login.png +0 -0
- data/app/assets/javascripts/platform/jsdk.js +0 -539
- data/app/controllers/platform/api/apps_controller.rb +0 -40
- data/app/views/platform/developer/resources/index.html.erb +0 -23
- data/test/dummy/config/platform/site/sample_apps.yml +0 -100
|
Binary file
|
|
@@ -1,539 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Platform JavaScript SDK
|
|
3
|
-
* Copyright 2011, Ian McDaniel, Platform Inc.
|
|
4
|
-
* For all api documentation:
|
|
5
|
-
* http://dev.geni.com
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
;(function(){
|
|
10
|
-
|
|
11
|
-
// The Platform namespace
|
|
12
|
-
var Platform = {
|
|
13
|
-
|
|
14
|
-
// current version
|
|
15
|
-
Version: '0.2.0',
|
|
16
|
-
|
|
17
|
-
_appid : null,
|
|
18
|
-
_status : null, // unknown, authorized or unauthorized
|
|
19
|
-
_logging : false,
|
|
20
|
-
_cookies : false,
|
|
21
|
-
_access_token :null,
|
|
22
|
-
_host : 'http://geni.com',
|
|
23
|
-
_url: {
|
|
24
|
-
api : '/api',
|
|
25
|
-
status : '/oauth/status',
|
|
26
|
-
connect : '/oauth/authorize',
|
|
27
|
-
disconnect: '/oauth/deauthorize',
|
|
28
|
-
logout : '/oauth/logout'
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
// creates a quick and dirty unique id for use in callbacks
|
|
32
|
-
uuid:function() {
|
|
33
|
-
return 'g' + (((1+Math.random())*0x10000)|0).toString(16).substring(1);
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
// log messages for debugging, off by default
|
|
37
|
-
log:function() {
|
|
38
|
-
if(this._logging) {
|
|
39
|
-
var args = Array.prototype.slice.call(arguments, 0) || [];
|
|
40
|
-
if (window.console) window.console.log.apply(window.console,args);
|
|
41
|
-
if (Platform.Event) Platform.Event.trigger.apply(Platform.Event,['log'].concat(args));
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
// Initialize the Platform SDK library
|
|
46
|
-
// The best place to put this code is right before the closing </body> tag
|
|
47
|
-
//
|
|
48
|
-
// Platform.init({
|
|
49
|
-
// appId : 'YOUR APP KEY', // app id or app key
|
|
50
|
-
// access_token : 'YOUR ACCESS TOKEN', // set the access token if you already have it
|
|
51
|
-
// host : 'http://sandbox.geni.com', // change host if needed
|
|
52
|
-
// cookies : true, // enable cookies to allow the server to access the session
|
|
53
|
-
// logging : true // enable log messages to help in debugging
|
|
54
|
-
// });
|
|
55
|
-
//
|
|
56
|
-
init:function(opts,cb) {
|
|
57
|
-
opts || (opts = {});
|
|
58
|
-
if(!opts.app_id) {
|
|
59
|
-
return Platform.log('Platform Javascript SDK requires an Application ID');
|
|
60
|
-
}
|
|
61
|
-
this._appid = opts.app_id;
|
|
62
|
-
|
|
63
|
-
// authorize app if we already have an access token
|
|
64
|
-
if(opts.access_token) {
|
|
65
|
-
this._access_token = opts.access_token;
|
|
66
|
-
this._status = "authorized";
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
this._logging = (window.location.toString().indexOf('geni_debug=1') > 0) || opts.logging || this._logging;
|
|
70
|
-
this._cookies = opts.cookies || this._cookies;
|
|
71
|
-
this._host = opts.host || this._host;
|
|
72
|
-
return this;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// Helper methods to make things easier
|
|
79
|
-
Platform.Util = {
|
|
80
|
-
|
|
81
|
-
// Extend an object with all the properties of the passed object
|
|
82
|
-
extend:function extend(destination, source) {
|
|
83
|
-
for (var property in source)
|
|
84
|
-
destination[property] = source[property];
|
|
85
|
-
return destination;
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
// Create a URL-encoded query string from an object
|
|
89
|
-
encodeQueryString:function(obj,prefix){
|
|
90
|
-
var str = [];
|
|
91
|
-
for(var p in obj) str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
|
|
92
|
-
return str.join("&");
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
// Parses a query string and returns an object composed of key/value pairs
|
|
96
|
-
decodeQueryString:function(qs){
|
|
97
|
-
var
|
|
98
|
-
obj = {},
|
|
99
|
-
segments = qs.split('&'),
|
|
100
|
-
kv;
|
|
101
|
-
for (var i=0; i<segments.length; i++) {
|
|
102
|
-
kv = segments[i].split('=', 2);
|
|
103
|
-
if (kv && kv[0]) {
|
|
104
|
-
obj[decodeURIComponent(kv[0])] = decodeURIComponent(kv[1]);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return obj;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
// Platform custom events. You may 'bind' or 'unbind' a callback function to an event;
|
|
114
|
-
// 'triggering'-ing an event fires all callbacks in succession.
|
|
115
|
-
//
|
|
116
|
-
// function showStatus(status){
|
|
117
|
-
// alert(status)
|
|
118
|
-
// }
|
|
119
|
-
// Platform.Event.bind('auth:statusChange', showStatus);
|
|
120
|
-
// Platform.Event.trigger('auth:statuschange','authorized');
|
|
121
|
-
// Platform.Event.unbind('auth:statusChange', showStatus);
|
|
122
|
-
//
|
|
123
|
-
Platform.Event = {
|
|
124
|
-
|
|
125
|
-
_events:{},
|
|
126
|
-
|
|
127
|
-
// Bind an event, specified by a string name, 'event', to a callback, 'cb', function.
|
|
128
|
-
bind: function(event, cb){
|
|
129
|
-
this._events[event] = this._events[event] || [];
|
|
130
|
-
this._events[event].push(cb);
|
|
131
|
-
},
|
|
132
|
-
|
|
133
|
-
// Remove one or many callbacks. If callback is null, all
|
|
134
|
-
// callbacks for the event wil be removed.
|
|
135
|
-
unbind: function(event, cb){
|
|
136
|
-
if(event in this._events === false) return;
|
|
137
|
-
this._events[event].splice(this._events[event].indexOf(cb), 1);
|
|
138
|
-
if(!cb) delete this._events[event];
|
|
139
|
-
},
|
|
140
|
-
|
|
141
|
-
// Trigger an event, firing all bound callbacks. Callbacks are passed the
|
|
142
|
-
// same arguments as 'trigger' is, apart from the event name.
|
|
143
|
-
trigger: function(event){
|
|
144
|
-
if( event in this._events === false ) return;
|
|
145
|
-
for(var i = 0; i < this._events[event].length; i++){
|
|
146
|
-
this._events[event][i].apply(this, Array.prototype.slice.call(arguments, 1))
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// APIs for making requests against Platform's Server.
|
|
153
|
-
// All request types take the same arguments; url, parameters and a callback.
|
|
154
|
-
//
|
|
155
|
-
|
|
156
|
-
Platform.Request = {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
callbacks : {},
|
|
160
|
-
|
|
161
|
-
// Standard JSONP request
|
|
162
|
-
//
|
|
163
|
-
// Platform.Request.jsonp(url[, paramerters, callback])
|
|
164
|
-
//
|
|
165
|
-
jsonp:function(url,params,cb) {
|
|
166
|
-
var
|
|
167
|
-
self = this,
|
|
168
|
-
script = document.createElement('script'),
|
|
169
|
-
uuid = Platform.uuid(),
|
|
170
|
-
params = Platform.Util.extend((params||{}),{callback:'Platform.Request.callbacks.' + uuid}),
|
|
171
|
-
url = url + (url.indexOf('?')>-1 ? '&' : '?') + Platform.Util.encodeQueryString(params);
|
|
172
|
-
|
|
173
|
-
this.callbacks[uuid] = function(data) {
|
|
174
|
-
if(data.error) {
|
|
175
|
-
Platform.log([data.error,data.error_description].join(' : '));
|
|
176
|
-
}
|
|
177
|
-
if(cb) cb(data);
|
|
178
|
-
delete self.callbacks[uuid];
|
|
179
|
-
}
|
|
180
|
-
script.src = url;
|
|
181
|
-
document.getElementsByTagName('head')[0].appendChild(script);
|
|
182
|
-
},
|
|
183
|
-
|
|
184
|
-
// Same as a jsonp request but with an access token for oauth authentication
|
|
185
|
-
//
|
|
186
|
-
// Platform.Request.oauth(url[, paramerters, callback])
|
|
187
|
-
//
|
|
188
|
-
oauth:function(url,params,cb) {
|
|
189
|
-
params || (params = {});
|
|
190
|
-
if(Platform._access_token) {
|
|
191
|
-
Platform.Util.extend(params,{access_token:Platform._access_token});
|
|
192
|
-
} else {
|
|
193
|
-
Platform.log('Platform.Request.oauth() called without an access token.');
|
|
194
|
-
}
|
|
195
|
-
this.jsonp(url,params,cb);
|
|
196
|
-
},
|
|
197
|
-
|
|
198
|
-
// Opens a popup window with the given url and places it at the
|
|
199
|
-
// center of the current window. Used for app authentication. Should only
|
|
200
|
-
// be called on a user event like a click as many browsers block popups
|
|
201
|
-
// if not initiated by a user.
|
|
202
|
-
//
|
|
203
|
-
// Platform.Request.popup(url[, paramerters, callback])
|
|
204
|
-
//
|
|
205
|
-
popup: function(url,params,cb) {
|
|
206
|
-
this.registerXDHandler();
|
|
207
|
-
// figure out where the center is
|
|
208
|
-
var
|
|
209
|
-
screenX = typeof window.screenX != 'undefined' ? window.screenX : window.screenLeft,
|
|
210
|
-
screenY = typeof window.screenY != 'undefined' ? window.screenY : window.screenTop,
|
|
211
|
-
outerWidth = typeof window.outerWidth != 'undefined' ? window.outerWidth : document.documentElement.clientWidth,
|
|
212
|
-
outerHeight = typeof window.outerHeight != 'undefined' ? window.outerHeight : (document.documentElement.clientHeight - 22),
|
|
213
|
-
width = params.width || 600,
|
|
214
|
-
height = params.height || 400,
|
|
215
|
-
left = parseInt(screenX + ((outerWidth - width) / 2), 10),
|
|
216
|
-
top = parseInt(screenY + ((outerHeight - height) / 2.5), 10),
|
|
217
|
-
features = (
|
|
218
|
-
'width=' + width +
|
|
219
|
-
',height=' + height +
|
|
220
|
-
',left=' + left +
|
|
221
|
-
',top=' + top
|
|
222
|
-
);
|
|
223
|
-
var
|
|
224
|
-
uuid = Platform.uuid(),
|
|
225
|
-
params = Platform.Util.extend((params||{}),{
|
|
226
|
-
callback : uuid,
|
|
227
|
-
display : 'popup',
|
|
228
|
-
origin : this._origin()
|
|
229
|
-
}),
|
|
230
|
-
url = url + (url.indexOf('?')>-1 ? '&' : '?') + Platform.Util.encodeQueryString(params);
|
|
231
|
-
var win = window.open(url,uuid,features);
|
|
232
|
-
this.callbacks[uuid] = function(data) {
|
|
233
|
-
if(cb) cb(data,win);
|
|
234
|
-
delete Platform.Request.callbacks[uuid];
|
|
235
|
-
}
|
|
236
|
-
},
|
|
237
|
-
|
|
238
|
-
// Creates and inserts a hidden iframe with the given url then removes
|
|
239
|
-
// the iframe from the DOM
|
|
240
|
-
//
|
|
241
|
-
// Platform.Request.hidden(url[, paramerters, callback])
|
|
242
|
-
//
|
|
243
|
-
hidden:function(url,params,cb) {
|
|
244
|
-
this.registerXDHandler();
|
|
245
|
-
var
|
|
246
|
-
iframe = document.createElement('iframe'),
|
|
247
|
-
uuid = Platform.uuid(),
|
|
248
|
-
params = Platform.Util.extend((params||{}),{
|
|
249
|
-
callback : uuid,
|
|
250
|
-
display : 'hidden',
|
|
251
|
-
origin : this._origin()
|
|
252
|
-
}),
|
|
253
|
-
url = url + (url.indexOf('?')>-1 ? '&' : '?') + Platform.Util.encodeQueryString(params);
|
|
254
|
-
|
|
255
|
-
iframe.style.display = "none";
|
|
256
|
-
this.callbacks[uuid] = function(data) {
|
|
257
|
-
if(cb) cb(data);
|
|
258
|
-
delete Platform.Request.callbacks[uuid];
|
|
259
|
-
iframe.parentNode.removeChild(iframe);
|
|
260
|
-
}
|
|
261
|
-
iframe.src = url;
|
|
262
|
-
document.getElementsByTagName('body')[0].appendChild(iframe);
|
|
263
|
-
},
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
// Make sure we're listening to the onMessage event
|
|
267
|
-
registerXDHandler:function() {
|
|
268
|
-
if(this.xd_registered) return;
|
|
269
|
-
var
|
|
270
|
-
self=Platform.Request,
|
|
271
|
-
fn = function(e){Platform.Request.onMessage(e)}
|
|
272
|
-
window.addEventListener
|
|
273
|
-
? window.addEventListener('message', fn, false)
|
|
274
|
-
: window.attachEvent('onmessage', fn);
|
|
275
|
-
this.xd_registered = true;
|
|
276
|
-
},
|
|
277
|
-
|
|
278
|
-
// handles message events sent via postMessage, and fires the appropriate callback
|
|
279
|
-
onMessage:function(e) {
|
|
280
|
-
var data = {};
|
|
281
|
-
if (e.data && typeof e.data == 'string') {
|
|
282
|
-
data = Platform.Util.decodeQueryString(e.data);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
if(data.error) {
|
|
286
|
-
Platform.log(data.error,data.error_description);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
if(data.callback) {
|
|
290
|
-
var cb = this.callbacks[data.callback];
|
|
291
|
-
if(cb) {
|
|
292
|
-
cb(data);
|
|
293
|
-
delete this.callbacks[data.callback];
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
},
|
|
297
|
-
|
|
298
|
-
// get the origin of the page
|
|
299
|
-
_origin: function() {
|
|
300
|
-
return (window.location.protocol + '//' + window.location.host)
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
// Authentication
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
Platform.Auth = {
|
|
314
|
-
|
|
315
|
-
// Returns the current authentication status of the user from the server, and provides
|
|
316
|
-
// an access token if the user is logged into Platform and has authorized the app.
|
|
317
|
-
//
|
|
318
|
-
// Platform.Auth.getStatus(function(response){
|
|
319
|
-
// if(response.status == 'authorized') {
|
|
320
|
-
// // User is logged in and has authorized the app
|
|
321
|
-
// }
|
|
322
|
-
// })
|
|
323
|
-
//
|
|
324
|
-
// The status returned in the response will be either 'authorized', user is logged in
|
|
325
|
-
// and has authorized the app, 'unauthorized', user is logged in but has not authorized
|
|
326
|
-
// the app and 'unknown', user is not logged in.
|
|
327
|
-
|
|
328
|
-
getStatus:function(cb) {
|
|
329
|
-
if(!Platform._appid) {
|
|
330
|
-
return Platform.log('Platform.Auth.getStatus() called without an app id');
|
|
331
|
-
}
|
|
332
|
-
var url = Platform._host + Platform._url.status;
|
|
333
|
-
Platform.Request.hidden(url,{client_id:Platform._appid},function(data){
|
|
334
|
-
Platform.Auth.setStatus(data);
|
|
335
|
-
if(cb) cb(data);
|
|
336
|
-
});
|
|
337
|
-
},
|
|
338
|
-
|
|
339
|
-
// Launches the authorization window to connect to Platform and if successful returns an
|
|
340
|
-
// access token.
|
|
341
|
-
//
|
|
342
|
-
// Platform.Auth.connect(function(response){
|
|
343
|
-
// if(response.status == 'authorized') {
|
|
344
|
-
// // User is logged in and has authorized the app
|
|
345
|
-
// }
|
|
346
|
-
// })
|
|
347
|
-
//
|
|
348
|
-
|
|
349
|
-
connect:function(cb) {
|
|
350
|
-
if(!Platform._appid) {
|
|
351
|
-
return Platform.log('Platform.Auth.connect() called without an app id.');
|
|
352
|
-
}
|
|
353
|
-
if(!Platform._access_token) {
|
|
354
|
-
var url = Platform._host + Platform._url.connect,
|
|
355
|
-
params = {
|
|
356
|
-
response_type : 'token',
|
|
357
|
-
client_id : Platform._appid
|
|
358
|
-
};
|
|
359
|
-
Platform.Request.popup(url,params,function(data,win){
|
|
360
|
-
Platform.Auth.setStatus(data);
|
|
361
|
-
if(win) win.close();
|
|
362
|
-
if(cb) cb(data);
|
|
363
|
-
});
|
|
364
|
-
} else {
|
|
365
|
-
Platform.log('Platform.Auth.connect() called when user is already connected.');
|
|
366
|
-
if(cb) cb();
|
|
367
|
-
}
|
|
368
|
-
},
|
|
369
|
-
|
|
370
|
-
// Revokes your apps authorization access
|
|
371
|
-
//
|
|
372
|
-
// Platform.Auth.disconnect(function(){
|
|
373
|
-
// // App authorization has been revoked
|
|
374
|
-
// })
|
|
375
|
-
//
|
|
376
|
-
disconnect:function(cb) {
|
|
377
|
-
if(!Platform._appid) {
|
|
378
|
-
return Platform.log('Platform.Auth.disconnect() called without an app id.');
|
|
379
|
-
}
|
|
380
|
-
var url = Platform._host + Platform._url.disconnect;
|
|
381
|
-
Platform.Request.jsonp(url,{client_id:Platform._appid},function(r){
|
|
382
|
-
Platform.Auth.setStatus(null);
|
|
383
|
-
if(cb) cb(r);
|
|
384
|
-
})
|
|
385
|
-
},
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
// Logs the user out of Platform
|
|
389
|
-
//
|
|
390
|
-
// Platform.Auth.logout(function(){
|
|
391
|
-
// // App authorization has been revoked
|
|
392
|
-
// })
|
|
393
|
-
//
|
|
394
|
-
logout:function(cb) {
|
|
395
|
-
if(!Platform._appid) {
|
|
396
|
-
return Platform.log('Platform.Auth.logout called() without an app id.');
|
|
397
|
-
}
|
|
398
|
-
var url = Platform._host + Platform._url.logout;
|
|
399
|
-
Platform.Request.jsonp(url,{client_id:Platform._appid},function(r){
|
|
400
|
-
Platform.Auth.setStatus(null);
|
|
401
|
-
if(cb) cb(r);
|
|
402
|
-
});
|
|
403
|
-
},
|
|
404
|
-
|
|
405
|
-
// Determines the correct status ('unknown', 'unauthorized' or 'authorized') and
|
|
406
|
-
// sets the access token if authorization is approved.
|
|
407
|
-
setStatus:function(data) {
|
|
408
|
-
data || (data = {});
|
|
409
|
-
if(data.access_token) {
|
|
410
|
-
Platform._access_token = data.access_token;
|
|
411
|
-
Platform.Cookie('geni'+Platform._appid, Platform._access_token);
|
|
412
|
-
data.status = "authorized";
|
|
413
|
-
} else {
|
|
414
|
-
Platform._access_token = null;
|
|
415
|
-
Platform.Cookie('geni'+Platform._appid, null);
|
|
416
|
-
data.status = data.status || "unknown";
|
|
417
|
-
}
|
|
418
|
-
if(Platform._status != data.status) {
|
|
419
|
-
Platform.Event.trigger('auth:statusChange',data.status);
|
|
420
|
-
}
|
|
421
|
-
return (Platform._status = data.status);
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
// Make API calls to Platform's Servers
|
|
429
|
-
//
|
|
430
|
-
// The API strives to provide consistent access to Platform’s data. IDs are embedded before
|
|
431
|
-
// the action so the urls read more like a sentence. To get all profile 1’s tree matches
|
|
432
|
-
// you would request
|
|
433
|
-
//
|
|
434
|
-
// Platform.api('/profile-1/tree-matches',function(data){
|
|
435
|
-
// // returns a list of tree matches for profile with id 1
|
|
436
|
-
// })
|
|
437
|
-
//
|
|
438
|
-
// Omitting the ids in urls implies the action should be applied to the current user’s data.
|
|
439
|
-
// For example,
|
|
440
|
-
//
|
|
441
|
-
// Platform.api('/profile',function(data) {
|
|
442
|
-
// // returns current user's profile data
|
|
443
|
-
// })
|
|
444
|
-
//
|
|
445
|
-
// will return the profile information for the logged in user. Parameters can optionally be
|
|
446
|
-
// passed in as the second argument:
|
|
447
|
-
//
|
|
448
|
-
// Platform.api('/profile-101',{fields:'first_name,last_name'},function(data) {
|
|
449
|
-
// // only returns first and last name of profile with id 101
|
|
450
|
-
// })
|
|
451
|
-
//
|
|
452
|
-
// Visit htp://dev.geni.com for more detailed documentation.
|
|
453
|
-
//
|
|
454
|
-
Platform.Api = {
|
|
455
|
-
|
|
456
|
-
// Makes an oauth jsonp request to Platform's servers for data.
|
|
457
|
-
//
|
|
458
|
-
// Platform.Api.get('/user',function(data){
|
|
459
|
-
// // do something awesome with Platform data
|
|
460
|
-
// })
|
|
461
|
-
//
|
|
462
|
-
get:function(path,params,cb) {
|
|
463
|
-
if(typeof params == 'function') {
|
|
464
|
-
cb = params;
|
|
465
|
-
params = {};
|
|
466
|
-
}
|
|
467
|
-
params || (params = {});
|
|
468
|
-
if(params.method) {
|
|
469
|
-
params['_method'] = params.method;
|
|
470
|
-
delete params.method;
|
|
471
|
-
}
|
|
472
|
-
path = Platform._host + Platform._url.api + "/" + path.replace(/^\//,'');
|
|
473
|
-
|
|
474
|
-
Platform.Request.oauth(path, params, cb);
|
|
475
|
-
},
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
// Makes an oauth jsonp request to Platform's servers to save data. All jsonp
|
|
479
|
-
// requests use a GET method but we can get around this by adding a
|
|
480
|
-
// _method=post parameter to our request.
|
|
481
|
-
//
|
|
482
|
-
// Platform.Api.post(function(data){
|
|
483
|
-
// // Add awesome data to Platform
|
|
484
|
-
// })
|
|
485
|
-
//
|
|
486
|
-
post:function(path,params,cb) {
|
|
487
|
-
params = Platform.Util.extend({'_method':'post'},params || {});
|
|
488
|
-
this.get(path,params,cb);
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
// Cookies
|
|
497
|
-
// Helper function to get/set browser cookies so an application's server can have access
|
|
498
|
-
// to the access token.
|
|
499
|
-
//
|
|
500
|
-
Platform.Cookie = function (key, value, options) {
|
|
501
|
-
if(!Platform._cookies) return;
|
|
502
|
-
if (arguments.length > 1 && String(value) !== "[object Object]") {
|
|
503
|
-
options = Platform.Util.extend({}, options);
|
|
504
|
-
if (value === null || value === undefined) options.expires = -1;
|
|
505
|
-
if (typeof options.expires === 'number') {
|
|
506
|
-
var days = options.expires, t = options.expires = new Date();
|
|
507
|
-
t.setDate(t.getDate() + days);
|
|
508
|
-
}
|
|
509
|
-
value = String(value);
|
|
510
|
-
return (document.cookie = [
|
|
511
|
-
encodeURIComponent(key), '=',
|
|
512
|
-
options.raw ? value : encodeURIComponent(value),
|
|
513
|
-
options.expires ? '; expires=' + options.expires.toUTCString() : '',
|
|
514
|
-
options.path ? '; path=' + options.path : '',
|
|
515
|
-
options.domain ? '; domain=' + options.domain : '',
|
|
516
|
-
options.secure ? '; secure' : ''
|
|
517
|
-
].join(''));
|
|
518
|
-
}
|
|
519
|
-
options = value || {};
|
|
520
|
-
var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
|
|
521
|
-
return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
// shortcuts to make things easier
|
|
528
|
-
|
|
529
|
-
window.Platform = window.$g = Platform.Util.extend(Platform,{
|
|
530
|
-
getStatus : Platform.Auth.getStatus,
|
|
531
|
-
connect : Platform.Auth.connect,
|
|
532
|
-
disconnect : Platform.Auth.disconnect,
|
|
533
|
-
logout : Platform.Auth.logout,
|
|
534
|
-
api : Platform.Api.get //most api calls are gets
|
|
535
|
-
});
|
|
536
|
-
|
|
537
|
-
}).call(this);
|
|
538
|
-
|
|
539
|
-
|