Module: ActsAsApi::Base::InstanceMethods

Defined in:
lib/acts_as_api/base.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) as_api_response(api_template, options = {})

Creates the api response of the model and returns it as a Hash. Will raise an exception if the passed api template is not defined for the model



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/acts_as_api/base.rb', line 59

def as_api_response(api_template, options = {})
  api_attributes = self.class.api_accessible_attributes(api_template)
  raise ActsAsApi::TemplateNotFoundError.new("acts_as_api template :#{api_template.to_s} was not found for model #{self.class}") if api_attributes.nil?

  before_api_response(api_template)
  response_hash = around_api_response(api_template) do
    api_attributes.to_response_hash(self, api_attributes, options)
  end
  after_api_response(api_template)

  response_hash
end