Module: Fakecrm::Events

Included in:
Server
Defined in:
lib/fakecrm/server/events.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



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
# File 'lib/fakecrm/server/events.rb', line 11

def self.included(base)
  base.class_eval do

    get '/crm/api/events.?:format?' do
      fetch_many(Event)
    end

    get '/crm/api/events/search.?:format?' do
      search(Event, [:event_set, :kind], [:title],
             params.fetch("sort_by", :updated_at).to_sym,
             params.fetch("sort_order", 'asc').to_s)
    end

    get '/crm/api/events/:id.?:format?' do |id, _|
      fetch_one(Event, id.to_i)
    end

    post '/crm/api/events.?:format?' do
      create_one(Event, event_params)
    end

    put '/crm/api/events/:id.?:format?' do |id, _|
      update_one(Event, id.to_i, event_params)
    end

    delete '/crm/api/events/:id.?:format?' do |id|
      destroy_one(Event, id.to_i)
    end

  end
end

Instance Method Details

#event_paramsObject



5
6
7
8
9
# File 'lib/fakecrm/server/events.rb', line 5

def event_params
  event = params["event"].dup
  event.delete("name")
  event
end