Sei sulla pagina 1di 3

require 'httparty'

require 'json'

class CustomerClient

include HTTParty

base_uri 'http://localhost:8080'
format :json
def CustomerClient.addEntry(lastName, firstName, email, lastOrder, lastOrder2, lastOrder3,
award)
response = post '/customers',
body: {customer:{lastName: lastName, firstName: firstName, email: email, lastOrder:
lastOrder, lastOrder2: lastOrder2, lastOrder3: lastOrder3, award: award}}.to_json,
headers: {'Content-Type' => 'application/json',
'ACCEPT' => 'application/json' }

puts response.code
if response.code == 201
puts response.body
end
end

def CustomerClient.getEntryById(id)
uri = "/customers?id=%d" % [id]
response = get uri

puts response.code
if response.code == 200
puts response.body
end
end

def CustomerClient.getEntryByEmail(email)
uri = "/customers?email=%s" % [email]
response = get uri

puts response.code
if response.code == 200
puts response.body
end
end
def CustomerClient.testOrder(customerId)
uri = "/customers/order"
#order:{itemId: 1, description: "idk", customerId: 1, price: 19.95, award: 1.00, total: 18.95}
response = put uri,
body: {order:{itemId: 1, description: "idk", customerId: 1, price: 19.95, award: 1.00, total:
18.95}}.to_json,
headers: { 'Content-Type' => 'application/json',
'ACCEPT' => 'application/json' }
puts response.code
#if response.code == 205
puts response.body
#end

end

end

#CustomerClient.addEntry("mikewazowski@monsters.inc", "Wazowski", "Mike")


exit = false
while exit == false do
puts "What do you want to do: register, email, id or quit"
option = gets.chomp

case option
when "register"
puts "Input last name for customer"
lastName = gets.chomp!
puts "Input first name for customer"
firstName = gets.chomp!
puts "Input valid email for customer"
email = gets.chomp!
lastOrder = 0
lastOrder2 = 0
lastOrder3 = 0
award = 0
puts "Attempting to create new entry..."
CustomerClient.addEntry(lastName, firstName, email, lastOrder, lastOrder2, lastOrder3,
award)

when "email"
puts "Input email"
email = gets
CustomerClient.getEntryByEmail(email)
puts "Attempting to retrieve customer data..."

when "id"
puts "Input id"
id = gets
CustomerClient.getEntryById(id)
puts "Retrieving customer data..."

when "quit"
puts "Goodbye"
exit = true
else
puts "Command not recognized"
end
end

Potrebbero piacerti anche