Files
deployd/lib/resources/collection/dashboard/api.html
2012-07-27 13:43:55 -07:00

179 lines
7.1 KiB
HTML

<div id="api" class="tab-pane well stacked hide">
</div>
<script type="text/html" id="api-template">
<h3>API</h3>
<ul class="nav nav-tabs" id="event-nav">
<li class="active"><a href="#js-examples" data-toggle='tab'>JavaScript</a></li>
<li><a href="#rest-examples" data-toggle='tab'>REST</a></li>
</ul>
<div class="tab-content tab-content-styled">
<div id="js-examples" class="tab-pane active">
<p>Deployd generates a browser JavaScript api for easily accessing data from the <code><%= resourceData.path %></code> collection. To use it you first need to include jQuery and the generated script.</p>
<pre class="prettyprint code">&lt;script src="http://code.jquery.com/jquery-latest.min.js"&gt;&lt;/script&gt;
&lt;script src="dpd.js"&gt;&lt;/script&gt;</pre>
<% if (resourceData.type === 'UserCollection') { %>
<p>Register a new user in the <code><%= resourceData.path %></code> collection:</p>
<pre class="code prettyprint">
dpd<%= ns(resourceData.path) %>.post({"email": "foo@bar.com", "password": "mypassword"}, function(user, err) {
if(err) return console.log(err);
console.log(user);
});</pre>
<p>Login an existing user in the <code><%= resourceData.path %></code> collection:</p>
<pre class="code prettyprint">
dpd<%= ns(resourceData.path) %>.login({"email": "foo@bar.com", "password": "mypassword"}, function(user, err) {
if(err) return console.log(err);
console.log(user);
});</pre>
<p>Get the current user in the <code><%= resourceData.path %></code> collection:</p>
<pre class="code prettyprint">
dpd<%= ns(resourceData.path) %>.me(function(me) {
console.log(me);
});</pre>
<p>Logout the current user in the <code><%= resourceData.path %></code> collection:</p>
<pre class="code prettyprint">
dpd<%= ns(resourceData.path) %>.logout(function(err) {
if(err) console.log(err);
});</pre>
<% } else { %>
<p>Insert data into the <code><%= resourceData.path %></code> collection:</p>
<pre class="code prettyprint">
dpd<%= ns(resourceData.path) %>.post(<%= getObj() %>, function(result, err) {
if(err) return console.log(err);
console.log(result, result.id);
});</pre>
<% } %>
<p>Get all the objects in the <code><%= resourceData.path %></code> collection:</p>
<pre class="code prettyprint">
dpd<%= ns(resourceData.path) %>.get(function (result, err) {
if(err) return console.log(err);
console.log(result);
});</pre>
<p>Get all the objects in the <code><%= resourceData.path %></code> collection that match a <a href="http://www.mongodb.org/display/DOCS/Advanced+Queries">query</a>:</p>
<pre class="code prettyprint">
var query = <%= getObj() %>;
dpd<%= ns(resourceData.path) %>.get(query, function (result) {
console.log(result);
});</pre>
<p>Get a single object in the <code><%= resourceData.path %></code> collection by id:</p>
<pre class="code prettyprint">
dpd<%= ns(resourceData.path) %>.first("000000000000000000000000", function (result) {
console.log(result);
});</pre>
<p>Get a single object in the <code><%= resourceData.path %></code> collection that matches a <a href="http://www.mongodb.org/display/DOCS/Advanced+Queries">query</a>:</p>
<pre class="code prettyprint">
var query = <%= getObj() %>;
dpd<%= ns(resourceData.path) %>.first(query, function (result) {
console.log(result);
});</pre>
<p>Update an object in the <code><%= resourceData.path %></code> collection:</p>
<pre class="code prettyprint">
dpd<%= ns(resourceData.path) %>.put("000000000000000000000000", <%= getObj() %>, function(result, err) {
if(err) return console.log(err);
console.log(result, result.id);
});</pre>
<p>Remove a single object from the <code><%= resourceData.path %></code> collection:</p>
<pre class="code prettyprint">
dpd<%= ns(resourceData.path) %>.del("000000000000000000000000", function (err) {
if(err) console.log(err);
});</pre>
</div>
<div id="rest-examples" class="tab-pane">
<p>Access the <code><%= resourceData.path %></code> collection over http.</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Task</th>
<th>Method</th>
<th>Route</th>
<th>Accepts</th>
<th>Returns</th>
</tr>
<tbody>
<tr>
<td><a href="http://deployd.github.com/deployd/#Listing-data" target="_blank">Listing data</a></td>
<td>GET</td>
<td><a href="<%- resourceData.path %>" target="_blank"><%- resourceData.path %></a></td>
<td><em>Nothing</em></td>
<td>An array of objects</td>
</tr>
<tr>
<td><a href="http://deployd.github.com/deployd/#Saving-data" target="_blank">Creating an object</a></td>
<td>POST</td>
<td><%- resourceData.path %></td>
<td>A single object</td>
<td>The saved object (or errors)</td>
</tr>
<tr>
<td><a href="http://deployd.github.com/deployd/#Retrieving-a-specific-object" target="_blank">Getting an object</a></td>
<td>GET</td>
<td><%- resourceData.path %>/&lt;id&gt;</td>
<td><em>Nothing</em></td>
<td>A single object</td>
</tr>
<tr>
<td><a href="http://deployd.github.com/deployd/#Updating-an-object" target="_blank">Updating an object</a></td>
<td>PUT</td>
<td><%- resourceData.path %>/&lt;id&gt;</td>
<td>A single object</td>
<td>The saved object (or errors)</td>
</tr>
<tr>
<td><a href="http://deployd.github.com/deployd/#Deleting-an-object" target="_blank">Deleting an object</a></td>
<td>DELETE</td>
<td><%- resourceData.path %>/&lt;id&gt;</td>
<td>A single object</td>
<td><em>Nothing</em></td>
</tr>
<% if (resourceData.type === 'UserCollection') { %>
<tr>
<td><a href="http://deployd.github.com/deployd/#Authenticating-a-user" target="_blank">Logging in</a></td>
<td>POST</td>
<td><%- resourceData.path %>/login</td>
<td><code>email</code> and <code>password</code> of user</td>
<td>The user, plus session cookie (or error)</td>
</tr>
<tr>
<td><a href="http://deployd.github.com/deployd/#Logging-out" target="_blank">Logging out</a></td>
<td>POST</td>
<td><%- resourceData.path %>/logout</td>
<td><em>Nothing</em></td>
<td><em>Nothing</em></td>
</tr>
<tr>
<td><a href="http://deployd.github.com/deployd/#Current-user" target="_blank">Getting the current user</a></td>
<td>GET</td>
<td><a href="<%- resourceData.path %>/me" target="_blank"><%- resourceData.path %>/me</a></td>
<td><em>Nothing</em></td>
<td>A single object</td>
</tr>
<% } %>
</tbody>
</thead>
</table>
</div>
</div>
</script>