lib/pivotal-tracker.rb in pivotal-tracker-0.3.0 vs lib/pivotal-tracker.rb in pivotal-tracker-0.3.1

- old
+ new

@@ -2,10 +2,11 @@ require 'rest_client' require 'happymapper' require 'nokogiri' +require File.join(File.dirname(__FILE__), 'pivotal-tracker', 'validation') require File.join(File.dirname(__FILE__), 'pivotal-tracker', 'extensions') require File.join(File.dirname(__FILE__), 'pivotal-tracker', 'proxy') require File.join(File.dirname(__FILE__), 'pivotal-tracker', 'client') require File.join(File.dirname(__FILE__), 'pivotal-tracker', 'project') require File.join(File.dirname(__FILE__), 'pivotal-tracker', 'attachment') @@ -20,20 +21,18 @@ # define error types class ProjectNotSpecified < StandardError; end def self.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))}" if options[o] - end - # assume remaining key-value pairs describe filters, and encode them as such. - filters_string = options.map do |key, value| - [value].flatten.map {|v| "#{CGI.escape(key.to_s)}%3A#{CGI.escape(v)}"}.join('&filter=') - end - options_strings << "filter=#{filters_string}" unless filters_string.empty? - return "?#{options_strings.join('&')}" + options_strings = options.inject({}) do |m, (k,v)| + if [:limit, :offset].include?(k.to_sym) + m.update k => v + else + filter_query = %{#{k}:#{[v].flatten.join(",")}} + m.update :filter => (m[:filter] ? "#{m[:filter]} #{filter_query}" : filter_query) + end + end.map {|k,v| "#{k}=#{CGI.escape(v.to_s)}"} + + %{?#{options_strings.join("&")}} unless options_strings.empty? end end