robut 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 216b7b1619326105ea953215d118ff0de9c123c8
4
+ data.tar.gz: 165a69435303dcee8ff52120603ab8ad5fab470c
5
+ SHA512:
6
+ metadata.gz: bf580beaab936d1bf28439a988346f75dee589ff026d824a14abe00ddc59ecf9476b1c940dabd50fa1fed935ce58574aecf77b94a0ff41fd2e5ecb0bbb820bde
7
+ data.tar.gz: 76a4ac19315db0820c5cc69679888c38bfcef0e892b692b6c04016c9750477a3003874906fdcef5dea16ca937688d1de9d52ba85258713fe5ca2e56bbea6d4a1
data/.gitignore CHANGED
@@ -1,6 +1,5 @@
1
1
  *.gem
2
2
  .bundle
3
- Gemfile.lock
4
3
  pkg/*
5
4
  doc/*
6
5
  coverage/*
@@ -1,8 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  # - 1.8.7
4
- - 1.9.2
5
4
  - 1.9.3
5
+ - 2.0
6
6
  # - jruby-18mode # JRuby in 1.8 mode
7
7
  # - jruby-19mode # JRuby in 1.9 mode
8
8
  # - rbx-18mode
data/Gemfile CHANGED
@@ -9,6 +9,7 @@ group :test do
9
9
  gem 'webmock'
10
10
  gem 'time-warp'
11
11
  gem 'mocha'
12
+ gem 'rack-test'
12
13
  end
13
14
 
14
15
  group :plugin do
@@ -0,0 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ robut (0.5.0)
5
+ sinatra (~> 1.3)
6
+ xmpp4r (~> 0.5.0)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ addressable (2.2.6)
12
+ calc (1.0.0)
13
+ classifier (1.3.1)
14
+ stemmer (>= 1.0.0)
15
+ crack (0.1.8)
16
+ meme_generator (1.9)
17
+ nokogiri (~> 1.4)
18
+ metaclass (0.0.1)
19
+ mocha (0.10.0)
20
+ metaclass (~> 0.0.1)
21
+ nokogiri (1.4.4)
22
+ rack (1.5.2)
23
+ rack-protection (1.5.0)
24
+ rack
25
+ rack-test (0.6.2)
26
+ rack (>= 1.0)
27
+ rake (10.0.4)
28
+ simplecov (0.4.2)
29
+ simplecov-html (~> 0.4.4)
30
+ simplecov-html (0.4.5)
31
+ sinatra (1.4.2)
32
+ rack (~> 1.5, >= 1.5.2)
33
+ rack-protection (~> 1.4)
34
+ tilt (~> 1.3, >= 1.3.4)
35
+ stemmer (1.0.1)
36
+ tilt (1.4.1)
37
+ time-warp (1.0.8)
38
+ twss (0.0.5)
39
+ classifier (= 1.3.1)
40
+ webmock (1.6.4)
41
+ addressable (~> 2.2, > 2.2.5)
42
+ crack (>= 0.1.7)
43
+ xmpp4r (0.5)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ calc
50
+ meme_generator
51
+ mocha
52
+ nokogiri
53
+ rack-test
54
+ rake
55
+ robut!
56
+ simplecov
57
+ time-warp
58
+ twss
59
+ webmock
@@ -2,16 +2,6 @@
2
2
 
3
3
  The friendly plugin-enabled HipChat bot.
4
4
 
5
- == NOTE: Breaking backwards compatibility!
6
-
7
- A little while ago, HipChat changed the way their mention names
8
- work. Instead of just using the first name ('@robut'), they now use
9
- the full name ('@RobutTRobot'). Starting from v0.4.0, robut uses this
10
- new format by default. If you prefer the old style, you can set it in
11
- your Chatfile:
12
-
13
- config.mention_name = 'robut'
14
-
15
5
  == Installation and usage
16
6
 
17
7
  Robut can be installed by running <tt>gem install robut</tt>. This
@@ -49,6 +39,13 @@ first parameter:
49
39
 
50
40
  The Chatfile is just ruby code. A simple example can be found here: Chatfile[https://github.com/justinweiss/robut/blob/master/examples/Chatfile]
51
41
 
42
+ == Robut::Web
43
+
44
+ You can run Robut as a rack application, which allows it to accept
45
+ incoming post requests (e.g. Heroku deploy hooks, GitHub post-recieve hooks, etc.)
46
+ that can send messages to all connected rooms. Have a look at
47
+ config.ru[https://github.com/justinweiss/robut/blob/master/examples/config.ru] for an example.
48
+
52
49
  === Adding and configuring plugins
53
50
 
54
51
  Plugins are ruby classes, so enabling a plugin just requires requiring
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'rake/testtask'
2
- require 'rake/rdoctask'
2
+ require 'rdoc/task'
3
3
  require 'bundler'
4
4
  Bundler::GemHelper.install_tasks
5
5
 
data/bin/robut CHANGED
@@ -7,3 +7,4 @@ require 'logger'
7
7
  load ARGV[0] || './Chatfile'
8
8
 
9
9
  Robut::Connection.new.connect
10
+ loop { sleep 1 }
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ Bundler.require :default
4
+
5
+ require 'robut'
6
+ require 'ostruct'
7
+ require 'logger'
8
+
9
+ load './Chatfile'
10
+
11
+ Robut::Web.set :connection, Robut::Connection.new.connect
12
+
13
+ run Robut::Web
@@ -5,4 +5,5 @@ module Robut
5
5
  autoload :PM, 'robut/pm'
6
6
  autoload :Connection, 'robut/connection'
7
7
  autoload :Storage, 'robut/storage'
8
+ autoload :Web, 'robut/web'
8
9
  end
@@ -85,14 +85,21 @@ class Robut::Connection
85
85
  self.roster = Jabber::Roster::Helper.new(client)
86
86
  roster.wait_for_roster
87
87
 
88
- rooms = self.config.rooms.collect do |room_name|
88
+ self.rooms = self.config.rooms.collect do |room_name|
89
89
  Robut::Room.new(self, room_name).tap {|r| r.join }
90
90
  end
91
91
 
92
92
  personal_message = Robut::PM.new(self, rooms)
93
93
 
94
94
  trap_signals
95
- loop { sleep 1 }
95
+ self
96
+ end
97
+
98
+ # Send a message to all rooms.
99
+ def reply(*args, &block)
100
+ self.rooms.each do |room|
101
+ room.reply(*args, &block)
102
+ end
96
103
  end
97
104
 
98
105
  private
@@ -111,4 +118,4 @@ private
111
118
  old_signal_callbacks[sig] = trap(sig) { signal_callback.call(sig) }
112
119
  end
113
120
  end
114
- end
121
+ end
@@ -40,6 +40,25 @@ module Robut::Plugin
40
40
  def matchers
41
41
  @matchers ||= []
42
42
  end
43
+
44
+ # Allows you to define http methods that this plugin should respond to.
45
+ # This is useful if you're want to accept generic post data for Robut to
46
+ # display in all rooms (e.g. Heroku deploy hooks, GitHub post receive
47
+ # hooks, etc).
48
+ #
49
+ # http do
50
+ # post '/heroku' do
51
+ # payload = Hashie::Mash.new(params)
52
+ # say "#{payload.user} deployed #{payload.head} to #{payload.app}", nil
53
+ # halt 200
54
+ # end
55
+ # end
56
+ #
57
+ # The action is run in the context of a Sinatra app (+Robut::Web+). So
58
+ # anything that Sinatra provides is available within the block.
59
+ def http(&block)
60
+ Robut::Web.class_eval &block
61
+ end
43
62
  end
44
63
 
45
64
  class << self
@@ -1,4 +1,4 @@
1
1
  module Robut # :nodoc:
2
2
  # Robut's version number.
3
- VERSION = "0.4.0"
3
+ VERSION = "0.5.0"
4
4
  end
@@ -0,0 +1,26 @@
1
+ require 'sinatra/base'
2
+
3
+ module Robut
4
+ class Web < Sinatra::Base
5
+ helpers do
6
+ # Say something to all connected rooms. Delegates to #reply
7
+ def say(*args)
8
+ reply(*args)
9
+ end
10
+
11
+ # Easy access to the current connection context.
12
+ def connection
13
+ settings.connection
14
+ end
15
+
16
+ # Delegates to Connection#reply
17
+ def reply(*args)
18
+ connection.reply(*args)
19
+ end
20
+ end
21
+
22
+ get '/' do
23
+ 'ok'
24
+ end
25
+ end
26
+ end
@@ -20,4 +20,5 @@ Gem::Specification.new do |s|
20
20
  s.require_paths = ["lib"]
21
21
 
22
22
  s.add_dependency "xmpp4r", "~> 0.5.0"
23
+ s.add_dependency "sinatra", "~> 1.3"
23
24
  end
@@ -2,9 +2,21 @@ require 'robut/storage/hash_store'
2
2
 
3
3
  class Robut::ConnectionMock < Robut::Connection
4
4
 
5
+ attr_accessor :messages
6
+
5
7
  def initialize(config = nil)
8
+ self.messages = []
6
9
  self.config = config || self.class.config
7
10
  self.store = Robut::Storage::HashStore
8
11
  self.client = Jabber::Client.new ''
9
12
  end
13
+
14
+ def connect
15
+ self.rooms = []
16
+ self
17
+ end
18
+
19
+ def reply(message, to)
20
+ self.messages << [message, to]
21
+ end
10
22
  end
@@ -0,0 +1,46 @@
1
+ require 'test_helper'
2
+ require 'rack/test'
3
+
4
+ class WebTest < Test::Unit::TestCase
5
+ include Rack::Test::Methods
6
+
7
+ def app
8
+ Robut::Web
9
+ end
10
+
11
+ def setup
12
+ app.set :show_exceptions, false
13
+ app.set :raise_errors, true
14
+ app.set :connection, connection
15
+ end
16
+
17
+ def test_root
18
+ get '/'
19
+
20
+ assert last_response.ok?
21
+ end
22
+
23
+ def test_say
24
+ app.class_eval do
25
+ get '/test_say' do
26
+ say "Hello", nil
27
+ halt 200
28
+ end
29
+ end
30
+
31
+ get '/test_say'
32
+
33
+ assert_equal messages.first, ["Hello", nil]
34
+ end
35
+
36
+ private
37
+
38
+ def messages
39
+ connection.messages
40
+ end
41
+
42
+ def connection
43
+ @connection ||= Robut::ConnectionMock.new.connect
44
+ end
45
+
46
+ end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: robut
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
5
- prerelease:
4
+ version: 0.5.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Justin Weiss
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-09-24 00:00:00.000000000 Z
11
+ date: 2013-06-07 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: xmpp4r
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,11 +20,24 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
29
26
  version: 0.5.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: sinatra
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
30
41
  description: A simple plugin-enabled HipChat bot
31
42
  email:
32
43
  - justin@uberweiss.org
@@ -38,10 +49,12 @@ files:
38
49
  - .gitignore
39
50
  - .travis.yml
40
51
  - Gemfile
52
+ - Gemfile.lock
41
53
  - README.rdoc
42
54
  - Rakefile
43
55
  - bin/robut
44
56
  - examples/Chatfile
57
+ - examples/config.ru
45
58
  - lib/rexml_patches.rb
46
59
  - lib/robut.rb
47
60
  - lib/robut/connection.rb
@@ -70,6 +83,7 @@ files:
70
83
  - lib/robut/storage/hash_store.rb
71
84
  - lib/robut/storage/yaml_store.rb
72
85
  - lib/robut/version.rb
86
+ - lib/robut/web.rb
73
87
  - robut.gemspec
74
88
  - test/fixtures/bad_location.xml
75
89
  - test/fixtures/las_vegas.xml
@@ -95,35 +109,29 @@ files:
95
109
  - test/unit/storage/hash_store_test.rb
96
110
  - test/unit/storage/yaml_store_test.rb
97
111
  - test/unit/storage/yaml_test.yml
112
+ - test/unit/web_test.rb
98
113
  homepage: http://rdoc.info/github/justinweiss/robut/master/frames
99
114
  licenses: []
115
+ metadata: {}
100
116
  post_install_message:
101
117
  rdoc_options: []
102
118
  require_paths:
103
119
  - lib
104
120
  required_ruby_version: !ruby/object:Gem::Requirement
105
- none: false
106
121
  requirements:
107
- - - ! '>='
122
+ - - '>='
108
123
  - !ruby/object:Gem::Version
109
124
  version: '0'
110
- segments:
111
- - 0
112
- hash: 2804599532514623618
113
125
  required_rubygems_version: !ruby/object:Gem::Requirement
114
- none: false
115
126
  requirements:
116
- - - ! '>='
127
+ - - '>='
117
128
  - !ruby/object:Gem::Version
118
129
  version: '0'
119
- segments:
120
- - 0
121
- hash: 2804599532514623618
122
130
  requirements: []
123
131
  rubyforge_project: robut
124
- rubygems_version: 1.8.24
132
+ rubygems_version: 2.0.3
125
133
  signing_key:
126
- specification_version: 3
134
+ specification_version: 4
127
135
  summary: A simple plugin-enabled HipChat bot
128
136
  test_files:
129
137
  - test/fixtures/bad_location.xml
@@ -150,3 +158,4 @@ test_files:
150
158
  - test/unit/storage/hash_store_test.rb
151
159
  - test/unit/storage/yaml_store_test.rb
152
160
  - test/unit/storage/yaml_test.yml
161
+ - test/unit/web_test.rb