Commit 22e5e7ca by tady (Masato TADA)

Merge pull request #118 from tadyjp/set-hipchat

[Review] Create Hipchat integration
parents 3eff2d2a 9f7bede3
......@@ -140,3 +140,6 @@ gem 'annotate', ">=2.6.0"
gem 'kaminari', github: 'amatsuda/kaminari'
gem 'jwt', '0.1.11'
# Optional
gem 'hipchat'
......@@ -172,9 +172,14 @@ GEM
teaspoon (>= 0.8.0)
hashie (3.2.0)
hike (1.2.3)
hipchat (1.2.0)
httparty
htmlentities (4.3.2)
http-cookie (1.0.2)
domain_name (~> 0.5)
httparty (0.13.1)
json (~> 1.8)
multi_xml (>= 0.5.2)
i18n (0.6.11)
i18n_generators (1.2.1)
mechanize
......@@ -428,6 +433,7 @@ DEPENDENCIES
guard-rspec
guard-rubocop
guard-teaspoon
hipchat
i18n_generators
jbuilder
jquery-rails
......
class PostDecorator < Draper::Decorator
delegate_all
def show_url
h.post_url(model)
end
def show_path
h.post_path(model)
end
......
module HipchatIntegration
# Call Hipchat API
def notify_hipchat!
client = HipChat::Client.new(Settings.hipchat.token)
client[Settings.hipchat.room].send('Rendezvous', notify_hipchat_body, message_format:'text', notify: 1)
end
# @return [String] notification body
def notify_hipchat_body
<<EOF
#{author.name}が「#{title}」を投稿しました。
#{self.decorate.show_url}
--
#{body}
EOF
end
end
......@@ -16,6 +16,8 @@
require 'date'
class Post < ActiveRecord::Base
include HipchatIntegration if Settings.respond_to?(:hipchat)
######################################################################
# Associations
######################################################################
......@@ -29,7 +31,7 @@ class Post < ActiveRecord::Base
has_many :watchers, :through => :watches
######################################################################
# validations
# Validations
######################################################################
validates :title, presence: true
validates :body, presence: true
......@@ -39,6 +41,7 @@ class Post < ActiveRecord::Base
######################################################################
after_save :set_watcher!
after_save :notify_watchers!
after_create :notify_hipchat! if Settings.respond_to?(:hipchat)
######################################################################
# Named scope
......
......@@ -20,7 +20,12 @@ defaults: &defaults
bucket_name: "xxxxxxxxxxxxxxxxxx"
# optional
google_analytics:
# hipchat:
# token: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
# room: 'xxxxxxxxxxx'
# optional
# google_analytics:
development:
<<: *defaults
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment