add twitter configuration for notification_service

fixes CNVS-26201

Test-Plan:
- Run a message through canvas with twitter configured
- Notice you recieve a direct message through twitter

Change-Id: I7cd31bb2caf285a2bfadad44c248e6617da2f92e
Reviewed-on: https://gerrit.instructure.com/70893
QA-Review: Gentry Beckmann <gbeckmann@instructure.com>
Tested-by: Jenkins
Reviewed-by: Alex Boyd <aboyd@instructure.com>
Product-Review: Steven Burnett <sburnett@instructure.com>
This commit is contained in:
Steven Burnett 2016-01-22 16:26:44 -07:00
parent f8605f3a2d
commit 453fe29205
2 changed files with 17 additions and 1 deletions

View File

@ -31,6 +31,8 @@ class Message < ActiveRecord::Base
extend TextHelper
MAX_TWITTER_MESSAGE_LENGTH = 140
# Associations
belongs_to :asset_context, :polymorphic => true
@ -615,6 +617,11 @@ class Message < ActiveRecord::Base
Mailer.create_message(self).to_s
when "push"
sns_json
when "twitter"
url = self.main_link || self.url
message_length = MAX_TWITTER_MESSAGE_LENGTH - url.length - 1
truncated_body = HtmlTextHelper.strip_and_truncate(body, max_length: message_length)
"#{truncated_body} #{url}"
else
body
end
@ -624,8 +631,16 @@ class Message < ActiveRecord::Base
#
# Returns the targets in which to send the notification to
def notification_targets
if path_type == "push"
case path_type
when "push"
self.user.notification_endpoints.map(&:arn)
when "twitter"
twitter_service = user.user_services.where(service: 'twitter').first
[
"access_token"=> twitter_service.token,
"access_token_secret"=> twitter_service.secret,
"user_id"=> twitter_service.service_user_id
]
else
[to]
end

View File

@ -42,6 +42,7 @@ describe NotificationService do
expect{@message.deliver}.not_to raise_error
end
it "processes twitter message type" do
@user.user_services.create!(service: 'twitter', service_user_name: 'user', service_user_id: 'user', visible: true)
@queue.expects(:send_message).once
@message.path_type = "twitter"
expect{@message.deliver}.not_to raise_error