From 839522ef53154cb8ce0a3b4c0f5f6020d0c06152 Mon Sep 17 00:00:00 2001 From: Olivia Kesler Date: Sun, 15 Dec 2019 04:41:35 +0000 Subject: [PATCH 1/3] Done. --- app/item.rb | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/app/item.rb b/app/item.rb index f9107bf2f..cb5408fef 100644 --- a/app/item.rb +++ b/app/item.rb @@ -4,5 +4,42 @@ class Item def initialize(name,price) @name = name @price = price + + resp = Rack::Response.new + req = Rack::Request.new(env) + + if req.path.match(/items/) + item_name = req.path.split("/items/").last #turn + item = Item.find{|s| s.name == item_name} + #item_price = item.price + resp.write item.price + end + + + + + if req.path=="/items" + resp.write "You requested the songs" + else + resp.write "Route not found" + resp.status = 404 + end + + resp.finish end end + + + if req.path.match(/songs/) + + song_title = req.path.split("/songs/").last #turn /songs/Sorry into Sorry + song = @@songs.find{|s| s.title == song_title} + + resp.write song.artist + end + + +Your application should only accept the /items/ route. Everything else should 404 + +If a user requests /items/ it should return the price of that item +IF a user requests an item that you don't have, then return a 400 and an error message \ No newline at end of file From 3a43e8eff2a8ca9802da8ee3685796af9099ff97 Mon Sep 17 00:00:00 2001 From: Olivia Kesler Date: Sun, 15 Dec 2019 05:11:43 +0000 Subject: [PATCH 2/3] Done. --- app/item.rb | 54 ++++++++++++++++++----------------------------------- 1 file changed, 18 insertions(+), 36 deletions(-) diff --git a/app/item.rb b/app/item.rb index cb5408fef..20ee5ef2d 100644 --- a/app/item.rb +++ b/app/item.rb @@ -4,42 +4,24 @@ class Item def initialize(name,price) @name = name @price = price - - resp = Rack::Response.new - req = Rack::Request.new(env) - - if req.path.match(/items/) - item_name = req.path.split("/items/").last #turn - item = Item.find{|s| s.name == item_name} - #item_price = item.price - resp.write item.price end - - - - - if req.path=="/items" - resp.write "You requested the songs" - else - resp.write "Route not found" - resp.status = 404 + + 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 - - resp.finish end -end - - - if req.path.match(/songs/) - - song_title = req.path.split("/songs/").last #turn /songs/Sorry into Sorry - song = @@songs.find{|s| s.title == song_title} - - resp.write song.artist - end - - -Your application should only accept the /items/ route. Everything else should 404 - -If a user requests /items/ it should return the price of that item -IF a user requests an item that you don't have, then return a 400 and an error message \ No newline at end of file +end \ No newline at end of file From 77e06d945f1383aead2ee31181fda9a98b1ee12b Mon Sep 17 00:00:00 2001 From: Olivia Kesler Date: Sun, 15 Dec 2019 05:24:23 +0000 Subject: [PATCH 3/3] Done. --- app/application.rb | 24 ++++++++++++++++++++++++ app/item.rb | 40 ++++++++++++++++++++++------------------ 2 files changed, 46 insertions(+), 18 deletions(-) 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 20ee5ef2d..416d469fd 100644 --- a/app/item.rb +++ b/app/item.rb @@ -1,27 +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) + #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 + #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