Module: MisarMail::Core::Query

Defined in:
lib/misar_mail/core/query.rb

Overview

Query-string encoding shared by every generated GET/DELETE method.

Class Method Summary collapse

Class Method Details

.encode(params) ⇒ Object

Returns "" for an empty bag so a generated call site can always append unconditionally. Nil values are dropped so optional filters stay out of the URL entirely rather than being sent as the string "".



12
13
14
15
16
17
18
# File 'lib/misar_mail/core/query.rb', line 12

def self.encode(params)
  return "" if params.nil? || params.empty?

  pairs = params.reject { |_, v| v.nil? }
                .map { |k, v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" }
  pairs.empty? ? "" : "?#{pairs.join('&')}"
end