From 60d01c8ed415d80d427877c77ff7344282abbc58 Mon Sep 17 00:00:00 2001 From: ortufte Date: Tue, 14 Jan 2020 19:21:33 -0600 Subject: [PATCH] Done. --- app/application.rb | 24 ++++++++++++++++++++++++ app/item.rb | 3 ++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/application.rb b/app/application.rb index e69de29bb..9f43faaaa 100644 --- a/app/application.rb +++ b/app/application.rb @@ -0,0 +1,24 @@ +class Application + + def call(env) + resp = Rack::Response.new + req = Rack::Request.new(env) + + if req.path.match(/items\/.+/) + item_name = req.path.split("/items/").last + item = @@items.detect { |i| i.name == item_name } + if item + resp.write item.price + else + resp.write "Item not found" + resp.status = 400 + end + else + resp.write "Route not found" + resp.status = 404 + end + + resp.finish + end + +end diff --git a/app/item.rb b/app/item.rb index f9107bf2f..f82bcbedf 100644 --- a/app/item.rb +++ b/app/item.rb @@ -5,4 +5,5 @@ def initialize(name,price) @name = name @price = price end -end + +end \ No newline at end of file