Skip to content

Commit

Permalink
Add API docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Bell committed Nov 13, 2011
1 parent 3f62183 commit ec4521e
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 11 deletions.
14 changes: 4 additions & 10 deletions lib/hubot_factory/app.rb
Expand Up @@ -27,6 +27,10 @@ class App < Sinatra::Base
mustache :index
end

get "/api_docs" do
mustache :api_docs
end

post "/build" do
@email = params[:email]
@name = params[:name]
Expand All @@ -48,15 +52,5 @@ class App < Sinatra::Base
@title = "About - Hubot Factory"
mustache :about
end


post "/build_notice" do
email = params[:email]
name = params[:name]
adapter = params[:adapter]

puts "built #{name} on #{adapter} transferred to #{email}"
"gj!"
end
end
end
14 changes: 14 additions & 0 deletions public/stylesheets/app.css
Expand Up @@ -43,6 +43,20 @@ h2 {
font-weight: bold;
}

code, pre {
font-family: Consolas, Menlo, "Courier New", monospace;
font-size: 14px;
}

pre {
background-color: #fafafa;
border: 1px solid #d5d5d5;
border-left: 10px solid #d5d5d5;
line-height: 20px;
overflow-x: auto;
padding: 11px 15px 12px;
}

form p {
margin: 0 0 12px 0;
}
Expand Down
66 changes: 66 additions & 0 deletions templates/api_docs.mustache
@@ -0,0 +1,66 @@
<h1>API Documentation</h1>

<p>
So what happens when you automate automation? Let's find out. We present to
you an API for Hubot Factory. You no longer need to visit the web site to
build and deploy a Hubot!
</p>

<p>
The API is currently <strong>very</strong> simple to use. It's a single end
point you HTTP POST your configuration to and we'll return a response telling
you whether it was successful or not.
</p>

<h2>Creating a Hubot</h2>

<pre><code>POST /api/build</code></pre>

<h3>Request</h3>

<ul>
<li><strong>email</strong> - Required</li>
<li><strong>name</strong> - Required</li>
<li><strong>adapter</strong> - Required</li>
<li><strong>url</strong> - Optional</li>
<li><strong>adapter_vars</strong> Optional</li>
</ul>

<pre><code>{
"email": "hubot@hubot-factory.com",
"name": "Hubot",
"adapter": "campfire",
"url": "http://hubot-factory.com/provision",
"adapter_vars": [
"HUBOT_CAMPFIRE_ROOMS": "123,321",
"HUBOT_CAMPFIRE_ACCOUNT": "hubot-factory",
"HUBOT_CAMPFIRE_TOKEN": "5d748c04a2bd7aadd7a15d062f5f29108773ad34"
]
}</code></pre>

<h3>Response</h3>

<p>
If an error occurs the <code>success</code> property will be false and a
<code>message</code> property will contain the error message.
</p>

<pre><code>{
"success": true
}</code></pre>

<h3>HTTP POST Notification</h3>

<p>
If you supply a <code>url</code> parameter we will send a HTTP POST request
to this URL when your Hubot has been built and deployed.
</p>

<h3>Payload</h3>

<pre><code>{
"email": "hubot@hubot-factory.com",
"name": "Hubot",
"adapter": "campfire"
}</code></pre>

6 changes: 5 additions & 1 deletion templates/layout.mustache
Expand Up @@ -18,7 +18,11 @@
<div class="container_12">
<div class="main grid_8 push_2">
<p>
<a href="/">Build</a> &middot; <a href="/about">About</a>
<a href="/">Build</a>
&middot;
<a href="/api_docs"> API</a>
&middot;
<a href="/about">About</a>
</p>

{{{yield}}}
Expand Down
6 changes: 6 additions & 0 deletions views/api_docs.rb
@@ -0,0 +1,6 @@
module HubotFactory
module Views
class ApiDocs < Layout
end
end
end

0 comments on commit ec4521e

Please sign in to comment.