Permalink
Browse files

unatomic batch of progess

  • Loading branch information...
1 parent 2342dbb commit 3cc27ea9e2d4f30f184730f64c8f44725890e817 @deepthawtz committed Jul 27, 2011
Showing with 38 additions and 84 deletions.
  1. +2 −1 README.md
  2. +0 −54 lib/zendesk/client/paginator.rb
  3. +14 −14 lib/zendesk/client/tickets.rb
  4. +22 −15 lib/zendesk/client/users.rb
View
@@ -46,7 +46,8 @@ Users
@zendesk.users.per_page(100) # all users in account (v2 should accept `?per_page=NUMBER`)
@zendesk.users.page(2) # all users in account (v1 currently accepts `?page=NUMBER`)
@zendesk.users.next_page # all users in account (v1 currently accepts `?page=NUMBER`)
- @zendesk.users(:current) # currently authenticated user
+ @zendesk.users.current # currently authenticated user
+ @zendesk.users.me # currently authenticated user
@zendesk.users("Bobo") # all users with name matching all or part of "Bobo"
@zendesk.users(123) # return user=123
@zendesk.users("Bobo", :role => :admin) # all users with name matching all or part of "Bobo" who are admins
@@ -1,54 +0,0 @@
-module Zendesk
- module Paginator
- include Enumerable
-
- attr_reader :query
-
- def clear_cache
- @cache = nil
- @query = {}
- end
-
- # number of results to return per page
- def per_page(count=15)
- @query[:per_page] = count
- self
- end
-
- def page(number)
- @query[:page] = number
- self
- end
-
- # TODO: API v2
- # def next_page?
- # fetch if @cache.nil?
- # !!@cache["next_page"]
- # end
-
- # TODO: API v2
- # def fetch_next_page
- # if next_page?
- # @cache = get(@cache["next_page"])
- # end
- # end
-
- # fetches actual result of request
- def fetch(force=false)
- if @cache.nil? || force
- options = query.dup
- @cache = get(options.delete(:path), options)
- end
- @cache
- end
-
- # call block once for each element in self
- def each
- fetch.each {|result| yield result}
- end
-
- def [](idx)
- fetch[idx]
- end
- end
-end
@@ -28,38 +28,38 @@ def initialize(client, *args)
end
end
- # ## Update a ticket by id
+ # ## Create a ticket
#
# ### V1
#
- # @zendesk.tickets(123).update({:name => "Sort of Cool Guys"})
+ # @zendesk.tickets.create({:subject => "My phone fell in the toilet", :description => "HALP ME!"})
#
# # optional block syntax
- # @zendesk.tickets(123).update do |ticket|
- # ticket[:name] = "Just People"
- # ticket[:description] = "That's all"
+ # @zendesk.tickets.create do |ticket|
+ # ticket[:subject] = "My phone fell in the toilet"
+ # ticket[:description] = "HALP ME!"
# end
#
- def update(data={})
+ def create(data={})
yield data if block_given?
- do_put(@query.delete(:path), @query.merge(:ticket => data))
+ do_post(@query.delete(:path), @query.merge(:ticket => data))
end
- # ## Create a ticket
+ # ## Update a ticket by id
#
# ### V1
#
- # @zendesk.tickets.create({:name => "Cool Guys", :agents => [123, 456, 789]})
+ # @zendesk.tickets(123).update({:subject => "My phone fell in the toilet"})
#
# # optional block syntax
- # @zendesk.tickets.create do |ticket|
- # ticket[:name] = "Cool Guys"
- # ticket[:description] = "wish you could be this cool"
+ # @zendesk.tickets(123).update do |ticket|
+ # ticket[:subject] = "My phone fell in the toilet"
+ # ticket[:description] = "That's all"
# end
#
- def create(data={})
+ def update(data={})
yield data if block_given?
- do_post(@query.delete(:path), @query.merge(:ticket => data))
+ do_put(@query.delete(:path), @query.merge(:ticket => data))
end
# ## Delete ticket
@@ -7,7 +7,6 @@ module Users
#
# @zendesk.users - returns a list of users (limit 15)
# @zendesk.users.per_page(100) - returns a list of users (limit 15)
- # @zendesk.users(:current) - returns the currently authenticated user
# @zendesk.users(123) - returns the user with id=123
# @zendesk.users("Bob") - returns users with name matching all or part of "Bob"
# @zendesk.users("Bob", :role => :end_user) - returns users with name matching all or part of "Bob"
@@ -32,8 +31,6 @@ def initialize(client, *args)
case selection = args.shift
when nil
@query[:path] = "users"
- when :current
- @query[:path] = "users/current"
when Integer
@query[:path] = "users/#{selection}"
when String
@@ -42,21 +39,15 @@ def initialize(client, *args)
end
end
- # ## Update a user
- #
- # ### V1
+ # ## Get currently authenticated user
#
- # @zendesk.users(123).update({:name => "Wu Tang"})
+ # @zendesk.users.current
#
- # # optional block syntax
- # @zendesk.users(123).update do |user|
- # user[:email] = "hongkong@phooey.com"
- # end
- #
- def update(data={})
- yield data if block_given?
- do_put(@query.delete(:path), @query.merge(:user => data))
+ def current
+ @query[:path] += "/current"
+ self
end
+ alias current me
# ## Create a user
#
@@ -74,6 +65,22 @@ def create(data={})
do_post(@query.delete(:path), @query.merge(:user => data))
end
+ # ## Update a user
+ #
+ # ### V1
+ #
+ # @zendesk.users(123).update({:email => "hongkong@phooey.com"})
+ #
+ # # optional block syntax
+ # @zendesk.users(123).update do |user|
+ # user[:email] = "hongkong@phooey.com"
+ # end
+ #
+ def update(data={})
+ yield data if block_given?
+ do_put(@query.delete(:path), @query.merge(:user => data))
+ end
+
# ## Delete a user
#
# ### V1

0 comments on commit 3cc27ea

Please sign in to comment.