Class: Twitter::REST::FormEncoder

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter/rest/form_encoder.rb

Constant Summary collapse

UNESCAPED_CHARS =
/[^a-z0-9\-._~]/i

Class Method Summary collapse

Class Method Details

.encode(data) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/twitter/rest/form_encoder.rb', line 6

def self.encode(data)
  data.collect do |k, v|
    if v.nil?
      ::URI::DEFAULT_PARSER.escape(k.to_s, UNESCAPED_CHARS)
    elsif v.respond_to?(:to_ary)
      v.to_ary.collect do |w|
        str = ::URI::DEFAULT_PARSER.escape(k.to_s, UNESCAPED_CHARS)
        unless w.nil?
          str << "="
          str << ::URI::DEFAULT_PARSER.escape(w.to_s, UNESCAPED_CHARS)
        end
      end.join("&")
    else
      str = ::URI::DEFAULT_PARSER.escape(k.to_s, UNESCAPED_CHARS)
      str << "="
      str << ::URI::DEFAULT_PARSER.escape(v.to_s, UNESCAPED_CHARS)
    end
  end.join("&")
end