module Oss::Util
Public Instance Methods
camelize(str)
click to toggle source
# File lib/oss/util.rb, line 5 def camelize(str) str.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } end
hash_filter(input_hash, key_map, target_hash = Hash.new)
click to toggle source
# File lib/oss/util.rb, line 9 def hash_filter(input_hash, key_map, target_hash = Hash.new) key_map.each do |key, value| unless input_hash[key].nil? target_hash[value] = input_hash[key] end end target_hash end
oss_headers_to_s(input_hash, key_map)
click to toggle source
x-oss:value
# File lib/oss/util.rb, line 19 def oss_headers_to_s(input_hash, key_map) header_array = Array.new # sort by hash value sorted = Hash[key_map.sort_by{|k,v| v}] sorted.each do |key, value| unless input_hash[key].nil? header_array << "#{value}:#{input_hash[key]}" end end header_array.join("\n") end
set_query_string(path, query)
click to toggle source
# File lib/oss/util.rb, line 33 def set_query_string(path, query) return path if query.nil? attrs = Array.new new_path = "#{path}" # sort by hash value sorted = Hash[query.sort_by{|k,v| k}] sorted.each do |k, v| # query key ruby hash _ to - attrs << "#{k.to_s.gsub('_', '-')}=#{v}" end # create http request query string if attrs.length > 0 new_path << "?#{attrs.join('&')}" end new_path end