2019-08-14 09:48:44 +00:00
|
|
|
class Api::V1::WebhooksController < ApplicationController
|
|
|
|
skip_before_action :authenticate_user!, raise: false
|
|
|
|
skip_before_action :set_current_user
|
|
|
|
|
2020-02-02 19:09:00 +00:00
|
|
|
def twitter_crc
|
2020-02-09 10:17:48 +00:00
|
|
|
render json: { response_token: "sha256=#{twitter_client.generate_crc(params[:crc_token])}" }
|
2020-02-02 19:09:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def twitter_events
|
|
|
|
twitter_consumer.consume
|
|
|
|
head :ok
|
|
|
|
rescue StandardError => e
|
|
|
|
Raven.capture_exception(e)
|
|
|
|
head :ok
|
|
|
|
end
|
|
|
|
|
2019-08-14 09:48:44 +00:00
|
|
|
private
|
2019-10-20 08:47:26 +00:00
|
|
|
|
2020-02-09 10:17:48 +00:00
|
|
|
def twitter_client
|
|
|
|
Twitty::Facade.new do |config|
|
|
|
|
config.consumer_secret = ENV.fetch('TWITTER_CONSUMER_SECRET', nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-02 19:09:00 +00:00
|
|
|
def twitter_consumer
|
|
|
|
@twitter_consumer ||= ::Webhooks::Twitter.new(params)
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
end
|