diff --git a/Gemfile b/Gemfile index 35de4a7f0e..c4651ac753 100644 --- a/Gemfile +++ b/Gemfile @@ -4,6 +4,7 @@ ruby '3.0.2' group :test do gem 'rspec' + gem 'twilio-ruby' gem 'simplecov', require: false, group: :test gem 'simplecov-console', require: false, group: :test end diff --git a/Gemfile.lock b/Gemfile.lock index 66064703c7..5730cc2f7d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -5,9 +5,37 @@ GEM ast (2.4.2) diff-lcs (1.4.4) docile (1.4.0) + faraday (1.10.0) + faraday-em_http (~> 1.0) + faraday-em_synchrony (~> 1.0) + faraday-excon (~> 1.1) + faraday-httpclient (~> 1.0) + faraday-multipart (~> 1.0) + faraday-net_http (~> 1.0) + faraday-net_http_persistent (~> 1.0) + faraday-patron (~> 1.0) + faraday-rack (~> 1.0) + faraday-retry (~> 1.0) + ruby2_keywords (>= 0.0.4) + faraday-em_http (1.0.0) + faraday-em_synchrony (1.0.0) + faraday-excon (1.1.0) + faraday-httpclient (1.0.1) + faraday-multipart (1.0.3) + multipart-post (>= 1.2, < 3) + faraday-net_http (1.0.1) + faraday-net_http_persistent (1.2.0) + faraday-patron (1.0.0) + faraday-rack (1.0.0) + faraday-retry (1.0.3) + jwt (2.3.0) + multipart-post (2.1.1) + nokogiri (1.13.3-arm64-darwin) + racc (~> 1.4) parallel (1.20.1) parser (3.0.2.0) ast (~> 2.4.1) + racc (1.5.1) rainbow (3.0.0) regexp_parser (2.1.1) rexml (3.2.5) @@ -36,6 +64,7 @@ GEM rubocop-ast (1.11.0) parser (>= 3.0.1.1) ruby-progressbar (1.11.0) + ruby2_keywords (0.0.5) simplecov (0.21.2) docile (~> 1.1) simplecov-html (~> 0.11) @@ -48,6 +77,10 @@ GEM simplecov_json_formatter (0.1.3) terminal-table (3.0.1) unicode-display_width (>= 1.1.1, < 3) + twilio-ruby (5.66.0) + faraday (>= 0.9, < 2.0) + jwt (>= 1.5, <= 2.5) + nokogiri (>= 1.6, < 2.0) unicode-display_width (2.0.0) PLATFORMS @@ -58,6 +91,7 @@ DEPENDENCIES rubocop (= 1.20) simplecov simplecov-console + twilio-ruby RUBY VERSION ruby 3.0.2p107 diff --git a/lib/TwilioTextMessenger.rb b/lib/TwilioTextMessenger.rb new file mode 100644 index 0000000000..37bf035bae --- /dev/null +++ b/lib/TwilioTextMessenger.rb @@ -0,0 +1,17 @@ +require 'twilio-ruby' + +class TwilioTextMessenger + attr_reader :message, :call + + def initialize + @message = message + account_sid = 'ACf27cbbcdf904e00bcf60428cfb4271c9' + auth_token = '18303ff4fddfac8208b8be0aab167886' + client = Twilio::REST::Client.new(account_sid, auth_token) + client.messages.create( + from: 'my twilio number', + to: 'my phone number', + body: "Thank you! Your order was placed and will be delivered before #{Time.now + 1*60*60}" + ) + end +end \ No newline at end of file diff --git a/lib/dish.rb b/lib/dish.rb new file mode 100644 index 0000000000..379dce0940 --- /dev/null +++ b/lib/dish.rb @@ -0,0 +1,18 @@ +class Dish + + attr_accessor = :name, :price + + def initialize(name, price) + @name = name + @price = price + end + + def name + @name + end + + def price + @price + end + +end \ No newline at end of file diff --git a/lib/menu.rb b/lib/menu.rb new file mode 100644 index 0000000000..a21fb2796b --- /dev/null +++ b/lib/menu.rb @@ -0,0 +1,28 @@ +require_relative 'dish' +require_relative 'order' + +class Menu + + attr_reader :order, :view_menu + attr_accessor :menu, :item_number + + def initialize + @menu = [] + end + + def add_dish(name, price) + dish = Dish.new(name, price) + @menu.push(dish) + end + + def menu + @menu + end + + private + + def view_order_numbers + @order_numbers + end + +end \ No newline at end of file diff --git a/lib/order.rb b/lib/order.rb new file mode 100644 index 0000000000..1e38ea058c --- /dev/null +++ b/lib/order.rb @@ -0,0 +1,39 @@ +require_relative 'dish' +require_relative 'menu' +require_relative 'TwilioTextMessenger' + +class Order + + attr_accessor :order + + def initialize(menu, *item_number) + @order = [] + @item_numbers = [*item_number] + @menu = menu + @total_price = 0 + end + + def submit_order + @order = @item_numbers.map { |dish| @menu.menu[dish-1]} + send_sms + end + + def bill + prepare_bill + end + + private + def calculate_order_price + @amounts = @order.map {|dish| dish.instance_variable_get(:@price)} + @amounts.each { |amount| @total_price+=amount} + "Total to pay: £#{@total_price}" + end + + def prepare_bill + @order.each { |dish| puts "#{dish.name}: £#{dish.price}"} + end + + def send_sms + TwilioTextMessenger.new + end +end \ No newline at end of file diff --git a/spec/TwilioTextMessenger_spec.rb b/spec/TwilioTextMessenger_spec.rb new file mode 100644 index 0000000000..a24cd08fea --- /dev/null +++ b/spec/TwilioTextMessenger_spec.rb @@ -0,0 +1,7 @@ +require 'TwilioTextMessenger' + +describe TwilioTextMessenger do + # it "should send text" do + # expect(subject).to include("Thank you! Your order was placed and will be delivered before 18:52") + # end +end \ No newline at end of file diff --git a/spec/dish_spec.rb b/spec/dish_spec.rb new file mode 100644 index 0000000000..39e50467db --- /dev/null +++ b/spec/dish_spec.rb @@ -0,0 +1,11 @@ +require 'dish' + +describe Dish do + dish = Dish.new("Korma", 8) + it '#name should retun the name of the dish' do + expect(dish.name).to be_a(String) + end + it '#price should return the price of the dish' do + expect(dish.price).to be_a(Integer) + end +end \ No newline at end of file diff --git a/spec/menu_spec.rb b/spec/menu_spec.rb new file mode 100644 index 0000000000..72d1cfcaaf --- /dev/null +++ b/spec/menu_spec.rb @@ -0,0 +1,15 @@ +require 'menu' + +describe Menu do + it '#view_menu will return the list of dishes available' do + subject.add_dish("Fish",9) + subject.add_dish("Korma",8) + expect(subject.menu).to be_a(Array) + end + + it "#add dish will allow use to pick as many dishes as they want" do + 20.times {subject.add_dish("Korma",8)} + expect(subject.menu.count).to eq 20 + end + +end \ No newline at end of file diff --git a/spec/order_spec.rb b/spec/order_spec.rb new file mode 100644 index 0000000000..4a785c8d2a --- /dev/null +++ b/spec/order_spec.rb @@ -0,0 +1,20 @@ +require 'order' +require 'menu' + +describe Order do + menu = Menu.new + menu.add_dish("Fish",9) + menu.add_dish("Korma",8) + order = Order.new(menu,1,2) + order.submit_order + it "#submit_order should put chosen dishes into an order" do + expect(order.order[0]).to be_a(Dish) + expect(order.order[1]).to be_a(Dish) + end + + it "#bill to return a bill with names and price of each item" do + expect(order.bill).to include(:dish => 'Fish') + expect(order.bill).to include(:price => 8) + end + +end \ No newline at end of file