forked from codeclimate/codeclimate-services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
campfire.rb
54 lines (43 loc) · 1.32 KB
/
campfire.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class CC::Service::Campfire < CC::Service
class Config < CC::Service::Config
attribute :subdomain, Axiom::Types::String,
description: "The Campfire subdomain for the account"
attribute :token, Axiom::Types::Token,
description: "Your Campfire API auth token"
attribute :room_id, Axiom::Types::String,
description: "Check your campfire URL for a room ID. Usually 6 digits."
validates :subdomain, presence: true
validates :room_id, presence: true
validates :token, presence: true
end
self.description = "Send messages to a Campfire chat room"
def receive_test
speak(formatter.format_test).merge(
message: "Test message sent",
)
end
def receive_coverage
speak(formatter.format_coverage)
end
def receive_quality
speak(formatter.format_quality)
end
def receive_vulnerability
speak(formatter.format_vulnerability)
end
private
def formatter
CC::Formatters::PlainFormatter.new(self)
end
def speak(line)
http.headers["Content-Type"] = "application/json"
params = { message: { body: line } }
http.basic_auth(config.token, "X")
service_post(speak_uri, params.to_json)
end
def speak_uri
subdomain = config.subdomain
room_id = config.room_id
"https://#{subdomain}.campfirenow.com/room/#{room_id}/speak.json"
end
end