From 53f8d18927fe1c5ed452a34d72947608f3e61f2a Mon Sep 17 00:00:00 2001 From: Kristen Kinnear-Ohlmann Date: Sat, 13 Mar 2021 03:23:25 +0000 Subject: [PATCH] Done. --- Gemfile | 1 + Gemfile.lock | 6 ++++++ app/application.rb | 27 +++++++++++++++++++++++++++ config/environment.rb | 1 + 4 files changed, 35 insertions(+) diff --git a/Gemfile b/Gemfile index 65300a9b1..9152e7c47 100644 --- a/Gemfile +++ b/Gemfile @@ -3,3 +3,4 @@ source 'https://rubygems.org' gem 'rack' gem 'rack-test' gem 'rspec' +gem 'pry' diff --git a/Gemfile.lock b/Gemfile.lock index 1f52c27d9..88b7cac17 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,12 @@ GEM remote: https://rubygems.org/ specs: + coderay (1.1.2) diff-lcs (1.3) + method_source (0.9.2) + pry (0.12.2) + coderay (~> 1.1.0) + method_source (~> 0.9.0) rack (2.0.6) rack-test (1.1.0) rack (>= 1.0, < 3) @@ -23,6 +28,7 @@ PLATFORMS ruby DEPENDENCIES + pry rack rack-test rspec diff --git a/app/application.rb b/app/application.rb index e69de29bb..9e7205d13 100644 --- a/app/application.rb +++ b/app/application.rb @@ -0,0 +1,27 @@ +class Application + + def call(env) + req = Rack::Request.new(env) + resp = Rack::Response.new + + if req.path.match(/items/) + search_item = req.path.split("/items/").last + item = @@items.find {|item| item.name == search_item} + + if item + resp.write item.price + resp.status = 200 + 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/config/environment.rb b/config/environment.rb index b76605abc..b50e94e49 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,6 @@ require 'bundler/setup' Bundler.require +require 'pry' require_relative "../app/item.rb" require_relative '../app/application'