Class: Api::ResourcesController

Inherits:
ApiController
  • Object
show all
Defined in:
app/controllers/api/resources_controller.rb

Overview

TODO: Split this file: one part for providers, one for consumers!

Instance Method Summary collapse

Instance Method Details

#createObject

Creates resource consumer on provider or consumer. This action does not care if a resource already exists on consumer.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/api/resources_controller.rb', line 8

def create
  if provider?
    instance.add_resource_consumer(params[:service], params[:realm])
    render(:json => {:resource => JSON.generate(instance.resourceable_hash)})
  else
    if instance
      instance.update_resource_attributes(params[:resource])
    else
      attributes = {:resource_uuid => params[:uuid], :resource_attributes => JSON.parse(params[:resource])}
      attributes[:realm_uuid] = params[:realm] if klass_with_realm?
      klass.create!(attributes)
    end
    render(:nothing => true, :status => :no_content)
  end
end

#destroyObject

Removes a resource consumer from provider or consumer.



36
37
38
39
40
41
42
43
# File 'app/controllers/api/resources_controller.rb', line 36

def destroy
  if provider?
    instance.remove_resource_consumer(params[:service], params[:realm])
  else
    instance.destroy_without_callback
  end
  render(:nothing => true, :status => :no_content)
end

#updateObject

Updates resource on consumer.



25
26
27
28
29
30
31
32
33
# File 'app/controllers/api/resources_controller.rb', line 25

def update
  begin
    instance.update_resource_attributes(params['resource'])
    render(:nothing => true, :status => :no_content)
  rescue => e
    Rails.logger.error "Error while updating resource consumer:\n#{e.inspect}"
    render(:json => {:error => e}, :status => :bad_request)
  end
end