Class: ApiCanon::DocumentedAction
- Inherits:
-
Object
- Object
- ApiCanon::DocumentedAction
- Defined in:
- lib/api_canon/documented_action.rb
Instance Attribute Summary collapse
-
#action_name ⇒ Object
readonly
Returns the value of attribute action_name.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#response_codes ⇒ Object
readonly
Returns the value of attribute response_codes.
Instance Method Summary collapse
-
#describe(desc) ⇒ Object
The describe method is used as a DSL method in the document_method block, Use it to describe your API action.
-
#initialize(action_name) ⇒ DocumentedAction
constructor
A new instance of DocumentedAction.
-
#param(param_name, options = {}) ⇒ Object
The param method describes and gives examples for the parameters your API action can take.
-
#response_code(code, desc = "") ⇒ Object
The response_code method will be used as a DSL method in the document_method block to describe what you mean when your action returns the given response code.
Constructor Details
#initialize(action_name) ⇒ DocumentedAction
Returns a new instance of DocumentedAction.
4 5 6 7 8 9 10 11 12 |
# File 'lib/api_canon/documented_action.rb', line 4 def initialize(action_name) @action_name = action_name @params={} # TODO: This should check routes to see if params[:format] is expected @params[:format] = DocumentedParam.new :format, :default => :json, :example_values => [:json, :xml], :type => :string, :description => "The requested format of the response." @response_codes={} end |
Instance Attribute Details
#action_name ⇒ Object (readonly)
Returns the value of attribute action_name.
3 4 5 |
# File 'lib/api_canon/documented_action.rb', line 3 def action_name @action_name end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
3 4 5 |
# File 'lib/api_canon/documented_action.rb', line 3 def description @description end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'lib/api_canon/documented_action.rb', line 3 def params @params end |
#response_codes ⇒ Object (readonly)
Returns the value of attribute response_codes.
3 4 5 |
# File 'lib/api_canon/documented_action.rb', line 3 def response_codes @response_codes end |
Instance Method Details
#describe(desc) ⇒ Object
The describe method is used as a DSL method in the document_method block, Use it to describe your API action. the generated API documentation page.
##Examples:
“‘ruby document_method :index do
describe "This action returns a filtered tree of categories based on the parameters given in the request."
end “‘
73 74 75 |
# File 'lib/api_canon/documented_action.rb', line 73 def describe(desc) @description = desc end |
#param(param_name, options = {}) ⇒ Object
The param method describes and gives examples for the parameters your API action can take. bit in params Valid keys are:
-
default: The default value to fill in for this parameter
-
example_values: Example values to show. Use when the input is unconstrained.
-
values: Valid values to use. Use when the input is constrained.
-
type: The expected type of the value(s) of this param, e.g. :string
-
description: A friendly description of what this parameter does or is used for.
-
multiple: Can this parameter be used multiple times? I.e. Array values.
##Examples:
“‘ruby document_method :index do
param :hierarchy_level, :values => 1..4, :type => :integer, :default => 1, :description => "Maximum depth to include child categories"
param :category_codes, :type => :array, :multiple => true, :example_values => Category.online.enabled.super_categories.all(:limit => 5, :select => :code).map(&:code), :description => "Return only categories for the given category codes", :default => 'mens-fashion-accessories'
end “‘
38 39 40 |
# File 'lib/api_canon/documented_action.rb', line 38 def param(param_name, ={}) @params[param_name] = DocumentedParam.new param_name, end |
#response_code(code, desc = "") ⇒ Object
The response_code method will be used as a DSL method in the document_method block to describe what you mean when your action returns the given response code. It currently does nothing. ##Examples:
“‘ruby document_method :index do
response_code 200, "Everything worked"
response_code 404, "Either the requested product or category could not be found"
end “‘
56 57 58 |
# File 'lib/api_canon/documented_action.rb', line 56 def response_code(code, desc="") @response_codes[code] = desc end |