2020-02-02 19:09:00 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Webhooks::Twitter
|
2020-02-09 10:17:48 +00:00
|
|
|
SUPPORTED_EVENTS = [:direct_message_events, :tweet_create_events].freeze
|
2020-02-02 19:09:00 +00:00
|
|
|
|
|
|
|
attr_accessor :params, :account
|
|
|
|
|
|
|
|
def initialize(params)
|
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def consume
|
|
|
|
send(event_name) if event_name
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def event_name
|
|
|
|
@event_name ||= SUPPORTED_EVENTS.find { |key| @params.key?(key.to_s) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def direct_message_events
|
2020-02-05 13:20:38 +00:00
|
|
|
::Twitter::DirectMessageParserService.new(payload: @params).perform
|
2020-02-02 19:09:00 +00:00
|
|
|
end
|
2020-02-09 10:17:48 +00:00
|
|
|
|
|
|
|
def tweet_create_events
|
|
|
|
::Twitter::TweetParserService.new(payload: @params).perform
|
|
|
|
end
|
2020-02-02 19:09:00 +00:00
|
|
|
end
|