Module: PivotalTracker

Defined in:
lib/pivotal_shell.rb

Overview

fixing pivotal-tracker’s options encoding; it did not work with array filters

Class Method Summary collapse

Class Method Details

.encode_options(options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pivotal_shell.rb', line 15

def encode_options(options)
  return nil if !options.is_a?(Hash) || options.empty?
  options_strings = []
  # remove options which are not filters, and encode them as such
  [:limit, :offset].each do |o|
    options_strings << "#{CGI.escape(o.to_s)}=#{CGI.escape(options.delete(o).to_s)}" if options[o]
  end
  # assume remaining key-value pairs describe filters, and encode them as such.
  filters_string = options.map do |key, value|
    "#{CGI.escape(key.to_s)}%3A#{CGI.escape([value].flatten.map{|v| v=v.to_s; v.include?(' ') ? '"'+v+'"' : v}.join(','))}"
  end
  options_strings << "filter=#{filters_string.join('+')}" unless filters_string.empty?
  return "?#{options_strings.join('&')}"
end