ellen-hipchat 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/ellen-hipchat.gemspec +1 -1
- data/lib/ellen/adapters/hipchat.rb +37 -71
- data/lib/ellen/hipchat/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e93050d2c424827b21eae85f71b6159d1277e398
|
4
|
+
data.tar.gz: ffd18a8711dcdc370adf2baaa991d86731dfcf6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b51939dc3d3693b15e2295b63a2782418583d8695976c0e813b7924ee458f8194a03db0c2d633f5944868428b97b50ff00b15ed0d72f439ebe3f36a8f19cd6ac
|
7
|
+
data.tar.gz: 877a99c1c3026fe5dcdc2d6d99f3183c92d094f9cec9fcd8de57e84e29400269e2a9a0ad9873429fab3b3d2a4ac3cac71c7cea8145fd1396e0a5258eee238045
|
data/CHANGELOG.md
CHANGED
data/ellen-hipchat.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
|
19
19
|
spec.add_dependency "ellen", ">= 0.2.0"
|
20
|
-
spec.add_dependency "
|
20
|
+
spec.add_dependency "xrc", ">= 0.0.5"
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.6"
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
end
|
@@ -1,116 +1,82 @@
|
|
1
|
-
require "
|
2
|
-
require "xmpp4r"
|
3
|
-
require "xmpp4r/muc/helper/simplemucclient"
|
4
|
-
require "xmpp4r/roster/helper/roster"
|
1
|
+
require "xrc"
|
5
2
|
|
6
3
|
module Ellen
|
7
4
|
module Adapters
|
8
5
|
class Hipchat < Base
|
9
6
|
include Mem
|
10
7
|
|
11
|
-
env :HIPCHAT_DEBUG, "Pass `1` to show debug information on stdout (optional)", optional: true
|
12
8
|
env :HIPCHAT_JID, "Account's JID (e.g. 12345_67890@chat.hipchat.com)"
|
13
|
-
env :HIPCHAT_NICKNAME, "Account's nickname, which must match the name on the HipChat account (e.g.
|
9
|
+
env :HIPCHAT_NICKNAME, "Account's nickname, which must match the name on the HipChat account (e.g. ellen)"
|
14
10
|
env :HIPCHAT_PASSWORD, "Account's password (e.g. xxx)"
|
15
|
-
env :
|
11
|
+
env :HIPCHAT_ROOM_NAME, "Room name ellen first logs in (e.g. 12345_myroom)"
|
16
12
|
|
17
13
|
def run
|
18
|
-
log
|
19
|
-
debug
|
20
14
|
bind
|
21
|
-
|
22
|
-
present
|
23
|
-
sleep
|
15
|
+
connect
|
24
16
|
rescue Interrupt
|
25
17
|
exit
|
26
18
|
end
|
27
19
|
|
28
|
-
# TODO: We should use message[:from] & message[:to] to select correct room
|
29
20
|
def say(message)
|
30
|
-
|
21
|
+
client.say(
|
22
|
+
body: message[:code] ? "/quote #{message[:body]}" : message[:body],
|
23
|
+
from: message[:from],
|
24
|
+
to: message[:original][:type] == "chat" ? message[:to] + "/resource" : message[:to],
|
25
|
+
type: message[:original][:type],
|
26
|
+
)
|
31
27
|
end
|
32
28
|
|
33
29
|
private
|
34
30
|
|
35
31
|
def client
|
36
|
-
client
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
def room
|
44
|
-
Jabber::MUC::SimpleMUCClient.new(client)
|
32
|
+
@client ||= Xrc::Client.new(
|
33
|
+
jid: jid,
|
34
|
+
nickname: nickname,
|
35
|
+
password: password,
|
36
|
+
room_jid: room_jid,
|
37
|
+
)
|
45
38
|
end
|
46
|
-
memoize :room
|
47
39
|
|
48
40
|
private
|
49
41
|
|
50
42
|
def jid
|
51
|
-
jid =
|
43
|
+
jid = Xrc::Jid.new(ENV["HIPCHAT_JID"])
|
52
44
|
jid.resource = "bot"
|
53
|
-
jid
|
54
|
-
end
|
55
|
-
|
56
|
-
def password
|
57
|
-
ENV["HIPCHAT_PASSWORD"]
|
58
|
-
end
|
59
|
-
|
60
|
-
def room_id
|
61
|
-
ENV["HIPCHAT_ROOM_ID"]
|
45
|
+
jid.to_s
|
62
46
|
end
|
63
47
|
|
64
|
-
def
|
65
|
-
|
48
|
+
def room_jid
|
49
|
+
"#{room_name}@conf.hipchat.com"
|
66
50
|
end
|
67
51
|
|
68
|
-
def
|
69
|
-
"
|
52
|
+
def room_name
|
53
|
+
ENV["HIPCHAT_ROOM_NAME"]
|
70
54
|
end
|
71
55
|
|
72
|
-
def
|
73
|
-
|
56
|
+
def password
|
57
|
+
ENV["HIPCHAT_PASSWORD"]
|
74
58
|
end
|
75
59
|
|
76
|
-
def
|
77
|
-
|
60
|
+
def nickname
|
61
|
+
ENV["HIPCHAT_NICKNAME"]
|
78
62
|
end
|
79
63
|
|
80
64
|
def bind
|
81
|
-
|
82
|
-
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def join
|
87
|
-
room.join(room_key)
|
88
|
-
end
|
89
|
-
|
90
|
-
def present
|
91
|
-
client.send(presence)
|
92
|
-
end
|
93
|
-
|
94
|
-
def presence
|
95
|
-
Jabber::Presence.new.set_type(:available)
|
65
|
+
client.on_private_message(&method(:on_message))
|
66
|
+
client.on_room_message(&method(:on_message))
|
96
67
|
end
|
97
68
|
|
98
|
-
def
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
def mention_name
|
103
|
-
Timeout.timeout(3) { roster[jid].attributes["mention_name"] }
|
104
|
-
rescue Timeout::Error
|
105
|
-
nickname.split(" ").first
|
69
|
+
def connect
|
70
|
+
client.connect
|
106
71
|
end
|
107
|
-
memoize :mention_name
|
108
72
|
|
109
|
-
def
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
73
|
+
def on_message(message)
|
74
|
+
robot.receive(
|
75
|
+
body: message.body,
|
76
|
+
from: message.from,
|
77
|
+
to: message.to,
|
78
|
+
type: message.type,
|
79
|
+
)
|
114
80
|
end
|
115
81
|
end
|
116
82
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ellen-hipchat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ellen
|
@@ -25,19 +25,19 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: xrc
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.0.5
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.0.5
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|