platform 3.1.1 → 3.1.2
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,77 @@
|
|
1
|
+
<%= render :partial => "/platform/common/header" %>
|
2
|
+
|
3
|
+
<style>
|
4
|
+
.recent_apps_table {
|
5
|
+
width:100%;
|
6
|
+
}
|
7
|
+
|
8
|
+
.recent_apps_table tr {
|
9
|
+
padding:5px;
|
10
|
+
border-top:#ccc 1px solid;border-bottom:#ccc 1px solid;
|
11
|
+
}
|
12
|
+
|
13
|
+
.recent_apps_table th {
|
14
|
+
padding:5px;
|
15
|
+
text-align:left;
|
16
|
+
}
|
17
|
+
|
18
|
+
.recent_apps_table td {
|
19
|
+
padding:5px;
|
20
|
+
}
|
21
|
+
|
22
|
+
.app_row {
|
23
|
+
background-color:white;
|
24
|
+
}
|
25
|
+
|
26
|
+
.app_row:hover {
|
27
|
+
background-color:#ffe;
|
28
|
+
}
|
29
|
+
|
30
|
+
</style>
|
31
|
+
<div class="module page_title lengthy">
|
32
|
+
<div class="inner">
|
33
|
+
<div class="section_title">
|
34
|
+
<%=tr("My Applications") %>
|
35
|
+
</div>
|
36
|
+
<% if @app_users.any? %>
|
37
|
+
<p><%=tr("You have authorized these apps to interact with your {site} account:", "", :site => Platform::Config.site_title)%></p>
|
38
|
+
<table class="recent_apps_table">
|
39
|
+
<tr style="background-color:#eee;">
|
40
|
+
<th></th>
|
41
|
+
<th><%=tr("Application Name") %></th>
|
42
|
+
<th><%=tr("Last Accessed At") %></th>
|
43
|
+
<th></th>
|
44
|
+
</tr>
|
45
|
+
<% @app_users.each do |au| %>
|
46
|
+
<tr class="app_row">
|
47
|
+
<td style="text-align:left; padding-left:3px; width:30px;"><%=image_tag(au.application.icon_url)%></td>
|
48
|
+
<td><%=link_to(au.application.name, :action => :view, :id => au.application.id)%></td>
|
49
|
+
<td><%=platform_when_string_tag(au.updated_at)%></td>
|
50
|
+
<td style="text-align:right; padding-right:3px;">
|
51
|
+
<%=link_to_function(image_tag("platform/close.gif"), "removeApplication('#{au.id}')")%></td>
|
52
|
+
</tr>
|
53
|
+
<% end %>
|
54
|
+
</table>
|
55
|
+
<% else %>
|
56
|
+
<p style="padding-top:10px;padding-bottom:10px;">
|
57
|
+
<%=tr("You have not authorized any applications.")%>
|
58
|
+
<%=tr("Visit [link: Application Directory] to get started.", "", :link => {:href => "/platform/apps"})%>
|
59
|
+
</p>
|
60
|
+
<% end %>
|
61
|
+
</div>
|
62
|
+
</div>
|
63
|
+
|
64
|
+
<%=form_tag({:action => :remove}, {:id => :app_form}) do %>
|
65
|
+
<%=hidden_field_tag(:app_user_id, '')%>
|
66
|
+
<% end %>
|
67
|
+
|
68
|
+
<script>
|
69
|
+
function removeApplication(app_user_id) {
|
70
|
+
if (!confirm("<%=trl("If you remove this application, it will no longer have access to your data and be removed from your Applications Page.")%>"))
|
71
|
+
return;
|
72
|
+
|
73
|
+
Platform.element('app_user_id').value = app_user_id;
|
74
|
+
Platform.element('app_form').submit();
|
75
|
+
}
|
76
|
+
</script>
|
77
|
+
<%= render :partial => "/platform/common/footer" %>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
<div class="section_title">
|
8
8
|
<div style="float:right; font-size:12px; padding-top:5px;">
|
9
|
-
<%=link_to(tr("edit developer information", "Developer preferences link"), :controller => "/platform/developer/
|
9
|
+
<%=link_to(tr("edit developer information", "Developer preferences link"), :controller => "/platform/developer/info", :action => :index)%>
|
10
10
|
|
|
11
11
|
<%=link_to(tr("dashboard preferences", "Dashboard preferences link"), :controller => "/platform/developer/dashboard", :action => :settings)%>
|
12
12
|
</div>
|
@@ -79,7 +79,7 @@
|
|
79
79
|
<div class="section_link <%="selected" if @api[:path]==api[:path] %>" style="vertical-align:middle;">
|
80
80
|
<% expanded = (path_parts.first == api[:path]) %>
|
81
81
|
<%=raw(platform_toggler_tag("#{api_key}_api_actions", "", expanded, {:style => "text-align:center; vertical-align:top; width:10px;"}))%>
|
82
|
-
<%=link_to(api_key.titleize, {:action => :api, :path => api[:path], :version => @version})%>
|
82
|
+
<%=link_to(api[:label] || api_key.titleize, {:action => :api, :path => api[:path], :version => @version})%>
|
83
83
|
<%=raw(platform_documentation_api_decorators_tag(api)) %>
|
84
84
|
</div>
|
85
85
|
<% if api[:actions] %>
|
@@ -7,6 +7,13 @@
|
|
7
7
|
<%=tr("Client side authentication and authorization flow is very similar to the server side flow.") %>
|
8
8
|
<%=tr("The difference is in the parameters passed to the server and in the response fields that you get back.") %>
|
9
9
|
</p>
|
10
|
+
|
11
|
+
<h2><%=tr("{site_title} JavaScript Client SDK", "", :site_title => Platform::Config.site_title)%></h2>
|
12
|
+
<p>
|
13
|
+
<%=tr("{site_title} Platform comes with a [link: full featured JavaScript library] that allows you to build dynamic web applications in the browser with {site_title}'s data.", "", :site_title => Platform::Config.site_title, :link => {:href => "/platform/developer/help/sdk_js"})%>
|
14
|
+
<%=tr("It supports authentication, autherization and API calls to get the site data.")%>
|
15
|
+
</p>
|
16
|
+
|
10
17
|
<h2><%=tr("Authentication & Authorization") %></h2>
|
11
18
|
<p>
|
12
19
|
<%=tr("To enter the authentication/authorization client-side flow, you must pass the following parameters to the authorization URL:")%>
|
@@ -197,19 +204,19 @@
|
|
197
204
|
<h2><%=tr("Cross Domain API Calls")%></h2>
|
198
205
|
<p>
|
199
206
|
<%=tr("{site_title} Platform supports cross-domain API calls using [link: JSONP] framework.", "", :site_title => Platform::Config.site_title, :link => ["http://en.wikipedia.org/wiki/JSONP"]) %>
|
200
|
-
<%=tr("Below is a simple example for
|
207
|
+
<%=tr("Below is a simple example for Platform JSONP API call.")%>
|
201
208
|
<%=tr("You must provide a valid access token in order to make an JSONP API call.")%>
|
202
209
|
</p>
|
203
210
|
<h3><%=tr("Example")%></h3>
|
204
211
|
<pre class="code_snippet">
|
205
|
-
var
|
212
|
+
var Platform = {callbacks:{}, client_id:"YOUR_APP_KEY", access_token:""};
|
206
213
|
|
207
214
|
function jsonp(url, params, callback) {
|
208
215
|
var script = document.createElement('script');
|
209
216
|
var g_uuid = 'g' + (((1+Math.random())*0x10000)|0).toString(16).substring(1);
|
210
217
|
|
211
218
|
params = params || {};
|
212
|
-
params['callback'] = '
|
219
|
+
params['callback'] = 'Platform.callbacks.' + g_uuid;
|
213
220
|
|
214
221
|
var query = [];
|
215
222
|
for(var p in params) str.push(encodeURIComponent(p) + "=" + encodeURIComponent(params[p]));
|
@@ -217,9 +224,9 @@ function jsonp(url, params, callback) {
|
|
217
224
|
|
218
225
|
url = url + (url.indexOf('?')>-1 ? '&' : '?') + query;
|
219
226
|
|
220
|
-
|
227
|
+
Platform.callbacks[g_uuid] = function(data) {
|
221
228
|
if(callback) callback(data);
|
222
|
-
delete
|
229
|
+
delete Platform.callbacks[g_uuid];
|
223
230
|
}
|
224
231
|
script.src = url;
|
225
232
|
document.getElementsByTagName('head')[0].appendChild(script);
|
@@ -227,7 +234,7 @@ function jsonp(url, params, callback) {
|
|
227
234
|
|
228
235
|
|
229
236
|
// Parse access token from the URL if it is available
|
230
|
-
if (
|
237
|
+
if (Platform.access_token == "") {
|
231
238
|
var params = {};
|
232
239
|
|
233
240
|
var anchor = window.location.href.split("#");
|
@@ -241,24 +248,19 @@ if (Geni.access_token == "") {
|
|
241
248
|
|
242
249
|
// Add code to store/retrieve access token from a cookie
|
243
250
|
|
244
|
-
|
251
|
+
Platform.access_token = params["access_token"];
|
245
252
|
}
|
246
253
|
|
247
|
-
if (
|
248
|
-
window.location = "https://
|
254
|
+
if (Platform.access_token == "") {
|
255
|
+
window.location = "https://localhost:3000/oauth/authorize?client_id" + Platform.client_id + "&redirect_uri="
|
249
256
|
+ window.location.href + "&response_type=token";
|
250
257
|
} else {
|
251
258
|
// Get profile data
|
252
|
-
jsonp("/profile", {access_token:
|
259
|
+
jsonp("/profile", {access_token:Platform.access_token}, function(data) {
|
253
260
|
alert("Hello " + data["name"]);
|
254
261
|
})
|
255
262
|
}
|
256
263
|
|
257
264
|
</pre>
|
258
|
-
<h3><%=tr("{site_title} JavaScript Client SDK", "", :site_title => Platform::Config.site_title)%></h3>
|
259
|
-
<p>
|
260
|
-
<%=tr("{site_title} Platform comes with a [link: full featured JavaScript library] that allows you to build dynamic web applications in the browser with {site_title}'s data.", "", :site_title => Platform::Config.site_title, :link => ["/platform/developer/help/sdk_js"])%>
|
261
|
-
<%=tr("It supports authentication, autherization and API calls to get the site data.")%>
|
262
|
-
</p>
|
263
265
|
</div>
|
264
266
|
<%= render :partial => "footer" %>
|
@@ -159,7 +159,7 @@
|
|
159
159
|
<h2><%=tr("Authorization Flow") %></h2>
|
160
160
|
<p>
|
161
161
|
<%=tr("There are two ways you could authorize your embedded application.")%>
|
162
|
-
<%=tr("If you chose to let
|
162
|
+
<%=tr("If you chose to let Platform handle authorization then we will check if the user has authorized your application, and if not, we will present the authorization screen.")%>
|
163
163
|
<%=tr("Once user has authorized your app, we will pass you a valid access token as a parameter to your apps canvas URL.")%>
|
164
164
|
<%=tr("Alternatively, you can take the userto the authorization flow yourself, by redirecting the iframce to the authorization URL.")%>
|
165
165
|
</p>
|
@@ -5,9 +5,14 @@
|
|
5
5
|
<div class="documentation_section">
|
6
6
|
<p>
|
7
7
|
<%=tr("Mobile authentication/authorization flow is very similar to the client-side flow, but it has a slightly different mechanism for handling the response data.") %>
|
8
|
-
<%=tr("This document provides details no how to integrate
|
8
|
+
<%=tr("This document provides details no how to integrate Platform into an iPhone application.") %>
|
9
9
|
<%=tr("Android and other mobile devices will work in a similar fashion.") %>
|
10
10
|
</p>
|
11
|
+
<h2><%=tr("Platform iOS Client SDK")%></h2>
|
12
|
+
<p>
|
13
|
+
<%=tr("{site_title} comes with a [link: full featured iOS library] that allows you to build dynamic iOS applications using the site data.", "", :site_title => Platform::Config.site_title, :link => {:href => "/platform/developer/help/ios_sdk"})%>
|
14
|
+
<%=tr("It supports authentication, autherization and API calls to get the site data.")%>
|
15
|
+
</p>
|
11
16
|
<h2><%=tr("Authentication & Authorization") %></h2>
|
12
17
|
<p>
|
13
18
|
<%=tr("To enter the authentication/authorization mobile flow, launch a browser from your mobile application and pass the following parameters to the authorization url:") %>
|
@@ -118,7 +123,7 @@
|
|
118
123
|
<string></string>
|
119
124
|
<key>CFBundleURLSchemes</key>
|
120
125
|
<array>
|
121
|
-
<string>YOUR_APP_ID</string>
|
126
|
+
<string>app[YOUR_APP_ID]</string>
|
122
127
|
</array>
|
123
128
|
</dict>
|
124
129
|
</array>
|
@@ -131,14 +136,14 @@
|
|
131
136
|
</p>
|
132
137
|
<h3><%=tr("Example")%></h3>
|
133
138
|
<pre class="code_snippet">
|
134
|
-
NSString *
|
139
|
+
NSString *platformOauthBaseURL = @"https://<%=Platform::Config.site_base_url %>/platform/oauth/authorize";
|
135
140
|
|
136
141
|
NSString *yourAppURL = [NSString stringWithFormat: @"%@/authorize", YOUR_APP_ID];
|
137
142
|
|
138
|
-
NSString *
|
139
|
-
|
143
|
+
NSString *platformOauthURL = [NSString stringWithFormat:@"%@?client_id=%@&redirect_uri=%@&response_type=token&display=mobile",
|
144
|
+
platformOauthBaseURL, YOUR_APP_ID, yourAppURL];
|
140
145
|
|
141
|
-
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:
|
146
|
+
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:platformOauthURL]];
|
142
147
|
</pre>
|
143
148
|
<p>
|
144
149
|
<%=tr("If the user is already logged in, we validate the login cookie that we have stored on the user's browser and authenticate the user.") %><%=tr("If the user is not logged in, they are prompted to enter their credentials:") %>
|
@@ -160,7 +165,7 @@ NSString *geniOauthURL = [NSString stringWithFormat:@"%@?client_id=%@&redirect_u
|
|
160
165
|
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *) url {
|
161
166
|
NSLog(@"Did come back from other application");
|
162
167
|
|
163
|
-
// If the URL's structure doesn't match the structure used for
|
168
|
+
// If the URL's structure doesn't match the structure used for Platform authorization, abort.
|
164
169
|
if (![[url absoluteString] hasPrefix:[NSString stringWithFormat:@"%@://authorize", YOUR_APP_ID]]) {
|
165
170
|
return NO;
|
166
171
|
}
|
@@ -283,10 +288,5 @@ NSString *geniOauthURL = [NSString stringWithFormat:@"%@?client_id=%@&redirect_u
|
|
283
288
|
<div class="code_snippet">
|
284
289
|
YOUR_APP_ID://authorize?access_token=ACCESS_TOKEN_GENERATED_BY_SERVER&expires_in=SECONDS_UNTIL_IT_IS_EXPIRED
|
285
290
|
</div>
|
286
|
-
<h3><%=tr("Geni iOS Client SDK")%></h3>
|
287
|
-
<p>
|
288
|
-
<%=tr("{site_title} comes with a [link: full featured iOS library] that allows you to build dynamic iOS applications using the site data.", "", :site_title => Platform::Config.site_title, :link => ["/platform/developer/help/ios_sdk"])%>
|
289
|
-
<%=tr("It supports authentication, autherization and API calls to get the site data.")%>
|
290
|
-
</p>
|
291
291
|
</div>
|
292
292
|
<%= render :partial => "footer" %>
|
@@ -438,21 +438,21 @@
|
|
438
438
|
if (empty($access_code)) {
|
439
439
|
$_SESSION['state'] = md5(uniqid(rand(), TRUE)); // CSRF protection
|
440
440
|
|
441
|
-
$
|
441
|
+
$platform_oauth_url = "http://localhost:3000/dialog/oauth?client_id=" . $app_id
|
442
442
|
. "&redirect_uri=" . urlencode($my_url) . "&state=" . $_SESSION['state'];
|
443
443
|
|
444
|
-
echo("<script> top.location.href='" . $
|
444
|
+
echo("<script> top.location.href='" . $platform_oauth_url . "'</script>");
|
445
445
|
}
|
446
446
|
|
447
447
|
if ($_REQUEST['state'] == $_SESSION['state']) {
|
448
|
-
$token_url = "https://
|
448
|
+
$token_url = "https://localhost:3000/oauth/request_token?client_id=" . $app_id . "&client_secret=" . $app_secret
|
449
449
|
. "&redirect_uri=" . urlencode($my_url) . "&code=" . $access_code;
|
450
450
|
|
451
451
|
$params = json_decode(file_get_contents($token_url), true);
|
452
452
|
|
453
|
-
$
|
453
|
+
$platform_api_url = "https://localhost:3000/api/profile?access_token=" . $params['access_token'];
|
454
454
|
|
455
|
-
$profile = json_decode(file_get_contents($
|
455
|
+
$profile = json_decode(file_get_contents($platform_api_url));
|
456
456
|
|
457
457
|
echo("Hello " . $profile->name);
|
458
458
|
} else {
|
@@ -568,7 +568,7 @@
|
|
568
568
|
String
|
569
569
|
</td>
|
570
570
|
<td>
|
571
|
-
<%=tr("Access token to be used with every request to
|
571
|
+
<%=tr("Access token to be used with every request to Platform API") %>
|
572
572
|
</td>
|
573
573
|
</tr>
|
574
574
|
<tr>
|
@@ -1,12 +1,12 @@
|
|
1
1
|
<%= render :partial => "header" %>
|
2
2
|
|
3
3
|
<div class="documentation_section_title">
|
4
|
-
<%= tr("#{
|
4
|
+
<%= tr("#{Platform::Config.site_title}'s iOS SDK") %>
|
5
5
|
</div>
|
6
6
|
|
7
7
|
<div class="documentation_section">
|
8
8
|
<p>
|
9
|
-
The <%=
|
9
|
+
The <%=Platform::Config.site_title %> iOS SDK is a full featured iOS library allowing developers to build iOS applications with <%=Platform::Config.site_title %>'s data.
|
10
10
|
It enables full access to all of <%=Tr8n::Config.site_title %>'s API methods on the client-side and provides robust functionality for working with Oauth 2.0 authentication.
|
11
11
|
</p>
|
12
12
|
|
@@ -17,7 +17,7 @@
|
|
17
17
|
</p>
|
18
18
|
|
19
19
|
<div class="code_snippet">
|
20
|
-
<%=link_to("https://github.com/
|
20
|
+
<%=link_to("https://github.com/berk/platform_ios_clientsdk", "https://github.com/berk/platform_ios_clientsdk")%>
|
21
21
|
</div>
|
22
22
|
|
23
23
|
<p>
|
@@ -1,202 +1,30 @@
|
|
1
1
|
<%= render :partial => "header" %>
|
2
2
|
|
3
3
|
<div class="documentation_section_title">
|
4
|
-
<%= tr("#{
|
4
|
+
<%= tr("#{Platform::Config.site_title}'s JavaScript SDK") %>
|
5
5
|
</div>
|
6
6
|
|
7
7
|
<div class="documentation_section">
|
8
8
|
<p>
|
9
|
-
The <%=
|
10
|
-
|
9
|
+
The <%=Platform::Config.site_title %> JavaScript SDK is a full featured JavaScript library allowing developers to build iOS applications with <%=Platform::Config.site_title %>'s data.
|
10
|
+
It enables full access to all of <%=Tr8n::Config.site_title %>'s API methods on the client-side and provides robust functionality for working with Oauth 2.0 authentication.
|
11
11
|
</p>
|
12
12
|
|
13
|
-
<h2>JavaScript SDK Source Code</h2>
|
14
|
-
<div class="code_snippet">
|
15
|
-
<%=link_to("http://geni.com/jsdk.js", "http://geni.com/jsdk.js")%>
|
16
|
-
</div>
|
17
|
-
|
18
|
-
<h2>Getting Started</h2>
|
19
|
-
|
20
|
-
<p>
|
21
|
-
To get started, you'll need to add the library to your page, and initialize your app by calling <strong><%=Tr8n::Config.site_title %>.init()</strong>, passing in your application key.
|
22
|
-
The best place to put this is at the bottom of your page, before the closing <strong></body></strong> tag to prohibit blocking parallel downloads as described in
|
23
|
-
<a href="http://developer.yahoo.com/performance/rules.html#js_bottom">Yahoo's best practices</a>.
|
24
|
-
</p>
|
25
|
-
|
26
|
-
<pre class="code_snippet">
|
27
|
-
<script src="http://geni.com/jsdk.js"></script>
|
28
|
-
<script>
|
29
|
-
<%=Tr8n::Config.site_title %>.init({
|
30
|
-
app_id: 'YOUR_APP_KEY'
|
31
|
-
});
|
32
|
-
</script>
|
33
|
-
</pre>
|
34
|
-
|
35
|
-
<p>
|
36
|
-
In addition to app_id, <strong><%=Tr8n::Config.site_title %>.init()</strong> has a few optional parameters.
|
37
|
-
</p>
|
38
|
-
|
39
|
-
<pre class="code_snippet">
|
40
|
-
<script src="http://geni.com/jsdk.js"></script>
|
41
|
-
<script>
|
42
|
-
<%=Tr8n::Config.site_title %>.init({
|
43
|
-
app_id: 'YOUR_APP_KEY',
|
44
|
-
host: 'http://sandbox.geni.com', // change host if needed
|
45
|
-
cookie: true, // enables saving the access token to a cookie on the users machine
|
46
|
-
logging:true // enable log messages to help in debugging
|
47
|
-
});
|
48
|
-
</script>
|
49
|
-
</pre>
|
50
|
-
|
51
|
-
|
52
|
-
<h2>Authentication</h2>
|
53
|
-
|
54
|
-
<p>
|
55
|
-
Once your app has been initialized you can authenticate the user.
|
56
|
-
<%=Tr8n::Config.site_title %> uses Oauth 2.0 for authentication, which entails getting an access token for a user via a redirect to the <%=Tr8n::Config.site_title %>.com website.
|
57
|
-
Once a user approves your application you can then use the access token to make authorized requests to <%=Tr8n::Config.site_title %>'s API on behalf of that user.
|
58
|
-
</p>
|
59
|
-
|
60
|
-
|
61
|
-
<h2><%=Tr8n::Config.site_title %>.getStatus</h2>
|
62
|
-
<p>
|
63
|
-
To authenticate a user via the Javascript SDK you'll need to figure out whether the user is logged in and whether that user has already authorized your application. To do this we can use <strong><%=Tr8n::Config.site_title %>.getStatus()</strong>.
|
64
|
-
</p>
|
65
|
-
|
66
|
-
<pre class="code_snippet">
|
67
|
-
<%=Tr8n::Config.site_title %>.getStatus(function(response) {
|
68
|
-
if(response.status == 'authorized') {
|
69
|
-
// User is logged in and has authorized your application.
|
70
|
-
// You can now make authorized calls to the API.
|
71
|
-
} else {
|
72
|
-
// User is either logged out, has not authorized the app or both.
|
73
|
-
}
|
74
|
-
});
|
75
|
-
</pre>
|
76
|
-
|
77
|
-
<p>
|
78
|
-
The <%=Tr8n::Config.site_title %>.getStatus() method will make a request to <%=Tr8n::Config.site_title %> to obtain the current status of the user. The request will respond with one of three status types:
|
79
|
-
</p>
|
80
|
-
|
81
|
-
<ul class="data_list">
|
82
|
-
<li>"authorized" - the user is logged in to <%=Tr8n::Config.site_title %> and has authorized your application</li>
|
83
|
-
<li>"unauthorized" - the user is logged in to <%=Tr8n::Config.site_title %> but has not authorized your application</li>
|
84
|
-
<li>"unknown" - the user is logged out of <%=Tr8n::Config.site_title %></li>
|
85
|
-
</ul>
|
86
|
-
|
87
|
-
|
88
|
-
<h2><%=Tr8n::Config.site_title %>.connect</h2>
|
89
|
-
<p>
|
90
|
-
If the status is 'authorized', an access token will be returned which can then be used to start making API calls. If the status is either 'unauthorized' or 'unknown', your application will need to prompt the user to login and/or authorize by calling <%=Tr8n::Config.site_title %>.connect().
|
91
|
-
</p>
|
92
|
-
|
93
|
-
|
94
|
-
<pre class="code_snippet">
|
95
|
-
<%=Tr8n::Config.site_title %>.connect(function(response) {
|
96
|
-
if(response.status == 'authorized')) {
|
97
|
-
// User is logged in and has authorized your application.
|
98
|
-
// You can now make authorized calls to the API.
|
99
|
-
} else {
|
100
|
-
// User canceled the popup
|
101
|
-
}
|
102
|
-
});
|
103
|
-
</pre>
|
104
|
-
|
105
|
-
<p>
|
106
|
-
<%=Tr8n::Config.site_title %>.connect() will open a small popup window to the <%=Tr8n::Config.site_title %>.com site, prompting the user to login and authorize your application. The popup will close immediately after authorization is either allowed or disallowed.
|
107
|
-
</p>
|
108
|
-
|
109
|
-
<p>
|
110
|
-
Just like the <%=Tr8n::Config.site_title %>.getStatus() method, <%=Tr8n::Config.site_title %>.connect() returns user status and an access token if the user authorizes the application. Note: Because calling this method opens a popup window to the <%=Tr8n::Config.site_title %>.com site, it should only be called on a user action like a click on a button or link, as most browsers will block the popup unless they are the result of a user initiated event.
|
111
|
-
</p>
|
112
|
-
|
113
|
-
<h2><%=Tr8n::Config.site_title %>.logout</h2>
|
114
|
-
|
115
|
-
<p>
|
116
|
-
At some point you may wish to offer your users a way to logout of <%=Tr8n::Config.site_title %>. To do this the Javascript SDK offers the logout() method.
|
117
|
-
</p>
|
118
|
-
|
119
|
-
<pre class="code_snippet">
|
120
|
-
<%=Tr8n::Config.site_title %>.logout(function() {
|
121
|
-
// The user is now logged out of <%=Tr8n::Config.site_title %>
|
122
|
-
// Your application will no longer be able to make api calls on the users behalf until they log back in
|
123
|
-
});
|
124
|
-
</pre>
|
125
|
-
|
126
|
-
|
127
|
-
<h2>Status Change Events</h2>
|
128
|
-
<p>
|
129
|
-
The Javascript SDK also provides an 'auth:statusChange' event that can be subscribed to. The event fires when the user's status changes as the result of calling one of these methods.
|
130
|
-
</p>
|
131
|
-
|
132
|
-
<pre class="code_snippet">
|
133
|
-
<%=Tr8n::Config.site_title %>.Event.bind('auth:statusChange',function(status) {
|
134
|
-
// status will be either 'authorized', 'unauthorized' or 'unknown'
|
135
|
-
});
|
136
|
-
</pre>
|
137
13
|
|
14
|
+
<h2>Installing Javascript SDK</h2>
|
138
15
|
<p>
|
139
|
-
|
16
|
+
You can install the SDK from the following URL:
|
140
17
|
</p>
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
Once you have an authenticated user, you are free to make calls to the <%=Tr8n::Config.site_title %> API. With the Javascript SDK, developers get full access to the API directly through the user's browser via the <%=Tr8n::Config.site_title %>.api() method.
|
147
|
-
</p>
|
148
|
-
|
18
|
+
|
19
|
+
<div class="code_snippet">
|
20
|
+
<%=link_to("https://github.com/berk/platform_js_clientsdk", "https://github.com/berk/platform_js_clientsdk")%>
|
21
|
+
</div>
|
22
|
+
|
149
23
|
<p>
|
150
|
-
|
24
|
+
Follow the documentation on the SDK site to get the SDK integrated into your application.
|
151
25
|
</p>
|
152
|
-
|
153
|
-
|
154
|
-
<%=Tr8n::Config.site_title %>.api('/profile-101/tree_matches', function(response) {
|
155
|
-
// returns a list of tree matches for profile with id 101
|
156
|
-
});
|
157
|
-
</pre>
|
158
|
-
|
159
|
-
<p>
|
160
|
-
Omitting the ids in urls implies the action should be applied to the current user’s data.
|
161
|
-
</p>
|
162
|
-
|
163
|
-
<pre class="code_snippet">
|
164
|
-
<%=Tr8n::Config.site_title %>.api('/profile', function(response) {
|
165
|
-
// returns current user's profile data
|
166
|
-
// alert(response.name)
|
167
|
-
});
|
168
|
-
</pre>
|
169
|
-
|
170
|
-
|
171
|
-
<p>
|
172
|
-
Specific parameters can optionally be passed in as the second argument.
|
173
|
-
</p>
|
174
|
-
|
175
|
-
<pre class="code_snippet">
|
176
|
-
<%=Tr8n::Config.site_title %>.api('/profile', { fields : 'first_name'}, function(data)
|
177
|
-
// only returns first name of profile current users profile
|
178
|
-
alert("Welcome + " " + response.first_name);
|
179
|
-
});
|
180
|
-
</pre>
|
181
|
-
|
182
|
-
<p>
|
183
|
-
For post requests, you'll need to pass a 'method' parameter in the second argument.
|
184
|
-
</p>
|
185
|
-
|
186
|
-
|
187
|
-
<pre class="code_snippet">
|
188
|
-
<%=Tr8n::Config.site_title %>.api('/profile', {
|
189
|
-
method:'post',
|
190
|
-
first_name: 'John'
|
191
|
-
},
|
192
|
-
function(response) {
|
193
|
-
// the current users first name is now set to 'John'
|
194
|
-
}
|
195
|
-
);
|
196
|
-
</pre>
|
197
|
-
|
198
|
-
</p>
|
199
|
-
|
26
|
+
|
27
|
+
|
200
28
|
</div>
|
201
29
|
|
202
30
|
<%= render :partial => "footer" %>
|