Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 163 lines (109 sloc) 3.298 kb
f956f5c8 »
2012-06-09 Generate gem with bundler
1 # Hovercraft
2
2be882bb »
2012-07-02 Setup travis ci
3 [![Build Status](https://secure.travis-ci.org/vanstee/hovercraft.png)](http://travis-ci.org/vanstee/hovercraft)
a2fc4aa4 »
2012-07-02 Add dependency status badge
4 [![Dependency Status](https://gemnasium.com/vanstee/hovercraft.png)](https://gemnasium.com/vanstee/hovercraft)
2be882bb »
2012-07-02 Setup travis ci
5
5a70a8f6 »
2012-07-02 Update description and README
6 Generate a RESTful API from a directory of ActiveRecord models.
f956f5c8 »
2012-06-09 Generate gem with bundler
7
8cff7c1a »
2012-07-08 Spruce up the README with more complete examples
8 ## Short Disclaimer
9
10 I am not yet running this in production and the gem is not very
11 extensible at this point. Consider it a proof of concept.
12
5a70a8f6 »
2012-07-02 Update description and README
13 ## Get Up and Running
f956f5c8 »
2012-06-09 Generate gem with bundler
14
5a70a8f6 »
2012-07-02 Update description and README
15 1. Throw this in your Gemfile:
f956f5c8 »
2012-06-09 Generate gem with bundler
16
8cff7c1a »
2012-07-08 Spruce up the README with more complete examples
17 ```ruby
18 gem 'hovercraft'
19 ```
f956f5c8 »
2012-06-09 Generate gem with bundler
20
5a70a8f6 »
2012-07-02 Update description and README
21 2. Put your ActiveRecord models in `models/` (make sure the file names
22 are the same as the class names).
f956f5c8 »
2012-06-09 Generate gem with bundler
23
8cff7c1a »
2012-07-08 Spruce up the README with more complete examples
24 Here's an example:
25
26 ```ruby
27 # models/employee.rb
28
29 class Employee < ActiveRecord::Base
30 attr_accessible :name, :career
31 end
32 ```
33
34 If you need help setting up an entire sinatra app here's a full
35 example: http://github.com/vanstee/hovercraft_example
36
5a70a8f6 »
2012-07-02 Update description and README
37 3. Create a rackup file that generates the application:
f956f5c8 »
2012-06-09 Generate gem with bundler
38
5a70a8f6 »
2012-07-02 Update description and README
39 ```ruby
8cff7c1a »
2012-07-08 Spruce up the README with more complete examples
40 # config.ru
41
42 require 'bundler'
43 Bundler.require
44
5a70a8f6 »
2012-07-02 Update description and README
45 run Hovercraft::Server.new
8cff7c1a »
2012-07-08 Spruce up the README with more complete examples
46 ```
47
48 If you need more setup I'd recommend using an `application.rb` file
49 and requiring that in the `config.ru` instead.
f956f5c8 »
2012-06-09 Generate gem with bundler
50
5a70a8f6 »
2012-07-02 Update description and README
51 4. Run the application like normal:
f956f5c8 »
2012-06-09 Generate gem with bundler
52
8cff7c1a »
2012-07-08 Spruce up the README with more complete examples
53 ```
54 bundle exec rackup
55 ```
56
57 5. Make some requests:
58
59 Create a record:
60
61 ```bash
62 curl -H 'Content-type: application/json' \
63 -X POST \
64 -d '{ "employee": { "name": "Philip J. Fry", "career": "Delivery Boy 1st Class" } }' \
65 http://localhost:9292/employees.json
66 ```
67
68 Show all records:
69
70 ```bash
71 curl http://localhost:9292/employees.json
72 ```
73
74 Show a single record:
75
76 ```bash
77 curl http://localhost:9292/employees/1.json
78 ```
79
80 Update a record:
81
82 ```bash
83 curl -H "Content-type: application/json" \
84 -X PUT \
85 -d '{ "employee": { "name": "Philip J. Fry", "career": "Executive Delivery Boy" } }' \
86 http://localhost:9292/employees/1.json
87 ```
88
89 Delete a record:
90
91 ```bash
92 curl -X DELETE http://localhost:9292/employees/1.json
93 ```
f956f5c8 »
2012-06-09 Generate gem with bundler
94
12f887f2 »
2012-07-29 Authenticate requests with warden
95 ## Authentication
96
97 1. Include `warden` in your Gemfile:
98
99 ```ruby
100 gem 'warden'
101 ```
102
103 2. Use rack builder to add warden strategies to your rackup file:
104
105 ```ruby
106 # config.ru
107
108 require 'bundler'
109 Bundler.require
110
111 application = Rack::Builder.new do
112 use Rack::Session::Cookie, secret: '...'
113
114 Warden::Strategies.add :password do
115 def valid?
116 ...
117 end
118
119 def authenticate
120 ...
121 end
122 end
123
124 use Warden::Manager do |manager|
125 manager.default_strategies :password
126 manager.failure_app = ...
127 end
128
129 run Hovercraft::Server
130 end
131
132 run application
133 ```
134
135 See the [warden project](https://github.com/hassox/warden/) for more in-depth examples or help troubleshooting.
136
5a70a8f6 »
2012-07-02 Update description and README
137 ## Give Back
f956f5c8 »
2012-06-09 Generate gem with bundler
138
8cff7c1a »
2012-07-08 Spruce up the README with more complete examples
139 1. Fork it:
140
141 https://help.github.com/articles/fork-a-repo
142
143 2. Create your feature branch:
144
145 ```bash
146 git checkout -b fixes_horrible_spelling_errors
147 ```
148
149 3. Commit your changes:
150
151 ```bash
152 git commit -am 'Really? You spelled application as "applickachon"?'
153 ```
154
155 4. Push the branch:
156
157 ```bash
158 git push origin fixes_horrible_spelling_errors
159 ```
160
161 5. Create a pull request:
162
163 https://help.github.com/articles/using-pull-requests
Something went wrong with that request. Please try again.