claude-says-no/app.rb
2025-06-06 18:50:32 +02:00

212 lines
5.1 KiB
Ruby

require 'sinatra'
require 'json'
# Configure Sinatra
set :port, ENV['PORT'] || 4567
set :bind, '0.0.0.0'
# Array of creative "no" responses
NO_RESPONSES = [
"No",
"Nope",
"Absolutely not",
"Not a chance",
"Never",
"No way",
"Negative",
"Not happening",
"Nah",
"No siree",
"Not today",
"Dream on",
"Over my dead body",
"When pigs fly",
"Not in a million years",
"Forget about it",
"No dice",
"Not on your life",
"Fat chance",
"No can do"
].freeze
# Helper method to get a random "no"
def get_no_response
NO_RESPONSES.sample
end
# Root endpoint - returns HTML by default
get '/' do
no_response = get_no_response
case request.accept.first&.to_s
when /application\/json/
content_type :json
{ answer: no_response, timestamp: Time.now.iso8601 }.to_json
else
content_type :html
erb :index, locals: { no_response: no_response }
end
end
# Explicit JSON endpoint
get '/api/no' do
content_type :json
{
answer: get_no_response,
timestamp: Time.now.iso8601,
service: "No as a Service",
version: "1.0.0"
}.to_json
end
# Health check endpoint
get '/health' do
content_type :json
{ status: "healthy", timestamp: Time.now.iso8601 }.to_json
end
# Catch-all route for any other endpoint
get '/*' do
no_response = get_no_response
case request.accept.first&.to_s
when /application\/json/
content_type :json
{ answer: no_response, timestamp: Time.now.iso8601 }.to_json
else
content_type :html
erb :index, locals: { no_response: no_response }
end
end
__END__
@@index
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>No as a Service</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
color: white;
}
.container {
text-align: center;
max-width: 600px;
padding: 2rem;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 20px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
border: 1px solid rgba(255, 255, 255, 0.2);
}
h1 {
font-size: 3rem;
margin-bottom: 1rem;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}
.subtitle {
font-size: 1.2rem;
margin-bottom: 2rem;
opacity: 0.9;
}
.no-response {
font-size: 4rem;
font-weight: bold;
color: #ff6b6b;
text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.5);
margin: 2rem 0;
padding: 1rem;
background: rgba(255, 255, 255, 0.1);
border-radius: 15px;
border: 2px solid rgba(255, 107, 107, 0.3);
}
.refresh-btn {
background: linear-gradient(45deg, #ff6b6b, #ff8e8e);
color: white;
border: none;
padding: 1rem 2rem;
font-size: 1.1rem;
border-radius: 50px;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
}
.refresh-btn:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
}
.api-info {
margin-top: 2rem;
padding: 1rem;
background: rgba(255, 255, 255, 0.05);
border-radius: 10px;
font-size: 0.9rem;
}
.api-info code {
background: rgba(0, 0, 0, 0.2);
padding: 0.2rem 0.5rem;
border-radius: 4px;
font-family: 'Courier New', monospace;
}
@media (max-width: 600px) {
.container {
margin: 1rem;
padding: 1.5rem;
}
h1 {
font-size: 2rem;
}
.no-response {
font-size: 2.5rem;
}
}
</style>
</head>
<body>
<div class="container">
<h1>No as a Service</h1>
<p class="subtitle">The definitive API for negative responses</p>
<div class="no-response">
<%= no_response %>
</div>
<button class="refresh-btn" onclick="location.reload()">
Get Another No
</button>
<div class="api-info">
<h3>API Usage</h3>
<p>JSON API: <code>GET /api/no</code></p>
<p>Accept JSON: <code>curl -H "Accept: application/json" /</code></p>
<p>Health Check: <code>GET /health</code></p>
</div>
</div>
</body>
</html>