-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.rb
48 lines (37 loc) · 1.13 KB
/
api.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require "dotenv"
Dotenv.load
require_relative "lib/redacted_breathe_client"
require "sinatra"
require "sinatra/json"
def valid_key?(key)
key === ENV.fetch("MIDDLEMAN_API_KEY")
end
def ensure_key_is_set
key = ENV.fetch("MIDDLEMAN_API_KEY")
raise "MIDDLEMAN_API_KEY not set properly" if key.nil? || key.length < 64
end
ensure_key_is_set
# Routing
before do
error 401, "API key invalid" unless valid_key?(request.env["HTTP_X_API_KEY"])
end
get "/employees" do
json RedactedBreatheClient.employees
rescue RateLimited
halt(420, "Redacted API: Rate limited")
end
get "/absences" do
json RedactedBreatheClient.absences(employee_id: params[:employee_id], after: params[:after])
rescue RateLimited
halt(420, "Redacted API: Rate limited")
end
get "/sicknesses" do
json RedactedBreatheClient.sicknesses(employee_id: params[:employee_id], after: params[:after])
rescue RateLimited
halt(420, "Redacted API: Rate limited")
end
get "/employee_training_courses" do
json RedactedBreatheClient.employee_training_courses(employee_id: params[:employee_id], after: params[:after])
rescue RateLimited
halt(420, "Redacted API: Rate limited")
end