Module: RightScale::CloudApi::Mixin::QueryApiPatterns::ClassMethods
- Defined in:
- lib/base/helpers/query_api_patterns.rb
Overview
Query API patterns help one to simulate the Query API type through the REST API
When the REST API is powerfull enough it is not easy to code it becaue one have to worry about the path, the URL parameters, the headers and the body, when in the QUERY API all you need to worry about are the URL parameters.
The patterns described below help you to build methods that will take a linear set of parameters (usially) a hash and put then into the proper positions into the URL, headers or body.
TODO :add an example that would compare REST vs QUERY calls
There are 2 ways to define a Query API pattern:
-
Manager class level:
We could use this when we define a new cloud handler. I dont see any use case right now because we can implement all we need now using the second way and Wrappers.
-
Manager instance level: this is where Wrappers come.
Instance Method Summary collapse
-
#query_api_pattern(method_name, verb, path = '', opts = {}, storage = nil, &block) ⇒ void
Defines a new query pattern.
-
#query_api_patterns ⇒ Array
The method returns a list of pattternd defined in the current class.
Instance Method Details
#query_api_pattern(method_name, verb, path = '', opts = {}, storage = nil, &block) ⇒ void
This method returns an undefined value.
Defines a new query pattern
TODO: :explain options, callbacks, etc
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/base/helpers/query_api_patterns.rb', line 168 def query_api_pattern(method_name, verb, path='', opts={}, storage=nil, &block) opts = opts.dup method_name = method_name.to_s storage ||= query_api_patterns before = opts.delete(:before) after = opts.delete(:after) || block defaults = opts.delete(:defaults) || {} params = opts.delete(:params) || {} headers = opts.delete(:headers) || {} = opts.delete(:options) || {} body = opts.delete(:body) || nil # Complain if there are any unused keys left. fail(Error.new("#{method_name.inspect} pattern: unsupported key(s): #{opts.keys.map{|k| k.inspect}.join(',')}")) if opts.any? # Store the new pattern. storage[method_name] = { :verb => verb.to_s.downcase.to_sym, :path => path.to_s, :before => before, :after => after, :defaults => defaults, :params => params, :headers => HTTPHeaders::new(headers), :options => , :body => body } end |
#query_api_patterns ⇒ Array
The method returns a list of pattternd defined in the current class
143 144 145 |
# File 'lib/base/helpers/query_api_patterns.rb', line 143 def query_api_patterns @query_api_patterns ||= {} end |