From b2fff1fa4cb516e599a6f3315eaa1f734548ff9f Mon Sep 17 00:00:00 2001 From: Paris Dolfman Date: Wed, 21 Oct 2020 16:57:55 +0000 Subject: [PATCH 1/3] Done. --- app/application.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/app/application.rb b/app/application.rb index e69de29bb..357bba2a4 100644 --- a/app/application.rb +++ b/app/application.rb @@ -0,0 +1,24 @@ +class Application + + @@item = [] + @@item << Item.new("Pear", 3.42) + + def call(env) + resp = Rack::Response.new + req = Rack::Request.new(env) + + if req.path.match(/items/) + @@item.each do |item| + resp.write "#{item.price}" + end + elsif + + resp.write "Item not found" + resp.status = 400 + else + resp.write "Route not found" + resp.status = 404 + end + resp.finish + end +end From 8de5f18a1b00e3e1293dd2ccb723f9d9830b5475 Mon Sep 17 00:00:00 2001 From: Paris Dolfman Date: Fri, 23 Oct 2020 17:19:36 +0000 Subject: [PATCH 2/3] Done. --- app/application.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/application.rb b/app/application.rb index 357bba2a4..ab4f7ca8f 100644 --- a/app/application.rb +++ b/app/application.rb @@ -8,16 +8,16 @@ def call(env) req = Rack::Request.new(env) if req.path.match(/items/) - @@item.each do |item| - resp.write "#{item.price}" - end - elsif - - resp.write "Item not found" - resp.status = 400 - else - resp.write "Route not found" + item_name = req.path.split("/items/").last + if item = @@item.find{|i| i.name == item_name} + resp.write item.price + else + resp.status = 400 + resp.write "Item not found" + end + else resp.status = 404 + resp.write "Route not found" end resp.finish end From e28cdcc85f31078ea8dc22ef428aecd053729da5 Mon Sep 17 00:00:00 2001 From: Paris Dolfman Date: Fri, 23 Oct 2020 17:21:27 +0000 Subject: [PATCH 3/3] Done. --- app/application.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/application.rb b/app/application.rb index ab4f7ca8f..9a71a876a 100644 --- a/app/application.rb +++ b/app/application.rb @@ -1,7 +1,7 @@ class Application - @@item = [] - @@item << Item.new("Pear", 3.42) + @@items = [] + @@items << Item.new("Pear", 3.42) def call(env) resp = Rack::Response.new @@ -9,7 +9,7 @@ def call(env) if req.path.match(/items/) item_name = req.path.split("/items/").last - if item = @@item.find{|i| i.name == item_name} + if item = @@items.find{|i| i.name == item_name} resp.write item.price else resp.status = 400