ellen-hipchat 0.0.4 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e30afae6e417e1a412d8bbdddf1c14c2ab2196e
4
- data.tar.gz: 386ae5b9880c4546b3d94aceb354c208bb5404fa
3
+ metadata.gz: e93050d2c424827b21eae85f71b6159d1277e398
4
+ data.tar.gz: ffd18a8711dcdc370adf2baaa991d86731dfcf6d
5
5
  SHA512:
6
- metadata.gz: 2ba38dd9f9a90b298eb1bd769e05ab41f14d0f00166105a7cb2ab5064c9c174c7f4768830c5661d980bc1cabf9c7d51f1b8f8098ecbaded14945838de82c93c2
7
- data.tar.gz: 50c7202d5166c6c2f814c539b77dd739a84d42834849f263f7f4c356226da45e0ba34d2e3bb1dbc3a77a98a49f1de5d8ebde359813b7224e4ad8f6121c17aee9
6
+ metadata.gz: b51939dc3d3693b15e2295b63a2782418583d8695976c0e813b7924ee458f8194a03db0c2d633f5944868428b97b50ff00b15ed0d72f439ebe3f36a8f19cd6ac
7
+ data.tar.gz: 877a99c1c3026fe5dcdc2d6d99f3183c92d094f9cec9fcd8de57e84e29400269e2a9a0ad9873429fab3b3d2a4ac3cac71c7cea8145fd1396e0a5258eee238045
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.1.0
2
+ * Change XMPP library: xmpp4r -> xrc
3
+
1
4
  ## 0.0.4
2
5
  * Support Ellen v0.2.0
3
6
 
@@ -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 "xmpp4r"
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 "timeout"
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. Ellen)"
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 :HIPCHAT_ROOM_ID, "Room ID the robot first logs in (e.g. 12345_room-name@conf.hipchat.com)"
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
- join
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
- room.say(message[:body])
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 = Jabber::Client.new(jid)
37
- client.connect
38
- client.auth(password)
39
- client
40
- end
41
- memoize :client
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 = Jabber::JID.new(ENV["HIPCHAT_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 nickname
65
- ENV["HIPCHAT_NICKNAME"]
48
+ def room_jid
49
+ "#{room_name}@conf.hipchat.com"
66
50
  end
67
51
 
68
- def room_key
69
- "#{room_id}/#{nickname}"
52
+ def room_name
53
+ ENV["HIPCHAT_ROOM_NAME"]
70
54
  end
71
55
 
72
- def log
73
- Jabber.logger = Ellen.logger
56
+ def password
57
+ ENV["HIPCHAT_PASSWORD"]
74
58
  end
75
59
 
76
- def debug
77
- Jabber.debug = true if ENV["HIPCHAT_DEBUG"]
60
+ def nickname
61
+ ENV["HIPCHAT_NICKNAME"]
78
62
  end
79
63
 
80
64
  def bind
81
- room.on_message do |time, nickname, body|
82
- robot.receive(body: body, from: nickname, to: room_id)
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 prefixed_mention_name
99
- "@#{mention_name}"
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 roster
110
- roster = Jabber::Roster::Helper.new(client, false)
111
- roster.get_roster
112
- roster.wait_for_roster
113
- roster
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
@@ -1,5 +1,5 @@
1
1
  module Ellen
2
2
  module Hipchat
3
- VERSION = "0.0.4"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  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
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-04-27 00:00:00.000000000 Z
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: xmpp4r
28
+ name: xrc
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
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: '0'
40
+ version: 0.0.5
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement