From e01cc48a554feff08c992e8535fc17b7437dd10d Mon Sep 17 00:00:00 2001 From: Daniel Suarez Date: Sun, 2 May 2021 16:12:23 -0400 Subject: [PATCH 1/9] Done. --- app/application.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/application.rb b/app/application.rb index e69de29bb..73ac2ee10 100644 --- a/app/application.rb +++ b/app/application.rb @@ -0,0 +1,16 @@ +class Application + + def call(env) + resp = Rack::Response.new + req = Rack::Request.new(env) + + # if req.path.match(/testing/) + if req.path=="/testing" + resp.write "Route not found" + resp.status = 404 + end + + resp.finish + + end +end \ No newline at end of file From ba8c2e3ac5ac47864c94d3b0746d499abf8fd508 Mon Sep 17 00:00:00 2001 From: Daniel Suarez Date: Sun, 2 May 2021 16:21:20 -0400 Subject: [PATCH 2/9] Done. --- app/application.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/application.rb b/app/application.rb index 73ac2ee10..cd5aab434 100644 --- a/app/application.rb +++ b/app/application.rb @@ -1,5 +1,7 @@ class Application + @@item = ["3.42"] + def call(env) resp = Rack::Response.new req = Rack::Request.new(env) @@ -8,6 +10,10 @@ def call(env) if req.path=="/testing" resp.write "Route not found" resp.status = 404 + elsif req.path.match(/items/) + @@item.each do |item| + resp.write "#{item}\n" + end end resp.finish From 3c47e7901cf27b36eaa3dcd83f40423d279e3a7b Mon Sep 17 00:00:00 2001 From: Daniel Suarez Date: Sun, 2 May 2021 17:05:40 -0400 Subject: [PATCH 3/9] Done. --- Gemfile | 1 + Gemfile.lock | 8 +++++++- app/application.rb | 9 +++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 65300a9b1..737d52157 100644 --- a/Gemfile +++ b/Gemfile @@ -3,3 +3,4 @@ source 'https://rubygems.org' gem 'rack' gem 'rack-test' gem 'rspec' + diff --git a/Gemfile.lock b/Gemfile.lock index 1f52c27d9..2f38e61bb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,12 @@ GEM remote: https://rubygems.org/ specs: + coderay (1.1.3) diff-lcs (1.3) + method_source (1.0.0) + pry (0.14.0) + coderay (~> 1.1) + method_source (~> 1.0) rack (2.0.6) rack-test (1.1.0) rack (>= 1.0, < 3) @@ -23,9 +28,10 @@ PLATFORMS ruby DEPENDENCIES + pry rack rack-test rspec BUNDLED WITH - 2.0.1 + 2.2.14 diff --git a/app/application.rb b/app/application.rb index cd5aab434..08790c867 100644 --- a/app/application.rb +++ b/app/application.rb @@ -13,9 +13,14 @@ def call(env) elsif req.path.match(/items/) @@item.each do |item| resp.write "#{item}\n" - end + end + # else + # search_term = req.params["item"] + # @@items.!inlcude?(item) + # resp.write "Item not found" + # resp.status = 404 + end - resp.finish end From 7fa29f4ff7bf765ecc055ceca49a4703d2e8d001 Mon Sep 17 00:00:00 2001 From: Daniel Suarez Date: Sun, 2 May 2021 20:31:06 -0400 Subject: [PATCH 4/9] Done. --- Gemfile | 2 +- app/application.rb | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index 737d52157..9152e7c47 100644 --- a/Gemfile +++ b/Gemfile @@ -3,4 +3,4 @@ source 'https://rubygems.org' gem 'rack' gem 'rack-test' gem 'rspec' - +gem 'pry' diff --git a/app/application.rb b/app/application.rb index 08790c867..67490446d 100644 --- a/app/application.rb +++ b/app/application.rb @@ -1,25 +1,24 @@ class Application @@item = ["3.42"] + # @@item = [] def call(env) resp = Rack::Response.new req = Rack::Request.new(env) - # if req.path.match(/testing/) - if req.path=="/testing" + if req.path.match(/testing/) + # if req.path=="/testing" resp.write "Route not found" resp.status = 404 elsif req.path.match(/items/) @@item.each do |item| resp.write "#{item}\n" end - # else - # search_term = req.params["item"] - # @@items.!inlcude?(item) - # resp.write "Item not found" - # resp.status = 404 - + else + !@@item.include?(Item.new.price) + resp.write "Item not found" + resp.status = 404 end resp.finish From bf2be01cbe9d53e87cdc22f0d18b82660519504b Mon Sep 17 00:00:00 2001 From: Daniel Suarez Date: Sun, 2 May 2021 22:37:39 -0400 Subject: [PATCH 5/9] Done. --- app/application.rb | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/app/application.rb b/app/application.rb index 67490446d..b2edb76dd 100644 --- a/app/application.rb +++ b/app/application.rb @@ -15,12 +15,36 @@ def call(env) @@item.each do |item| resp.write "#{item}\n" end - else - !@@item.include?(Item.new.price) - resp.write "Item not found" - resp.status = 404 + elsif !@@item.include?(@@item.last) + resp.write "Item not found" + resp.status = 404 end + # binding.pry resp.finish end -end \ No newline at end of file +end + +# elsif req.path.match(/items/) +# search_term = req.params["item"] +# if @@item.include?(search_term) +# @@item.each do |item| +# resp.write "#{item}\n" +# end +# else +# # elsif @@item.include?(@@item.last) +# resp.write "Item not found" +# resp.status = 404 +# end +# end + +# elsif req.path.match(/items/) + # if @@item.include?(@@item.last) + # @@item.each do |item| + # resp.write "#{item}\n" + # end + # else + # # !@@item.include?(@@item.last) + # resp.write "Item not found" + # resp.status = 404 + # end \ No newline at end of file From c5a63a699fe07cdc84f26dd88a113be6e0f0788c Mon Sep 17 00:00:00 2001 From: Daniel Suarez Date: Sun, 2 May 2021 22:38:12 -0400 Subject: [PATCH 6/9] Done. --- app/application.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/application.rb b/app/application.rb index b2edb76dd..fbf09241d 100644 --- a/app/application.rb +++ b/app/application.rb @@ -1,7 +1,6 @@ class Application - @@item = ["3.42"] - # @@item = [] + @@item = ["3.42"] def call(env) resp = Rack::Response.new @@ -19,9 +18,7 @@ def call(env) resp.write "Item not found" resp.status = 404 end - # binding.pry resp.finish - end end From d353983ba17e115186b67ff7350cfa7ad014276f Mon Sep 17 00:00:00 2001 From: Daniel Suarez Date: Sun, 2 May 2021 22:49:42 -0400 Subject: [PATCH 7/9] Done. --- app/application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/application.rb b/app/application.rb index fbf09241d..147e2198b 100644 --- a/app/application.rb +++ b/app/application.rb @@ -16,7 +16,7 @@ def call(env) end elsif !@@item.include?(@@item.last) resp.write "Item not found" - resp.status = 404 + resp.status = 400 end resp.finish end From 2231323bc04d81bae9eaea1b783fac29162b720f Mon Sep 17 00:00:00 2001 From: Daniel Suarez Date: Sun, 2 May 2021 23:24:07 -0400 Subject: [PATCH 8/9] Done. --- app/application.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/application.rb b/app/application.rb index 147e2198b..2ec06f70d 100644 --- a/app/application.rb +++ b/app/application.rb @@ -1,3 +1,5 @@ +require 'pry' + class Application @@item = ["3.42"] @@ -6,17 +8,19 @@ def call(env) resp = Rack::Response.new req = Rack::Request.new(env) - if req.path.match(/testing/) + # if req.path.match(/testing/) # if req.path=="/testing" + if req.path.match(/items/) + binding.pry resp.write "Route not found" resp.status = 404 - elsif req.path.match(/items/) @@item.each do |item| resp.write "#{item}\n" end - elsif !@@item.include?(@@item.last) - resp.write "Item not found" - resp.status = 400 + else + # !@@item.include?(@@item.last) + # resp.write "Item not found" + resp.status = 404 end resp.finish end From d89bbc511cc6c5a87302c88cae099e5fee0e5e80 Mon Sep 17 00:00:00 2001 From: Daniel Suarez Date: Mon, 3 May 2021 00:00:40 -0400 Subject: [PATCH 9/9] Done. --- app/application.rb | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/app/application.rb b/app/application.rb index 2ec06f70d..72d0d9aa3 100644 --- a/app/application.rb +++ b/app/application.rb @@ -2,7 +2,7 @@ class Application - @@item = ["3.42"] + @@items = [Item.new("Figs",3.42),Item.new("Pears",0.99)] def call(env) resp = Rack::Response.new @@ -10,16 +10,22 @@ def call(env) # if req.path.match(/testing/) # if req.path=="/testing" - if req.path.match(/items/) - binding.pry - resp.write "Route not found" - resp.status = 404 - @@item.each do |item| - resp.write "#{item}\n" - end + + if req.path.match(/items/) + item_name = req.path.split("/items/").last + found_item = @@items.find do |item| + item.name == item_name + end + if found_item + resp.write found_item.price + else + resp.write "Item not found" + resp.status = 400 + end + # binding.pry else # !@@item.include?(@@item.last) - # resp.write "Item not found" + resp.write "Route not found" resp.status = 404 end resp.finish