A web service API class specifies the methods that will be available for invocation for an API. It also contains metadata such as the method type signature hints.

It is not intended to be instantiated.

It is attached to web service implementation classes like ActionWebService::Base and ActionController::Base derivatives by using ClassMethods#web_service_api.

Methods
Included Modules
Public Class methods
api_method(name, options={})

API methods have a name, which must be the Ruby method name to use when performing the invocation on the web service object.

The signatures for the method input parameters and return value can by specified in options.

A signature is an array of one or more parameter specifiers. A parameter specifier can be one of the following:

  • A symbol or string of representing one of the Action Web Service base types. See ActionWebService::Signature for a canonical list of the base types.
  • The Class object of the parameter type
  • A single-element Array containing one of the two preceding items. This will cause Action Web Service to treat the parameter at that position as an array containing only values of the given type.
  • A Hash containing as key the name of the parameter, and as value one of the three preceding items

If no method input parameter or method return value signatures are given, the method is assumed to take no parameters and/or return no values of interest, and any values that are received by the server will be discarded and ignored.

Valid options:

:expects
Signature for the method input parameters
:returns
Signature for the method return value
:expects_and_returns
Signature for both input parameters and return value
    # File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 60
60:         def api_method(name, options={})
61:           unless options.is_a?(Hash)
62:             raise(ActionWebServiceError, "Expected a Hash for options")
63:           end
64:           validate_options([:expects, :returns, :expects_and_returns], options.keys)
65:           if options[:expects_and_returns]
66:             expects = options[:expects_and_returns]
67:             returns = options[:expects_and_returns]
68:           else
69:             expects = options[:expects]
70:             returns = options[:returns]
71:           end
72:           expects = canonical_signature(expects)
73:           returns = canonical_signature(returns)
74:           if expects
75:             expects.each do |type|
76:               type = type.element_type if type.is_a?(ArrayType)
77:               if type.type_class.ancestors.include?(ActiveRecord::Base) && !allow_active_record_expects
78:                 raise(ActionWebServiceError, "ActiveRecord model classes not allowed in :expects")
79:               end
80:             end
81:           end
82:           name = name.to_sym
83:           public_name = public_api_method_name(name)
84:           method = Method.new(name, public_name, expects, returns)
85:           write_inheritable_hash("api_methods", name => method)
86:           write_inheritable_hash("api_public_method_names", public_name => name)
87:         end
api_method_instance(method_name)

The Method instance for the given API method name, if any

     # File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 126
126:         def api_method_instance(method_name)
127:           api_methods[method_name]
128:         end
api_method_name(public_name)

The corresponding service method name for the given public method name

     # File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 110
110:         def api_method_name(public_name)
111:           api_public_method_names[public_name]
112:         end
api_methods()

A Hash containing all service methods on this API, and their associated metadata.

     # File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 116
116:         def api_methods
117:           read_inheritable_attribute("api_methods") || {}
118:         end
default_api_method_instance()

The Method instance for the default API method, if any

     # File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 131
131:         def default_api_method_instance
132:           return nil unless name = default_api_method
133:           instance = read_inheritable_attribute("default_api_method_instance")
134:           if instance && instance.name == name
135:             return instance
136:           end
137:           instance = Method.new(name, public_api_method_name(name), nil, nil)
138:           write_inheritable_attribute("default_api_method_instance", instance)
139:           instance
140:         end
has_api_method?(name)

Whether the given method name is a service method on this API

    # File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 90
90:         def has_api_method?(name)
91:           api_methods.has_key?(name)
92:         end
has_public_api_method?(public_name)

Whether the given public method name has a corresponding service method on this API

    # File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 96
96:         def has_public_api_method?(public_name)
97:           api_public_method_names.has_key?(public_name)
98:         end
public_api_method_instance(public_method_name)

The Method instance for the given public API method name, if any

     # File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 121
121:         def public_api_method_instance(public_method_name)
122:           api_method_instance(api_method_name(public_method_name))
123:         end
public_api_method_name(name)

The corresponding public method name for the given service method name

     # File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 101
101:         def public_api_method_name(name)
102:           if inflect_names
103:             name.to_s.camelize
104:           else
105:             name.to_s
106:           end
107:         end