diff --git a/app/application.rb b/app/application.rb index e69de29bb..a1b29bebf 100644 --- a/app/application.rb +++ b/app/application.rb @@ -0,0 +1,26 @@ +class Application + @@items = [] + + 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.find{|i| i.name == item_name} + + if item.nil? #IF a user requests an item that is not available + resp.write "Item not found" + resp.status = 400 + else + resp.write item.price #If user requests '/items/' it returns the price of that item. + 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..ac79bff6e 100644 --- a/app/item.rb +++ b/app/item.rb @@ -5,4 +5,5 @@ def initialize(name,price) @name = name @price = price end + end