2016-02-28 07:26:52 +00:00
|
|
|
class SlackService
|
|
|
|
class WikiPageMessage < BaseMessage
|
|
|
|
attr_reader :user_name
|
|
|
|
attr_reader :title
|
|
|
|
attr_reader :project_name
|
|
|
|
attr_reader :project_url
|
|
|
|
attr_reader :wiki_page_url
|
|
|
|
attr_reader :action
|
|
|
|
attr_reader :description
|
|
|
|
|
|
|
|
def initialize(params)
|
2016-09-30 21:03:30 +00:00
|
|
|
@user_name = params[:user][:username]
|
2016-02-28 07:26:52 +00:00
|
|
|
@project_name = params[:project_name]
|
|
|
|
@project_url = params[:project_url]
|
|
|
|
|
|
|
|
obj_attr = params[:object_attributes]
|
|
|
|
obj_attr = HashWithIndifferentAccess.new(obj_attr)
|
|
|
|
@title = obj_attr[:title]
|
|
|
|
@wiki_page_url = obj_attr[:url]
|
|
|
|
@description = obj_attr[:content]
|
|
|
|
|
2016-04-05 06:05:35 +00:00
|
|
|
@action =
|
2016-02-28 07:26:52 +00:00
|
|
|
case obj_attr[:action]
|
|
|
|
when "create"
|
|
|
|
"created"
|
|
|
|
when "update"
|
|
|
|
"edited"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def attachments
|
|
|
|
description_message
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def message
|
|
|
|
"#{user_name} #{action} #{wiki_page_link} in #{project_link}: *#{title}*"
|
|
|
|
end
|
|
|
|
|
|
|
|
def description_message
|
|
|
|
[{ text: format(@description), color: attachment_color }]
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_link
|
|
|
|
"[#{project_name}](#{project_url})"
|
|
|
|
end
|
|
|
|
|
|
|
|
def wiki_page_link
|
|
|
|
"[wiki page](#{wiki_page_url})"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|