Class: RestClient::Payload::UrlEncoded

Inherits:
Base
  • Object
show all
Defined in:
lib/restclient/payload.rb

Instance Method Summary collapse

Methods inherited from Base

#close, #flatten_params, #flatten_params_array, #initialize, #inspect, #read, #short_inspect, #size

Constructor Details

This class inherits a constructor from RestClient::Payload::Base

Instance Method Details

#build_stream(params = nil) ⇒ Object



141
142
143
144
145
146
# File 'lib/restclient/payload.rb', line 141

def build_stream(params = nil)
  @stream = StringIO.new(flatten_params(params).collect do |entry|
    "#{entry[0]}=#{handle_key(entry[1])}"
  end.join("&"))
  @stream.seek(0)
end

#handle_key(key) ⇒ Object

for UrlEncoded escape the keys



149
150
151
# File 'lib/restclient/payload.rb', line 149

def handle_key key
  URI.escape(key.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
end

#headersObject



153
154
155
# File 'lib/restclient/payload.rb', line 153

def headers
  super.merge({'Content-Type' => 'application/x-www-form-urlencoded'})
end