Class: AWS::EC2::Client
- Inherits:
-
Object
- Object
- AWS::EC2::Client
- Defined in:
- lib/aws/ec2/client.rb
Constant Summary
Constants included from AWS::EC2
Instance Method Summary collapse
- #camelize(key) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #method_missing(method_name, *args) ⇒ Object
Methods included from Parser
Methods included from Request
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 |
# File 'lib/aws/ec2/client.rb', line 12 def initialize( = {}) @access_key_id = [:access_key_id] @secret_access_key = [:secret_access_key] @region = [:region] @debug = [:debug] || false end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/aws/ec2/client.rb', line 19 def method_missing(method_name, *args) action = camelize(method_name) config = EC2::API.find{|x, y| y[:methods].include?(method_name.to_sym)} raise ArgumentError, "Unknown Method: #{method_name}" unless config host = config.last[:host] regions = config.last[:regions] || [] host = @region + '.' + host if @region and regions.include?(@region) version = config.last[:version] = args[0] || {} .merge!(:action => action, :version => version) = {} .each{|key, value| [camelize(key).to_sym] = value} puts "calling host=#{host}, params=#{.inspect}" if @debug xml_response = aws_request(host, ) parse(xml_response) end |
Instance Method Details
#camelize(key) ⇒ Object
42 43 44 |
# File 'lib/aws/ec2/client.rb', line 42 def camelize(key) key.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase } end |