module Fourteeninch class Customers def self.get_params print "Email: " new_email = $stdin.gets.chomp print "Name: " new_name = $stdin.gets.chomp print "Company: : " new_company = $stdin.gets.chomp print "Phone: " new_phone = $stdin.gets.chomp print "Address 1: " new_address1 = $stdin.gets.chomp print "Address 2: " new_address2 = $stdin.gets.chomp print "City: " new_city = $stdin.gets.chomp print "State: " new_state = $stdin.gets.chomp print "Country: " new_country = $stdin.gets.chomp print "Zip Code: " new_zip = $stdin.gets.chomp params = {} params.merge!(email: new_email) if new_email != "" params.merge!(name: new_name) if new_name != "" params.merge!(company: new_company) if new_company != "" params.merge!(phone: new_phone) if new_phone != "" params.merge!(address1: new_address1) if new_address1 != "" params.merge!(address2: new_address2) if new_address2 != "" params.merge!(city: new_city) if new_city != "" params.merge!(state: new_state) if new_state != "" params.merge!(country: new_country) if new_country != "" params.merge!(zip: new_zip) if new_zip != "" return params end def self.edit_customer(customer) puts "\n\n Edit Customer Information\n=================\n\n" puts "LEAVE A FIELD BLANK FOR NO CHANGES\n" params = get_params puts "\n\nUpdating customer ...." customer = Fourteeninch::Client.put('customers/' + customer['id'].to_s, params) if customer && customer.is_a?(Hash) & customer.has_key?('id') puts "done" else puts "Some error happend!! please try again" end Fourteeninch::Core.press_a_key return 11 end def self.new_customer puts "\n\n Create a new Customer\n===================" params = get_params customer = Fourteeninch::Client.post('customers', params) if customer && customer.is_a?(Hash) && customer.has_key?('id') puts "Customer created" Fourteeninch::Core.press_a_key return show_customer(customer) else puts "Some error happend!! please try again" Fourteeninch::Core.press_a_key return 1 end end def self.show_customer(customer) Fourteeninch::Core.clear puts "\n\n Customer Information\n=================" puts " ID: #{customer['id']}" puts " Email: #{customer['email']}" puts " Name: #{customer['name']}" puts " Company: #{customer['company']}" puts " Phone: #{customer['phone']}" puts " Address 1: #{customer['address1']}" puts " Address 2: #{customer['address2']}" puts " City: #{customer['city']}" puts " State: #{customer['state']}" puts " Country: #{customer['country']}" puts " ZIP code: #{customer['zip']}" puts "\n\n" puts "Do you want to edit this customer?[Yes/No]" edit_choice = $stdin.gets.chomp while !(edit_choice == "Yes" || edit_choice == "No" || edit_choice == "yes" || edit_choice == "no") puts "Do you want to edit this customer?[Yes/No]" edit_choice = $stdin.gets.chomp end if edit_choice == "No" || edit_choice == "no" return 11 elsif edit_choice == "Yes" || edit_choice == "yes" edit_customer(customer) end end def self.list_customers puts "Retrieving customers....\n\n" customers = Fourteeninch::Client.get('customers') puts"\nAll Customers:\n=================\n\n" if customers && customers.is_a?(Array) && customers.count > 0 customers.each do |c| puts (" " * (5 - c['id'].to_s.length)) + c['id'].to_s + ". " + c['name'].to_s end else puts "No Customers found!" end print "\n\nTo view, edit, or delete a customer, enter thier ID now. (Or enter `0` to exit): " customer_choice = $stdin.gets.chomp if customer_choice == "0" return 1 elsif customer_choice == "" return 11 else customer = Fourteeninch::Client.get('customers/' + customer_choice) if customer && customer.is_a?(Hash) && customer.has_key?('id') self.show_customer(customer) return 11 end end end def self.customers_menu puts Fourteeninch::Screens.customer_intro print 'Enter command number: ' customer_choice = $stdin.gets.chomp case customer_choice when '1' return 11 when '2' return 12 when '0' return 0 else return 1 end end def self.invoices clear puts "Invoices" end end end