ellen-hipchat 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dc46d3716d7bcf6b3bab31e36418b1e7d328315f
4
+ data.tar.gz: f763125e04009b4408583f2f1e9d20995d29fbbf
5
+ SHA512:
6
+ metadata.gz: 053a613023b11b4f5e96958b48b5c649e46f2606374876d9c526b1da498d6ecbe8139d4e6ebec034413a488381e1a1cbc0a917d7c1793d21f4d4537308054dce
7
+ data.tar.gz: 03da897de57d425c78dc81260daadfa066479a3df8b61cd62ceca68fc8d21c9c20a42a9e21507a97f56293c65020fd6b439a8af67e8df572e0d8b53537b25d5d
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ellen-hipchat.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ryo Nakamura
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # Ellen::Hipchat
2
+ Hipchat adapter for Ellen.
3
+
4
+ ## Usage
5
+ ```ruby
6
+ # Gemfile
7
+ gem "ellen-hipchat"
8
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "ellen/hipchat/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ellen-hipchat"
7
+ spec.version = Ellen::Hipchat::VERSION
8
+ spec.authors = ["Ryo Nakamura"]
9
+ spec.email = ["r7kamura@gmail.com"]
10
+ spec.summary = "Hipchat adapter for Ellen"
11
+ spec.homepage = "https://github.com/r7kamura/ellen-hipchat"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "ellen", ">= 0.0.2"
20
+ spec.add_dependency "xmpp4r"
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,118 @@
1
+ require "timeout"
2
+ require "xmpp4r"
3
+ require "xmpp4r/muc/helper/simplemucclient"
4
+ require "xmpp4r/roster/helper/roster"
5
+
6
+ module Ellen
7
+ module Adapters
8
+ class Hipchat < Base
9
+ include Mem
10
+
11
+ EVENT_NAMES = [
12
+ :join,
13
+ :leave,
14
+ :message,
15
+ :private_message,
16
+ :room_message,
17
+ :self_leave,
18
+ :subject,
19
+ ]
20
+
21
+ def run
22
+ log
23
+ debug
24
+ bind
25
+ join
26
+ present
27
+ sleep
28
+ rescue Interrupt
29
+ exit
30
+ end
31
+
32
+ def say(body, options = {})
33
+ room.say(body)
34
+ end
35
+
36
+ private
37
+
38
+ def client
39
+ client = Jabber::Client.new(jid)
40
+ client.connect
41
+ client.auth(password)
42
+ client
43
+ end
44
+ memoize :client
45
+
46
+ def room
47
+ Jabber::MUC::SimpleMUCClient.new(client)
48
+ end
49
+ memoize :room
50
+
51
+ private
52
+
53
+ def jid
54
+ ENV["HIPCHAT_JID"] or Ellen.die("HIPCHAT_JID is missing")
55
+ end
56
+
57
+ def password
58
+ ENV["HIPCHAT_PASSWORD"] or Ellen.die("HIPCHAT_PASSWORD is missing")
59
+ end
60
+
61
+ def room_id
62
+ ENV["HIPCHAT_ROOM_ID"] or Ellen.die("HIPCHAT_ROOM_ID is missing")
63
+ end
64
+
65
+ def nickname
66
+ ENV["HIPCHAT_NICKNAME"] or Ellen.die("HIPCHAT_NICKNAME is missing")
67
+ end
68
+
69
+ def room_key
70
+ "#{room_id}/#{nickname}"
71
+ end
72
+
73
+ def log
74
+ Jabber.logger = Ellen.logger
75
+ end
76
+
77
+ def debug
78
+ Jabber.debug = true if ENV["HIPCHAT_DEBUG"]
79
+ end
80
+
81
+ def bind
82
+ room.on_message do |time, nickname, body|
83
+ robot.receive(body: body, source: nickname, command: body.start_with?(prefixed_mention_name))
84
+ end
85
+ end
86
+
87
+ def join
88
+ room.join(room_key)
89
+ end
90
+
91
+ def present
92
+ client.send(presence)
93
+ end
94
+
95
+ def presence
96
+ Jabber::Presence.new.set_type(:available)
97
+ end
98
+
99
+ def prefixed_mention_name
100
+ "@#{mention_name}"
101
+ end
102
+
103
+ def mention_name
104
+ Timeout.timeout(3) { roster[jid].attributes["mention_name"] }
105
+ rescue Timeout::Error
106
+ nickname.split(" ").first
107
+ end
108
+ memoize :mention_name
109
+
110
+ def roster
111
+ roster = Jabber::Roster::Helper.new(client, false)
112
+ roster.get_roster
113
+ roster.wait_for_roster
114
+ roster
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,5 @@
1
+ module Ellen
2
+ module Hipchat
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "ellen/adapters/hipchat"
2
+ require "ellen/hipchat/version"
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ellen-hipchat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryo Nakamura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ellen
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: xmpp4r
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - r7kamura@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - ellen-hipchat.gemspec
82
+ - lib/ellen/adapters/hipchat.rb
83
+ - lib/ellen/hipchat.rb
84
+ - lib/ellen/hipchat/version.rb
85
+ homepage: https://github.com/r7kamura/ellen-hipchat
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.2.2
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Hipchat adapter for Ellen
109
+ test_files: []