lib/desk/client/customer.rb in desk-0.3.3 vs lib/desk/client/customer.rb in desk-1.0.0
- old
+ new
@@ -1,146 +1,48 @@
module Desk
class Client
- # Defines methods related to customers
module Customer
- # Returns extended information of customers
- #
- # @option options [Boolean, String, Integer]
- # @example Return extended information for customers
- # Desk.customers
- # Desk.customers(:since_id => 12345, :count => 5)
- # @format :json
- # @authenticated true
- # @see http://dev.desk.com/docs/api/customers
- def customers(*args)
- options = args.last.is_a?(Hash) ? args.pop : {}
- response = get("customers",options)
- response
+
+ def customer_endpoints
+ [ :list, :show, :create, :update, :search ]
end
- # Returns extended information on a single customer
- #
- # @option options [String]
- # @example Return extended information for customer 12345
- # Desk.customer(12345)
- # @format :json
- # @authenticated true
- # @see http://dev.desk.com/docs/api/customers/show
- def customer(id)
- response = get("customers/#{id}")
- response.customer
+ def customer_add_key(key, customer, value, type)
+ customer.send(key) << {:value => value, :type => type}
+ customer = Desk.update_customer(customer.id, {key.to_sym => customer.send(key)})
end
- # Create a new customer
- #
- # @option options [String]
- # @example Return extended information for 12345
- # Desk.create_customer(:name => "Chris Warren", :twitter => "cdwarren")
- # @format :json
- # @authenticated true
- # @see http://dev.desk.com/docs/api/customers/create
- def create_customer(*args)
- options = args.last.is_a?(Hash) ? args.pop : {}
- response = post("customers",options)
- if response['success']
- return response['results']['customer']
- else
- return response
+ def customer_delete_key(key, customer, *args)
+ a = args.last.is_a?(Array) ? args.pop : args
+ customer.send(key).delete_if do |item|
+ a.include?(item.type) || a.include?(item.value)
end
+ customer = Desk.update_customer(customer.id, {key.to_sym => customer.send(key)})
end
- # Update a customer
- #
- # @option options [String]
- # @example Return extended information for 12345
- # Desk.update_customer(12345, :name => "Christopher Warren")
- # @format :json
- # @authenticated true
- # @see http://dev.desk.com/docs/api/customers/update
- def update_customer(id, *args)
- options = args.last.is_a?(Hash) ? args.pop : {}
- response = put("customers/#{id}",options)
- if response['success']
- return response['results']['customer']
- else
- return response
- end
+ def customer_add_address(customer, address, type = "home")
+ customer_add_key("addresses", customer, address, type)
end
- # Create a new customer email
- #
- # @option options [String]
- # @example Return extended information for 12345
- # Desk.create_customer_email(12345, "foo@example.com")
- # @format :json
- # @authenticated true
- # @see http://dev.desk.com/docs/api/customers/emails/create
- def create_customer_email(id, email, *args)
- options = args.last.is_a?(Hash) ? args.pop : {}
- options.merge!({:email => email})
- response = post("customers/#{id}/emails",options)
- if response['success']
- return response['results']['email']
- else
- return response
- end
+ def customer_delete_address(customer, *args)
+ customer_delete_key("addresses", customer, args)
end
- # Update a customer's email
- #
- # @option options [String]
- # @example Return extended information for 12345
- # Desk.update_customer_email(12345, 12345, :email => "foo@example.com")
- # Desk.update_customer_email(12345, 12345, :customer_contact_type => "work")
- # @format :json
- # @authenticated true
- # @see http://dev.desk.com/docs/api/customers/emails/update
- def update_customer_email(id, email_id, *args)
- options = args.last.is_a?(Hash) ? args.pop : {}
- response = put("customers/#{id}/emails/#{email_id}",options)
- if response['success']
- return response['results']['email']
- else
- return response
- end
+ def customer_add_email(customer, email, type = "home")
+ customer_add_key("emails", customer, email, type)
end
- # Create a new customer phone number
- #
- # @option options [String]
- # @example Return extended information for 12345
- # Desk.create_customer_phone(12345, "555-368-7147")
- # @format :json
- # @authenticated true
- # @see http://dev.desk.com/docs/api/customers/phones/create
- def create_customer_phone(id, phone, *args)
- options = args.last.is_a?(Hash) ? args.pop : {}
- options.merge!({:phone => phone})
- response = post("customers/#{id}/phones",options)
- if response['success']
- return response['results']['phone']
- else
- return response
- end
+ def customer_delete_email(customer, *args)
+ customer_delete_key("emails", customer, args)
end
- # Update a customer's phone number
- #
- # @option options [String]
- # @example Return extended information for 12345
- # Desk.update_customer_phone(12345, 12345, :phone => "555-368-7147")
- # Desk.update_customer_phone(12345, 12345, :customer_contact_type => "work")
- # @format :json
- # @authenticated true
- # @see http://dev.desk.com/docs/api/customers/phones/update
- def update_customer_phone(id, phone_id, *args)
- options = args.last.is_a?(Hash) ? args.pop : {}
- response = put("customers/#{id}/phones/#{phone_id}",options)
- if response['success']
- return response['results']['phone']
- else
- return response
- end
+ def customer_add_phone_number(customer, phone_number, type = "home")
+ customer_add_key("phone_numbers", customer, phone_number, type)
end
+
+ def customer_delete_phone_number(customer, *args)
+ customer_delete_key("phone_numbers", customer, args)
+ end
+
end
end
end