Browse files

First attempt at implementing @zendesk.tickets(:view => 1234567) syntax.

  • Loading branch information...
1 parent 258198e commit 72ac60c8039484dacdb2153fb927b92592513daa Kamiel committed Jan 8, 2012
Showing with 14 additions and 3 deletions.
  1. +11 −1 lib/zendesk/client/tickets.rb
  2. +3 −2 lib/zendesk/collection.rb
View
12 lib/zendesk/client/tickets.rb
@@ -11,7 +11,17 @@ def tickets(*args)
class TicketsCollection < Collection
# TODO: document all the fields
def initialize(client, *args)
- super(client, :tickets, *args)
+ query = args.last.is_a?(Hash) ? args.pop : {}
+ id = args.shift
+
+ if view_id = query.delete(:view)
+ raise ArgumentError "cannot specify ticket id and view id in the same query" unless id.nil?
+
+ id = view_id
+ query[:path] = 'rules'
+ end
+
+ super(client, :tickets, id, query)
end
def views
View
5 lib/zendesk/collection.rb
@@ -17,12 +17,13 @@ def initialize(client, resource, *args)
@client = client
@resource = resource.to_s.singularize
@query = args.last.is_a?(Hash) ? args.pop : {}
+ @query[:path] ||= resource.to_s
case id = args.shift
when nil
- @query[:path] = resource.to_s
+ # do nothing
when Integer
- @query[:path] = "#{resource}/#{id}"
+ @query[:path] = "#{@query[:path]}/#{id}"
else
raise ArgumentError, "argument must be a numeric id."
end

0 comments on commit 72ac60c

Please sign in to comment.