Skip to content

Commit 516df8f

Browse files
authored
Style improvements (#6)
* easy updates from swagger_ui_to_rails_assets * required updates
1 parent 029047b commit 516df8f

21 files changed

+181
-184
lines changed

.env.sample

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
BIKEINDEX_APP_ID: SWEET_APP_ID
2+
BIKEINDEX_APP_SECRET: SOME_SECRET_THING
3+
DEVISE_SECRET_KEY: 89xcv98xcv98xcvxcXXXXXX
4+
SECRET_KEY_BASE: 9412651f423fd80bfaad4872a03ec735183cf4a2fd72779b47a45368e69ae5d34d3156c00673da471e440109ef4096bb13e987420537d0e0be45b8cd6317d083

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
/tmp
1414

1515
# Ignore environmental variables
16-
.env*
17-
16+
.env
1817

1918
# Ignore rvm stuff and things
2019
dump.rdb

.travis.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
language: ruby
2+
addons:
3+
postgresql: '9.4'
4+
rvm:
5+
- 2.2.5
6+
before_install:
7+
- gem install bundler -v 1.9.10
8+
script:
9+
- bundle exec rspec
10+
before_script:
11+
- psql -c 'create database grape_doorkeeper_test' -U postgres
12+
- bundle exec rake db:schema:load
13+
cache: bundler
14+
notifications:
15+
email:
16+
on_success: never

Gemfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
ruby '2.2.2'
1+
ruby '2.2.5'
22
source 'https://rubygems.org'
33

44
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
5-
gem 'rails', '4.2.5'
5+
gem 'rails', '4.2.7'
66
# Use postgresql as the database for Active Record
77
gem 'pg'
88
gem 'sass'
@@ -40,6 +40,7 @@ gem 'wine_bouncer'
4040
gem 'kramdown'
4141
gem 'kaminari'
4242
gem 'grape'
43+
gem 'grape_logging'
4344
gem 'active_model_serializers'
4445
gem 'grape-active_model_serializers'
4546
gem 'grape-swagger'

Gemfile.lock

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,38 @@ GIT
77
GEM
88
remote: https://rubygems.org/
99
specs:
10-
actionmailer (4.2.5)
11-
actionpack (= 4.2.5)
12-
actionview (= 4.2.5)
13-
activejob (= 4.2.5)
10+
actionmailer (4.2.7)
11+
actionpack (= 4.2.7)
12+
actionview (= 4.2.7)
13+
activejob (= 4.2.7)
1414
mail (~> 2.5, >= 2.5.4)
1515
rails-dom-testing (~> 1.0, >= 1.0.5)
16-
actionpack (4.2.5)
17-
actionview (= 4.2.5)
18-
activesupport (= 4.2.5)
16+
actionpack (4.2.7)
17+
actionview (= 4.2.7)
18+
activesupport (= 4.2.7)
1919
rack (~> 1.6)
2020
rack-test (~> 0.6.2)
2121
rails-dom-testing (~> 1.0, >= 1.0.5)
2222
rails-html-sanitizer (~> 1.0, >= 1.0.2)
23-
actionview (4.2.5)
24-
activesupport (= 4.2.5)
23+
actionview (4.2.7)
24+
activesupport (= 4.2.7)
2525
builder (~> 3.1)
2626
erubis (~> 2.7.0)
2727
rails-dom-testing (~> 1.0, >= 1.0.5)
2828
rails-html-sanitizer (~> 1.0, >= 1.0.2)
2929
active_model_serializers (0.9.3)
3030
activemodel (>= 3.2)
31-
activejob (4.2.5)
32-
activesupport (= 4.2.5)
31+
activejob (4.2.7)
32+
activesupport (= 4.2.7)
3333
globalid (>= 0.3.0)
34-
activemodel (4.2.5)
35-
activesupport (= 4.2.5)
34+
activemodel (4.2.7)
35+
activesupport (= 4.2.7)
3636
builder (~> 3.1)
37-
activerecord (4.2.5)
38-
activemodel (= 4.2.5)
39-
activesupport (= 4.2.5)
37+
activerecord (4.2.7)
38+
activemodel (= 4.2.7)
39+
activesupport (= 4.2.7)
4040
arel (~> 6.0)
41-
activesupport (4.2.5)
41+
activesupport (4.2.7)
4242
i18n (~> 0.7)
4343
json (~> 1.7, >= 1.7.7)
4444
minitest (~> 5.1)
@@ -71,7 +71,7 @@ GEM
7171
coffee-script-source
7272
execjs
7373
coffee-script-source (1.9.1.1)
74-
concurrent-ruby (1.0.1)
74+
concurrent-ruby (1.0.2)
7575
database_cleaner (1.5.0)
7676
descendants_tracker (0.0.4)
7777
thread_safe (~> 0.3, >= 0.3.1)
@@ -94,7 +94,7 @@ GEM
9494
http_parser.rb (~> 0.6.0)
9595
equalizer (0.0.11)
9696
erubis (2.7.0)
97-
eventmachine (1.0.8)
97+
eventmachine (1.2.0.1)
9898
execjs (2.6.0)
9999
factory_girl (4.5.0)
100100
activesupport (>= 3.0.0)
@@ -107,7 +107,7 @@ GEM
107107
foreman (0.78.0)
108108
thor (~> 0.19.1)
109109
formatador (0.2.5)
110-
globalid (0.3.6)
110+
globalid (0.3.7)
111111
activesupport (>= 4.1.0)
112112
grape (0.13.0)
113113
activesupport
@@ -128,6 +128,8 @@ GEM
128128
grape-swagger (0.10.4)
129129
grape (>= 0.8.0)
130130
grape-entity (< 0.5.0)
131+
grape_logging (1.3.0)
132+
grape
131133
growl (1.0.3)
132134
guard (2.13.0)
133135
formatador (>= 0.2.4)
@@ -174,18 +176,20 @@ GEM
174176
loofah (2.0.3)
175177
nokogiri (>= 1.5.9)
176178
lumberjack (1.0.9)
177-
mail (2.6.3)
178-
mime-types (>= 1.16, < 3)
179+
mail (2.6.4)
180+
mime-types (>= 1.16, < 4)
179181
method_source (0.8.2)
180-
mime-types (2.99.1)
181-
mini_portile2 (2.0.0)
182-
minitest (5.8.4)
182+
mime-types (3.1)
183+
mime-types-data (~> 3.2015)
184+
mime-types-data (3.2016.0521)
185+
mini_portile2 (2.1.0)
186+
minitest (5.9.1)
183187
multi_json (1.11.2)
184188
multi_xml (0.5.5)
185189
multipart-post (2.0.0)
186190
nenv (0.2.0)
187-
nokogiri (1.6.7.2)
188-
mini_portile2 (~> 2.0.0.rc2)
191+
nokogiri (1.6.8.1)
192+
mini_portile2 (~> 2.1.0)
189193
notiffany (0.0.8)
190194
nenv (~> 0.1)
191195
shellany (~> 0.0)
@@ -222,16 +226,16 @@ GEM
222226
rack (>= 1.0.0)
223227
rack-test (0.6.3)
224228
rack (>= 1.0)
225-
rails (4.2.5)
226-
actionmailer (= 4.2.5)
227-
actionpack (= 4.2.5)
228-
actionview (= 4.2.5)
229-
activejob (= 4.2.5)
230-
activemodel (= 4.2.5)
231-
activerecord (= 4.2.5)
232-
activesupport (= 4.2.5)
229+
rails (4.2.7)
230+
actionmailer (= 4.2.7)
231+
actionpack (= 4.2.7)
232+
actionview (= 4.2.7)
233+
activejob (= 4.2.7)
234+
activemodel (= 4.2.7)
235+
activerecord (= 4.2.7)
236+
activesupport (= 4.2.7)
233237
bundler (>= 1.3.0, < 2.0)
234-
railties (= 4.2.5)
238+
railties (= 4.2.7)
235239
sprockets-rails
236240
rails-deprecated_sanitizer (1.0.3)
237241
activesupport (>= 4.2.0.alpha)
@@ -241,13 +245,13 @@ GEM
241245
rails-deprecated_sanitizer (>= 1.0.1)
242246
rails-html-sanitizer (1.0.3)
243247
loofah (~> 2.0)
244-
railties (4.2.5)
245-
actionpack (= 4.2.5)
246-
activesupport (= 4.2.5)
248+
railties (4.2.7)
249+
actionpack (= 4.2.7)
250+
activesupport (= 4.2.7)
247251
rake (>= 0.8.7)
248252
thor (>= 0.18.1, < 2.0)
249253
rainbow (2.1.0)
250-
rake (10.5.0)
254+
rake (11.3.0)
251255
rb-fsevent (0.9.6)
252256
rb-inotify (0.9.5)
253257
ffi (>= 0.5.0)
@@ -295,10 +299,10 @@ GEM
295299
activesupport (>= 4.0.0)
296300
slop (3.6.0)
297301
spring (1.4.0)
298-
sprockets (3.5.2)
302+
sprockets (3.7.0)
299303
concurrent-ruby (~> 1.0)
300304
rack (> 1, < 3)
301-
sprockets-rails (3.0.3)
305+
sprockets-rails (3.2.0)
302306
actionpack (>= 4.0)
303307
activesupport (>= 4.0)
304308
sprockets (>= 3.0.0)
@@ -345,6 +349,7 @@ DEPENDENCIES
345349
grape
346350
grape-active_model_serializers
347351
grape-swagger
352+
grape_logging
348353
growl
349354
guard
350355
guard-livereload
@@ -361,7 +366,7 @@ DEPENDENCIES
361366
pry
362367
puma
363368
rack-cors
364-
rails (= 4.2.5)
369+
rails (= 4.2.7)
365370
rerun
366371
rspec (~> 3.3.0)
367372
rspec-rails
@@ -375,5 +380,8 @@ DEPENDENCIES
375380
vcr
376381
wine_bouncer
377382

383+
RUBY VERSION
384+
ruby 2.2.5p319
385+
378386
BUNDLED WITH
379-
1.11.2
387+
1.13.3

Procfile_development

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
custom_web: bundle exec puma -b 'tcp://0.0.0.0:3001' -C config/puma.rb
1+
custom_web: bundle exec puma -b 'tcp://0.0.0.0:3003' -C config/puma.rb
22
log: tail -f log/development.log

README.markdown

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ This app is ready to deploy to Heroku [![Deploy](https://www.herokucdn.com/deplo
1111

1212
## Set up
1313

14-
First `bundle install` and `rake db:setup`
14+
- Set up the rails app and database with `bundle install` and `rake db:setup`
1515

16-
Run `rake start` to get the server running locally. It runs at [http://localhost:3001](http://localhost:3001)
16+
- Run `./start` to get the server running locally. It runs at [http://localhost:3003](http://localhost:3003)
1717

18-
You will want to change [config/initializers/secret_token.rb](config/initializers/secret_token.rb) and export `DEVISE_SECRET_KEY` (see config/initializers/devise.rb).
18+
- Copy [.env.sample](/.env.sample) to `.env` and replace the values with your own values.
1919

20-
You will also probably want to delete the [imaginary item](app/models/imaginary_item.rb) class and [serializer](app/serializers/item_serializer.rb), which are included for demonstration in [the me/items endpoint](app/controllers/api/v1/me.rb#L24-L33).
20+
- Delete the [imaginary item](app/models/imaginary_item.rb) class and [serializer](app/serializers/item_serializer.rb), which are included for demonstration in [the me/items endpoint](app/controllers/api/v1/me.rb#L24-L33).
2121

22-
This app includes [omniauth-bike-index](https://github.com/bikeindex/omniauth-bike-index). For Bike Index login to work, export environment variables `BIKEINDEX_APP_ID` and `BIKEINDEX_APP_SECRET`. You'll need a Bike Index app, which you can create at [BikeIndex.org/oauth/applications/new](https://BikeIndex.org/oauth/applications/new).
22+
This app includes [omniauth-bike-index](https://github.com/bikeindex/omniauth-bike-index). For Bike Index login to work, create a Bike Index app at [BikeIndex.org/oauth/applications/new](https://BikeIndex.org/oauth/applications/new) and add the values from `BIKEINDEX_APP_ID` and `BIKEINDEX_APP_SECRET` to the `.env` file.
2323

2424
*Bike Index uses a similar grape, Swagger, doorkeeper setup&mdash;this is an example of [creating an OmniAuth strategy for doorkeeper](https://github.com/doorkeeper-gem/doorkeeper/wiki/Create-a-OmniAuth-strategy-for-your-provider)*.
2525

@@ -48,13 +48,13 @@ Important things in the Gemfile:
4848

4949
Also important, but maybe not as necessary to know about:
5050

51-
- [rails_swagger-ui](https://github.com/d4be4st/swagger-ui_rails) (how we get swagger-ui)
51+
- [rails-assets](https://rails-assets.org) manages the js for swagger-ui
5252
- [Puma](http://puma.io/) (the web server)
5353
- [api-pagination](https://github.com/davidcelis/api-pagination)
5454
- [grape-active_model_serializers](https://github.com/jrhe/grape-active_model_serializers)
5555
- [CORS](https://github.com/cyu/rack-cors)
5656
- [foreman](https://github.com/ddollar/foreman) (in development to manage processes)
57-
- [Haml](http://haml.info/)
57+
- [Haml](http://haml.info/) - and [Hamlit](https://github.com/k0kubun/hamlit), which is faster haml
5858
- [dotenv-rails](https://github.com/bkeepers/dotenv) (load environmental variables - .env is in .gitignore, so it isn't committed)
5959
- [Bootstrap](http://getbootstrap.com/)
6060
- Postgres
@@ -66,6 +66,7 @@ If you want to change the name of the app, swap out:
6666
- `GrapeDoorkeeper` in [config/application.rb](config/application.rb)
6767
- `grape-doorkeeper` in [config/database.yml](config/database.yml) (multiple instances)
6868
- `grape-doorkeeper` in [config/initializers/session_store.rb](config/initializers/session_store.rb)
69+
- Do a project wide search of `/grape.doorkeeper/i` to catch any lingering ones like [api_v1.html.haml](app/views/documentation/api_v1.html.haml)
6970

7071

7172
## Testing

app/controllers/api/base.rb

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
1+
require 'grape_logging'
2+
13
module API
2-
class Dispatch < Grape::API
3-
mount API::V1::Root
4-
format :json
5-
route :any, '*path' do
6-
Rack::Response.new({message: 'Not found'}.to_json, 404).finish
4+
class Base < Grape::API
5+
use GrapeLogging::Middleware::RequestLogger, instrumentation_key: 'grape_key',
6+
include: [GrapeLogging::Loggers::FilterParameters.new]
7+
mount API::V1::RootV1
8+
9+
def self.respond_to_error(e)
10+
logger.error e unless Rails.env.test? # Breaks tests...
11+
eclass = e.class.to_s
12+
message = "OAuth error: #{e}" if eclass =~ /WineBouncer::Errors/
13+
opts = { error: message || e.message }
14+
opts[:trace] = e.backtrace[0, 10] unless Rails.env.production?
15+
Rack::Response.new(opts.to_json, status_code_for(e, eclass), {
16+
'Content-Type' => 'application/json',
17+
'Access-Control-Allow-Origin' => '*',
18+
'Access-Control-Request-Method' => '*'
19+
}).finish
720
end
8-
end
921

10-
Base = Rack::Builder.new do
11-
use API::Logger
12-
run API::Dispatch
22+
def self.status_code_for(error, eclass)
23+
if eclass =~ /OAuthUnauthorizedError/
24+
401
25+
elsif eclass =~ /OAuthForbiddenError/
26+
403
27+
elsif (eclass =~ /RecordNotFound/) || (error.message =~ /unable to find/i)
28+
404
29+
else
30+
(error.respond_to? :status) && error.status || 500
31+
end
32+
end
1333
end
14-
end
34+
end

app/controllers/api/logger.rb

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)