Class: LessonlyApi::Webhook

Inherits:
Object
  • Object
show all
Defined in:
lib/lessonly_api/webhook.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Webhook

Returns a new instance of Webhook.



11
12
13
# File 'lib/lessonly_api/webhook.rb', line 11

def initialize(env)
  @env = env
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



9
10
11
# File 'lib/lessonly_api/webhook.rb', line 9

def env
  @env
end

Class Method Details

.call(env) ⇒ Object



4
5
6
# File 'lib/lessonly_api/webhook.rb', line 4

def call(env)
  new(env).call
end

Instance Method Details

#callObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/lessonly_api/webhook.rb', line 15

def call
  return [405, {"Content-Type" => "text/plain"}, ['Method Not Allowed']] unless webhook_handler
  return [401, {"Content-Type" => "text/plain"}, ['Unauthorized']] unless authorized?

  parse_webhook_data

  return [406, {"Content-Type" => "text/plain"}, ['Not Acceptable']] if raw_webhook_data.nil?

  webhook_handler.call(webhook_data)

  [200, {"Content-Type" => "text/plain"}, ['OK']]
end