Sha256: bbb1bf11924c7bdaea5f8a481bdc54439158ef3a8b3c65cdd6a038e3d45c2b79

Contents?: true

Size: 1.45 KB

Versions: 14

Compression:

Stored size: 1.45 KB

Contents

module Desk
  class Client
    module Customer

      def customer_endpoints
        [ :list, :show, :create, :update, :search ]
      end

      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

      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

      def customer_add_address(customer, address, type = "home")
        customer_add_key("addresses", customer, address, type)
      end

      def customer_delete_address(customer, *args)
        customer_delete_key("addresses", customer, args)
      end

      def customer_add_email(customer, email, type = "home")
        customer_add_key("emails", customer, email, type)
      end

      def customer_delete_email(customer, *args)
        customer_delete_key("emails", customer, args)
      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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
desk-1.2.0 lib/desk/client/customer.rb
desk-1.1.1 lib/desk/client/customer.rb
desk-1.1.0 lib/desk/client/customer.rb
desk-1.0.10 lib/desk/client/customer.rb
desk-1.0.9 lib/desk/client/customer.rb
desk-1.0.8 lib/desk/client/customer.rb
desk-1.0.7 lib/desk/client/customer.rb
desk-1.0.6 lib/desk/client/customer.rb
desk-1.0.5 lib/desk/client/customer.rb
desk-1.0.4 lib/desk/client/customer.rb
desk-1.0.3 lib/desk/client/customer.rb
desk-1.0.2 lib/desk/client/customer.rb
desk-1.0.1 lib/desk/client/customer.rb
desk-1.0.0 lib/desk/client/customer.rb