Class: ForestAdminRpcAgent::Routes::Create

Inherits:
BaseRoute
  • Object
show all
Defined in:
lib/forest_admin_rpc_agent/routes/create.rb

Instance Method Summary collapse

Methods inherited from BaseRoute

#build_rails_response, #register_rails, #register_sinatra, #registered

Constructor Details

#initializeCreate

Returns a new instance of Create.



6
7
8
# File 'lib/forest_admin_rpc_agent/routes/create.rb', line 6

def initialize
  super('rpc/:collection_name/create', 'post', 'rpc_create')
end

Instance Method Details

#handle_request(args) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/forest_admin_rpc_agent/routes/create.rb', line 10

def handle_request(args)
  return {} unless args[:params]['collection_name']

  datasource = ForestAdminRpcAgent::Facades::Container.datasource
  collection = get_collection_safe(datasource, args[:params]['collection_name'])

  [collection.create(args[:caller], args[:params]['data'].first)]
end