Method: Yake::API::DSL#route
- Defined in:
- lib/yake/api.rb
#route(event, context = nil, &block) ⇒ Object
Proxy handler for HTTP requests from Slack
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/yake/api.rb', line 13 def route(event, context = nil, &block) # Extract route method method = event['routeKey'] raise Yake::Errors::UndeclaredRoute, method unless respond_to?(method) # Normalize headers event['headers']&.transform_keys!(&:downcase) # Decode body if Base64-encoded if event['isBase64Encoded'] body = event['body'].unpack1('m0') event.update('body' => body, 'isBase64Encoded' => false) end # Execute request res = send(method, event, context) block_given? ? yield(res) : res end |