lib/aliyun/ecs.rb in aliyun-api-0.0.9 vs lib/aliyun/ecs.rb in aliyun-api-0.1.0

- old
+ new

@@ -10,11 +10,13 @@ module Aliyun class ECS def initialize(options={}) 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] + Aliyun[:endpoint_url] = options[:endpoint_url] || Aliyun[:endpoint_url] + Aliyun[:request_parameters][:Version] = options[:version] || Aliyun[:version] + end 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 '_','' @@ -27,10 +29,11 @@ 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: #{rcex.to_s}\nrequest parameters: #{params.reject{|k,v| k==:AccessKeyId}}" + message = JSON.parse(rcex.response) + raise AliyunError.new "response error: [#{message['Message']}] #{rcex.to_s}\nrequest parameters: #{params.reject{|k,v| k==:AccessKeyId}}" rescue =>e raise AliyunError.new e.to_s end end