Class: Elasticity::AwsUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/elasticity/aws_utils.rb

Class Method Summary collapse

Class Method Details

.aws_escape(param) ⇒ Object



7
8
9
10
11
# File 'lib/elasticity/aws_utils.rb', line 7

def self.aws_escape(param)
  param.to_s.gsub(/([^a-zA-Z0-9._~-]+)/n) do
    '%' + $1.unpack('H2' * $1.size).join('%').upcase
  end
end

.camelize(word) ⇒ Object



30
31
32
# File 'lib/elasticity/aws_utils.rb', line 30

def self.camelize(word)
  word.to_s.gsub(/\/(.?)/) { '::' + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
end

.convert_ruby_to_aws_v4(value) ⇒ Object

With the advent of v4 signing, we can skip the complex translation from v2 and ship the JSON over with nearly the same structure.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/elasticity/aws_utils.rb', line 15

def self.convert_ruby_to_aws_v4(value)
  case value
    when Array
      return value.map{|v| convert_ruby_to_aws_v4(v)}
    when Hash
      result = {}
      value.each do |k,v|
        result[camelize(k.to_s)] = convert_ruby_to_aws_v4(v)
      end
      return result
    else
      return value
  end
end