-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_app.rb
63 lines (51 loc) · 1.37 KB
/
my_app.rb
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
require_relative 'config/application.rb'
module Fungileaks
class API < Grape::API
VERSION = 'v1'
version VERSION, using: :path
format :json
before do
header['Access-Control-Allow-Origin'] = '*'
header['Access-Control-Request-Method'] = '*'
end
resource :pickings do
desc 'List all pickings'
get do
Picking.all
end
desc 'List the last 10 pickings'
get :latest do
Picking.order_by('picked_at DESC').limit(10)
end
desc 'Return a picking by its ID'
route_param :id do
get do
Picking.find(params[:id])
end
end
desc 'Create a new picking'
params do
requires :picked_at, type: String, desc: 'The date you picked those'
requires :username, type: String, desc: 'Your desired user name'
requires :species, type: String, desc: 'The king of mushroom you picked'
requires :lat, type: BigDecimal, desc: 'Latitude'
requires :lng, type: BigDecimal, desc: 'Guess what ... Longitude'
end
post do
picking = Fungileaks::Picking.new declared(params)
picking.save!
picking
end
end
add_swagger_documentation api_version: VERSION
end
class Web < Sinatra::Base
get '/' do
'Hello World'
end
end
class App < Grape::API
mount Web
mount API
end
end