Class: Line::Bot::V2::WebhookParser
- Inherits:
-
Object
- Object
- Line::Bot::V2::WebhookParser
- Defined in:
- lib/line/bot/v2/webhook_parser.rb
Defined Under Namespace
Classes: InvalidSignatureError
Instance Method Summary collapse
-
#initialize(channel_secret:) ⇒ WebhookParser
constructor
A new instance of WebhookParser.
-
#parse(body:, signature:) ⇒ Array<Line::Bot::V2::Webhook::Event>
Parse events from the raw request body and validate the signature.
Constructor Details
#initialize(channel_secret:) ⇒ WebhookParser
Returns a new instance of WebhookParser.
14 15 16 |
# File 'lib/line/bot/v2/webhook_parser.rb', line 14 def initialize(channel_secret:) @channel_secret = channel_secret end |
Instance Method Details
#parse(body:, signature:) ⇒ Array<Line::Bot::V2::Webhook::Event>
Parse events from the raw request body and validate the signature.
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/line/bot/v2/webhook_parser.rb', line 56 def parse(body:, signature:) raise InvalidSignatureError.new("Invalid signature: #{signature}") unless verify_signature(body: body, signature: signature) data = JSON.parse(body.chomp, symbolize_names: true) data = Line::Bot::V2::Utils.deep_underscore(data) data = Line::Bot::V2::Utils.deep_convert_reserved_words(data) data = Line::Bot::V2::Utils.deep_symbolize(data) data[:events].map do |event| Line::Bot::V2::Webhook::Event.create(**event) # steep:ignore end end |