Skip to content

Commit

Permalink
Improved PivotalTracker.find, so that it works with multiple filters,…
Browse files Browse the repository at this point in the history
… as well as just searching by a string
  • Loading branch information
technicalpickles committed Jun 6, 2009
1 parent 430af7f commit 7339483
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
23 changes: 6 additions & 17 deletions lib/pivotal-tracker.rb
@@ -1,6 +1,7 @@
require 'restclient'
require 'happymapper'
require 'builder'
require 'cgi'


# initial definition, to avoid circular dependencies when declaring happymappings
Expand All @@ -17,11 +18,8 @@ class PivotalTracker
def initialize(project_id, token, options = {})
@project_id, @token = project_id, token

@base_url = if options[:use_ssl]
"https://www.pivotaltracker.com/services/v2"
else
"http://www.pivotaltracker.com/services/v2"
end
@base_url = "http://www.pivotaltracker.com/services/v2"
@base_url.gsub! 'http', 'https' if options[:use_ssl]
end

def project
Expand All @@ -39,18 +37,9 @@ def iterations
Iteration.parse(response)
end

# would ideally like to pass a size, aka :all to limit search
def find(filters = {})
unless filters.empty?
filter_string = "?filter="
filters.each do |key, value|
filter_string << CGI::escape("#{key}:\"#{value}\"")
end
else
filter_string = ""
end

response = stories_resource[filter_string].get
def find(*filters)
filter_query = CGI::escape filters.to_pivotal_filter
response = stories_resource["?filter=#{filter_query}"].get
Story.parse(response)
end

Expand Down
30 changes: 30 additions & 0 deletions lib/pivotal-tracker/extensions.rb
Expand Up @@ -3,10 +3,40 @@ class String
def to_param
self
end

def to_pivotal_filter
self.inspect
end
end

class Integer
def to_param
to_s
end

def to_pivotal_filter
to_s.inspect
end
end

class Hash
def to_pivotal_filter
collect do |key, value|
%Q{#{key}:"#{value}"}
end.join(' ')
end
end

class NilClass
def to_pivotal_filter
""
end
end

class Array
def to_pivotal_filter
collect do |each|
each.to_pivotal_filter
end.join(' ')
end
end

0 comments on commit 7339483

Please sign in to comment.