When a client class extends this module, its API configuration is parsed. For each operation in the API configuration, one client method is added.
Clients extending QueryJSON all have in common their method of serializing request (input) parameters and parsing response (output) JSON.
# File lib/aws/core/client/query_json.rb, line 28 def self.extended base base.send(:include, ErrorParser) base.send(:define_client_methods) end
@return [Hash<Symbol,OptionGrammar>] Returns a hash option
parsers. Hash keys are client method names and hash values are {OptionGrammar} objects.
@private
# File lib/aws/core/client/query_json.rb, line 37 def option_parsers @option_parsers ||= {} end
# File lib/aws/core/client/query_json.rb, line 56 def define_client_method method_name, operation add_client_request_method(method_name) do configure_request do |request, options| parser = self.class.option_parsers[method_name] x_amz_target = self.class::TARGET_PREFIX + operation request.headers["content-type"] = "application/x-amz-json-1.0" request.headers["x-amz-target"] = x_amz_target request.body = parser.to_json(options) end process_response do |response| response_body = response.http_response.body response_body = "{}" if response_body == "" data = JSON.load(response_body) MetaUtils.extend_method(response, :data) { data } end simulate_response do |response| data = {} MetaUtils.extend_method(response, :data) { data } end end end
Enumerates through the operations specified in the API configuration (yaml configuration file found in lib/api_config/) and defines one request method per operation.
# File lib/aws/core/client/query_json.rb, line 46 def define_client_methods api_config[:operations].each do |op| method_name = op[:method] option_parsers[method_name] = OptionGrammar.customize(op[:inputs]) end end