2020-02-11 08:57:38 +00:00
|
|
|
class Twitter::WebhookSubscribeService
|
|
|
|
include Rails.application.routes.url_helpers
|
|
|
|
|
|
|
|
pattr_initialize [:inbox_id]
|
|
|
|
|
|
|
|
def perform
|
2020-03-28 06:21:42 +00:00
|
|
|
register_response = twitter_client.register_webhook(url: webhooks_twitter_url(protocol: 'https'))
|
2020-02-11 08:57:38 +00:00
|
|
|
twitter_client.subscribe_webhook if register_response.status == '200'
|
|
|
|
Rails.logger.info 'TWITTER_REGISTER_WEBHOOK_FAILURE: ' + register_response.body.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
delegate :channel, to: :inbox
|
|
|
|
delegate :twitter_client, to: :channel
|
|
|
|
|
|
|
|
def inbox
|
|
|
|
Inbox.find_by!(id: inbox_id)
|
|
|
|
end
|
|
|
|
end
|