poundie 0.0.4 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/poundie.rb +2 -2
- data/lib/poundie/campfire/message.rb +3 -3
- data/lib/poundie/campfire/user.rb +11 -0
- data/lib/poundie/plugin.rb +2 -1
- data/lib/poundie/runner.rb +4 -5
- metadata +20 -8
data/lib/poundie.rb
CHANGED
@@ -6,6 +6,8 @@ require "yaml"
|
|
6
6
|
require "readline"
|
7
7
|
require "typhoeus"
|
8
8
|
require "json"
|
9
|
+
require "uri"
|
10
|
+
require "yajl/http_stream"
|
9
11
|
|
10
12
|
require "poundie/runner"
|
11
13
|
require "poundie/plugin"
|
@@ -14,8 +16,6 @@ require "poundie/campfire/message"
|
|
14
16
|
require "poundie/plugins/greeter"
|
15
17
|
require "poundie/plugins/debug"
|
16
18
|
|
17
|
-
trap('INT') { puts "ok bye!" ; exit! }
|
18
|
-
|
19
19
|
module Poundie
|
20
20
|
def self.start(name="default")
|
21
21
|
name.gsub!(/\W/, '_')
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Poundie
|
2
2
|
module Campfire
|
3
3
|
class Message
|
4
|
-
def initialize(hash)
|
5
|
-
@hash = hash
|
4
|
+
def initialize(room, hash)
|
5
|
+
@room, @hash = room, hash
|
6
6
|
end
|
7
7
|
|
8
8
|
def id
|
@@ -22,7 +22,7 @@ module Poundie
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def user
|
25
|
-
Poundie::Campfire::User.
|
25
|
+
Poundie::Campfire::User.get(@room, @hash[:user_id])
|
26
26
|
end
|
27
27
|
|
28
28
|
def type
|
@@ -1,6 +1,17 @@
|
|
1
1
|
module Poundie
|
2
2
|
module Campfire
|
3
3
|
class User
|
4
|
+
def self.get(room, user_id)
|
5
|
+
cache[user_id] || begin
|
6
|
+
json = room.users.detect { |u| u["id"] == user_id }
|
7
|
+
cache[user_id] = Poundie::Campfire::User.new(json)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.cache
|
12
|
+
@cache ||= {}
|
13
|
+
end
|
14
|
+
|
4
15
|
def initialize(hash)
|
5
16
|
@hash = hash
|
6
17
|
end
|
data/lib/poundie/plugin.rb
CHANGED
@@ -36,11 +36,12 @@ module Poundie
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def call(message)
|
39
|
-
message = Poundie::Campfire::Message.new(message)
|
39
|
+
message = Poundie::Campfire::Message.new(@room, message)
|
40
40
|
begin
|
41
41
|
match?(message) && perform(message)
|
42
42
|
rescue => e
|
43
43
|
puts "ERROR: #{e.message}"
|
44
|
+
puts " #{e.backtrace.join("\n")}"
|
44
45
|
raise e
|
45
46
|
end
|
46
47
|
end
|
data/lib/poundie/runner.rb
CHANGED
@@ -8,12 +8,11 @@ module Poundie
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def run
|
11
|
-
|
12
|
-
|
11
|
+
url = URI.parse("http://#{@token}:x@streaming.campfirenow.com//room/#{room.id}/live.json")
|
12
|
+
puts "Starting stream: #{url.inspect}"
|
13
|
+
Yajl::HttpStream.get(url, :symbolize_keys => true) do |message|
|
13
14
|
Thread.new do
|
14
|
-
plugins.each { |plugin|
|
15
|
-
plugin.call(line)
|
16
|
-
}
|
15
|
+
plugins.each { |plugin| plugin.call(message) }
|
17
16
|
end
|
18
17
|
end
|
19
18
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poundie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Pat Nakajima
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-05-13 00:00:00
|
19
|
-
default_executable:
|
18
|
+
date: 2011-05-13 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: tinder
|
@@ -46,6 +45,20 @@ dependencies:
|
|
46
45
|
version: "0"
|
47
46
|
type: :runtime
|
48
47
|
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: yajl-ruby
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
type: :runtime
|
61
|
+
version_requirements: *id003
|
49
62
|
description: Uses plugins to interact with campfire rooms
|
50
63
|
email:
|
51
64
|
executables: []
|
@@ -65,7 +78,6 @@ files:
|
|
65
78
|
- lib/poundie/plugins/greeter.rb
|
66
79
|
- lib/poundie/plugins/debug.rb
|
67
80
|
- lib/poundie/runner.rb
|
68
|
-
has_rdoc: true
|
69
81
|
homepage:
|
70
82
|
licenses: []
|
71
83
|
|
@@ -95,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
107
|
requirements: []
|
96
108
|
|
97
109
|
rubyforge_project:
|
98
|
-
rubygems_version: 1.
|
110
|
+
rubygems_version: 1.8.2
|
99
111
|
signing_key:
|
100
112
|
specification_version: 3
|
101
113
|
summary: A campfire bot
|