-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.html
144 lines (115 loc) · 4.86 KB
/
index.html
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Hullo World!</title>
<meta name="description" content="Hullo, world!">
<meta name="viewport" content="width=device-width">
<!-- Those are optional too, just here for the demo. Remove if you don't need them -->
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
<!-- Now the real stuff begings. This is mandatory -->
<script src="https://d3f5pyioow99x0.cloudfront.net/0.8/hull.api.js"></script>
<script>
// Before calling any Hull method, ensure Initialization is complete.
Hull.init({
debug: true, // Comment this line to stop displaying debugging information
orgUrl: "YOUR_ORGANIZATION_URL",
appId: "YOUR_APP_ID"
}, function(hull, me, app, org) {
//Hull is initialized, This is where you start your app.
//Create a test user, then make him post a comment on an object.
if(me){
retrieveComments();
} else {
Hull.signup({
email:'user@host.com',
password:'test_password',
name: 'Test user',
picture: 'http://placehold.it/100x100'
}).then(function(user){
postComment();
}).fail(handleSignupError);
}
});
//Handle signup error with email already taken.
var handleSignupError = function(error){
if(error && error.errors && error.errors.email && error.errors.email[0]=="is already taken"){
Hull.login('user@host.com','test_password').then(handleSuccess).fail(handleError);
}
}
// Post a comment on 'TestObject'
var postComment = function() {
var testObjectEntity = Hull.util.entity.encode('TestObject');
Hull.api(testObjectEntity + '/comments', 'post', {
description: 'Hullo, world',
}).then(handleSuccess).fail(handleError);
};
var handleSuccess = function(response) {
$('#success').removeClass('hidden');
$('#success_output').html(JSON.stringify(response, null, 2));
};
var handleError = function(error){
$('#error').removeClass('hidden');
$('#error_output').html(JSON.stringify(error,null,2));
}
// Retreive comments on the entity, and display them
var retrieveComments = function(){
var testObjectEntity = Hull.util.entity.encode('TestObject');
Hull.api(testObjectEntity + '/comments').then(function(comments){
handleSuccess(comments[0]);
}).fail(handleError);
}
</script>
</head>
<body>
<div class="container">
<div class="col-md-6">
<div id="error" class="hidden">
<h3>Something went wrong!</h3>
<p>It looks like an error occured when trying to create the test comment or log you in. Here are more details:</p>
<pre><code id='error_output'></code></pre>
</div>
<div id="success" class="hidden">
<h3>Hull is ready!</h3>
<p>We signed up a test user with the following credentials and logged you in with it.</p>
<ul>
<li><strong>email</strong> : user@host.com</li>
<li><strong>password</strong> : test_password</li>
</ul>
<pre><code>Hull.signup({
email:'user@host.com',
password:'test_password',
name: 'Test user',
picture: 'http://placehold.it/100x100'
})</code></pre>
<p>Then we created your first comment on the <a href='http://hull.io/docs/social/entities'>Entity</a> "TestObject" with this code:</p>
<pre><code>var testObjectEntity = Hull.util.entity.encode('TestObject');
Hull.api(testObjectEntity + '/comments', 'post', {
description: 'Hullo, world',
});</code></pre>
<p>Here is the response: </p>
<pre><code id='success_output'></code></pre>
</div>
</div>
<div class="col-md-6">
<h3>Read the docs and start building:</h3>
<ul>
<li><a href='http://hull.io/docs/start'>Quickstart</a></li>
<li><a href='http://hull.io/docs/references/hull_js'>Hull.js Reference</a></li>
<li><a href='http://hull.io/docs/users'>User authentication</a></li>
<li><a href='http://hull.io/docs/social'>Social Actions</a></li>
</ul>
</div>
</div>
<script>
// This is used only when the page is served as a local file (eg, file://path/to/index.html)
// instead of an HTTP server (eg, http://domain.tld/path/to/index.html).
// Remove it when your server is setup.
if (!~window.location.protocol.indexOf('http')) {
document.body.innerHTML = '<h1>It seems you\'re trying to run the app as a file.</h1><p>Hull apps must be served fron an HTTP server. <a href="http://hull.io/docs/apps/serve" target="_blank">How do I do this?</a></p>';
}
</script>
</body>
</html>