Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.

Commit

Permalink
Forward parsed json body to function handler
Browse files Browse the repository at this point in the history
  • Loading branch information
zhulik committed Feb 8, 2023
1 parent fc633b5 commit 952ad70
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion backup-stats-collector/function/lib/function/handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
class Function::Handler
METRICS_PREFIX = ENV.fetch("METRICS_PREFIX")

def initialize(env)
def initialize(env, body: nil)
@env = env
@body = body
end

def call
Expand Down
8 changes: 7 additions & 1 deletion base/config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ handler = lambda do

raise Function::Unauthorized if token != AUTH_TOKEN

[200, {}, Function::Handler.new(request.env).call]
body = begin
JSON.parse(request.body.read, symbolize_names: true)
rescue StandardError
nil
end

[200, {}, Function::Handler.new(request.env, body:).call]
end

get "/*", &handler
Expand Down
3 changes: 2 additions & 1 deletion hass-listener/function/lib/function/handler.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# frozen_string_literal: true

class Function::Handler
def initialize(env)
def initialize(env, body: nil)
@env = env
@body = body
end

def call
Expand Down
6 changes: 3 additions & 3 deletions notifier/function/lib/function/handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ class Function::Handler

TELEGRAM = Function::Telegram.new(TELEGRAM_TOKEN, TELEGRAM_CHATS)

def initialize(env)
def initialize(env, body: nil)
@env = env
@body = body
end

def call
pp(@env.to_json)
@env.to_json
@body
end
end
3 changes: 2 additions & 1 deletion time-passed/function/lib/function/handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ class Function::Handler

METRICS_PREFIX = ENV.fetch("METRICS_PREFIX")

def initialize(env)
def initialize(env, body: nil)
@env = env
@body = body
end

def call
Expand Down

0 comments on commit 952ad70

Please sign in to comment.