Class: Vayacondios::Server::EventHandler

Inherits:
DocumentHandler show all
Defined in:
lib/vayacondios/server/handlers/event_handler.rb

Instance Attribute Summary

Attributes inherited from DocumentHandler

#database, #log

Instance Method Summary collapse

Methods inherited from DocumentHandler

#action_successful, #base_create, #base_delete, #base_retrieve, #base_search, #base_update, #call, #initialize

Constructor Details

This class inherits a constructor from Vayacondios::Server::DocumentHandler

Instance Method Details

#create(params, document) ⇒ Object

Create an event.

Parameters:

  • params (Hash)

    routing information like ‘organization`, `topic,`, or `id`

  • document (Hash)

    the body of the document



8
9
10
11
12
# File 'lib/vayacondios/server/handlers/event_handler.rb', line 8

def create(params, document)
  Event.create(params, document) do |request|
    database.call(:insert, request)
  end
end

#delete(params, document) ⇒ Object

Delete a specific event.

Parameters:

  • params (Hash)

    routing information like ‘organization`, `topic,`, or `id`

  • document (Hash)

    the body of the document

Raises:

  • (Goliath::Validation::Error)

    if params do not have an id



30
31
32
33
34
35
36
# File 'lib/vayacondios/server/handlers/event_handler.rb', line 30

def delete(params, document)
  raise Goliath::Validation::BadRequestError.new('An <Id> is required to delete an Event') unless params[:id]
  Event.destroy(params, {}) do |request, options|
    database.call(:remove, request, options)
  end
  action_successful
end

#retrieve(params, document) ⇒ Object

Find and show a particular event.

Parameters:

  • params (Hash)

    routing information like ‘organization`, `topic,`, or `id`

  • document (Hash)

    the body of the document

Raises:

  • (Goliath::Validation::Error)

    if no event is found. Returns a 404.



19
20
21
22
23
# File 'lib/vayacondios/server/handlers/event_handler.rb', line 19

def retrieve(params, document)
  Event.find(params) do |request|
    database.call(:retrieve, request)
  end or raise Goliath::Validation::NotFoundError.new("Event with topic <#{params[:topic]}> and ID <#{params[:id]}> not found")
end