lib/aliyun/ecs.rb in aliyun-api-0.0.7 vs lib/aliyun/ecs.rb in aliyun-api-0.0.8

- old
+ new

@@ -13,23 +13,24 @@ Aliyun[:access_key_id] = options[:access_key_id] || Aliyun[:access_key_id] || ENV['ALIYUN_ACCESS_KEY_ID'] Aliyun[:access_key_secret] = options[:access_key_secret] || Aliyun[:access_key_secret] || ENV['ALIYUN_ACCESS_KEY_SECRET'] Aliyun[:endpoint_url] ||= options[:endpoint_url] end - def method_missing(method_name, *args) + def method_missing(method_name, *args,&block) super if /[A-Z]/ =~ method_name.to_s method_name = method_name.to_s.split('_').map{|w| w.capitalize }.join('').gsub '_','' - proxy_to_aliyun(method_name, args[0]) + proxy_to_aliyun(method_name, args[0],&block) end private - def proxy_to_aliyun(method_name, params) + def proxy_to_aliyun(method_name, params,&block) params = build_request_parameters method_name, params + block.call params if block begin res = RestClient.send Aliyun[:request_method].downcase, Aliyun[:endpoint_url], {:params => params,:verify_ssl => OpenSSL::SSL::VERIFY_PEER } return JSON.parse res.body if res.code == 200 rescue RestClient::Exception => rcex - raise AliyunError.new "response error code: #{rcex.response.code}\ndetails: #{rcex.response.body}\nrequest parameters: #{params.reject{|k,v| k==:AccessKeyId}}" + raise AliyunError.new "response error: #{rcex.to_s}\nrequest parameters: #{params.reject{|k,v| k==:AccessKeyId}}" rescue =>e raise AliyunError.new e.to_s end end