diff --git a/app/application.rb b/app/application.rb index e69de29bb..2c23ace14 100644 --- a/app/application.rb +++ b/app/application.rb @@ -0,0 +1,24 @@ +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{|s| s.name == item_name} + if !item + resp.write "Item not found" + resp.status = 400 + else + resp.write item.price + 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..416d469fd 100644 --- a/app/item.rb +++ b/app/item.rb @@ -1,8 +1,31 @@ class Item attr_accessor :name, :price + + @@items = [] def initialize(name,price) @name = name @price = price + @@items << self end end + + #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 = Item.find{|s| s.name == item_name} + #if !item + #resp.write "Item not found" + #resp.status 400 + #else + #resp.write item.price + #end + #else + #resp.write "Error!" + #resp.status 404 + # end + #end +#end \ No newline at end of file