module EmmyHttp::Encoders
Public Instance Methods
encode_auth(userinfo)
click to toggle source
# File lib/emmy_http/client/encoders.rb, line 29 def encode_auth(userinfo) "Basic #{Base64.strict_encode64(userinfo)}" end
encode_body(encoding, body)
click to toggle source
# File lib/emmy_http/client/encoders.rb, line 33 def encode_body(encoding, body) require 'zlib' require 'stringio' case encoding when "gzip" wio = StringIO.new("w") begin w_gz = Zlib::GzipWriter.new(wio) w_gz.write(body) rescue raise EmmyHttp::EncoderError ensure w_gz.close end wio.string else body end end
escape(str)
click to toggle source
# File lib/emmy_http/client/encoders.rb, line 5 def escape(str) str.gsub(/([^a-zA-Z0-9_.-]+)/) { '%'+$1.unpack('H2'*$1.bytesize).join('%').upcase } end
param(k, v)
click to toggle source
# File lib/emmy_http/client/encoders.rb, line 21 def param(k, v) if v.is_a?(Array) v.map { |e| escape(k) + "[]=" + escape(e) }.join("&") else escape(k) + "=" + escape(v) end end
query(query)
click to toggle source
# File lib/emmy_http/client/encoders.rb, line 17 def query(query) query.map { |k, v| param(k, v) }.join('&') end
rfc3986(str)
click to toggle source
# File lib/emmy_http/client/encoders.rb, line 9 def rfc3986(str) str.gsub(/([!'()*]+)/m) { '%'+$1.unpack('H2'*$1.bytesize).join('%').upcase } end
www_form(enum)
click to toggle source
# File lib/emmy_http/client/encoders.rb, line 13 def www_form(enum) URI.encode_www_form(enum) end