Module: Dagger::Utils
- Defined in:
- lib/dagger.rb
Class Method Summary collapse
Class Method Details
.append_key(root_key, key) ⇒ Object
41 42 43 |
# File 'lib/dagger.rb', line 41 def self.append_key(root_key, key) root_key.nil? ? key : "#{root_key}[#{key.to_s}]" end |
.encode(obj, key = nil) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dagger.rb', line 27 def self.encode(obj, key = nil) if key.nil? && obj.is_a?(String) # && obj['='] return obj end case obj when Hash then obj.map { |k, v| encode(v, append_key(key,k)) }.join('&') when Array then obj.map { |v| encode(v, "#{key}[]") }.join('&') when nil then '' else "#{key}=#{URI.escape(obj.to_s)}" end end |
.parse_uri(uri) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/dagger.rb', line 18 def self.parse_uri(uri) raise ArgumentError.new("Empty URI") if uri.to_s.strip == '' uri = 'http://' + uri unless uri.to_s['http'] uri = URI.parse(uri) raise ArgumentError.new("Invalid URI: #{uri}") unless uri.is_a?(URI::HTTP) uri.path = '/' if uri.path == '' uri end |