firering 0.1.1 → 1.0.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.
- data/README.rdoc +26 -26
- data/Rakefile +1 -1
- data/bin/campf-notify +27 -33
- data/examples/authenticate.rb +10 -8
- data/examples/events.rb +17 -8
- data/examples/recent_messages.rb +37 -25
- data/examples/rooms.rb +15 -10
- data/examples/update_room.rb +14 -11
- data/firering.gemspec +9 -6
- data/lib/firering/connection.rb +125 -0
- data/lib/firering/data/message.rb +43 -23
- data/lib/firering/data/room.rb +115 -8
- data/lib/firering/data/upload.rb +5 -4
- data/lib/firering/data/user.rb +13 -11
- data/lib/firering/data.rb +26 -19
- data/lib/firering/requests.rb +31 -167
- data/lib/firering.rb +10 -11
- data/log/.gitignore +1 -0
- data/spec/firering/connection_spec.rb +25 -0
- data/spec/firering/data/message_spec.rb +61 -0
- data/spec/firering/data/room_spec.rb +206 -0
- data/spec/firering/data/user_spec.rb +21 -0
- data/spec/firering/data_spec.rb +4 -9
- data/spec/fixtures/load_server.rb +48 -21
- data/spec/spec_helper.rb +12 -0
- data/spec/support/helpers.rb +11 -0
- metadata +17 -11
- data/lib/firering/http.rb +0 -53
- data/lib/firering/streaming.rb +0 -51
- data/spec/firering/requests_spec.rb +0 -203
- data/spec/fixtures/server.rb +0 -40
@@ -0,0 +1,206 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Firering::Room do
|
4
|
+
|
5
|
+
it "gets a single room" do
|
6
|
+
EM.run {
|
7
|
+
conn.room(304355) do |room|
|
8
|
+
|
9
|
+
room.name.should == "test2"
|
10
|
+
room.created_at.should == Date.parse("2010/05/29 21:38:02 +0000")
|
11
|
+
room.updated_at.should == Date.parse("2010/05/29 21:38:02 +0000")
|
12
|
+
room.topic.should == "this and the test room should be deleted by a campfire admin."
|
13
|
+
room.should_not be_full
|
14
|
+
room.id.should == 304355
|
15
|
+
room.should_not be_open_to_guests
|
16
|
+
room.membership_limit.should == 12
|
17
|
+
room.should_not be_locked
|
18
|
+
|
19
|
+
room.users do |users|
|
20
|
+
users.each do |u|
|
21
|
+
u.should be_an_instance_of(Firering::User)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
EM.stop
|
26
|
+
end
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
it "gets all rooms" do
|
31
|
+
EM.run {
|
32
|
+
conn.rooms do |rooms|
|
33
|
+
rooms.each do |room|
|
34
|
+
room.should be_an_instance_of(Firering::Room)
|
35
|
+
room.users do |users|
|
36
|
+
users.should be_an_instance_of(Array)
|
37
|
+
users.should_not be_empty
|
38
|
+
end
|
39
|
+
end
|
40
|
+
EM.stop
|
41
|
+
end
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
it "updates a room and then calls the block" do
|
46
|
+
EM.run {
|
47
|
+
conn.room(304355) do |room|
|
48
|
+
room.update(:topic => "some topic") do
|
49
|
+
EM.stop
|
50
|
+
end
|
51
|
+
end
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
it "returns the messages of today for a given room" do
|
56
|
+
EM.run {
|
57
|
+
conn.room(304355) do |room|
|
58
|
+
room.today_transcript do |messages|
|
59
|
+
messages.length.should == 33
|
60
|
+
|
61
|
+
messages.each do |m|
|
62
|
+
m.should be_an_instance_of(Firering::Message)
|
63
|
+
end
|
64
|
+
|
65
|
+
message = messages.last
|
66
|
+
|
67
|
+
message.should be_paste
|
68
|
+
message.room_id.should == 304355
|
69
|
+
message.created_at.should == Date.parse("2010/05/29 22:41:34 +0000")
|
70
|
+
message.body.should == "paste\ntext"
|
71
|
+
message.id.should == 224590114
|
72
|
+
message.user_id.should == 415731
|
73
|
+
|
74
|
+
EM.stop
|
75
|
+
end
|
76
|
+
end
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
it "returns the messages of an specific date for a given room" do
|
81
|
+
EM.run {
|
82
|
+
conn.room(304355) do |room|
|
83
|
+
room.transcript(2010, 12, 12) do |messages|
|
84
|
+
|
85
|
+
messages.length.should == 33
|
86
|
+
|
87
|
+
messages.each do |m|
|
88
|
+
m.should be_an_instance_of(Firering::Message)
|
89
|
+
end
|
90
|
+
|
91
|
+
message = messages.last
|
92
|
+
|
93
|
+
message.should be_paste
|
94
|
+
message.room_id.should == 304355
|
95
|
+
message.created_at.should == Date.parse("2010/05/29 22:41:34 +0000")
|
96
|
+
message.body.should == "paste\ntext"
|
97
|
+
message.id.should == 224590114
|
98
|
+
message.user_id.should == 415731
|
99
|
+
|
100
|
+
EM.stop
|
101
|
+
end
|
102
|
+
end
|
103
|
+
}
|
104
|
+
end
|
105
|
+
|
106
|
+
it "joins a room" do
|
107
|
+
EM.run {
|
108
|
+
conn.room(304355) { |room|
|
109
|
+
room.join {
|
110
|
+
EM.stop
|
111
|
+
}
|
112
|
+
}
|
113
|
+
}
|
114
|
+
end
|
115
|
+
|
116
|
+
it "leaves a room" do
|
117
|
+
EM.run {
|
118
|
+
conn.room(304355) { |room|
|
119
|
+
room.leave {
|
120
|
+
EM.stop
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
124
|
+
end
|
125
|
+
|
126
|
+
it "unlocks a room an call a block" do
|
127
|
+
EM.run {
|
128
|
+
conn.room(304355) { |room|
|
129
|
+
room.unlock {
|
130
|
+
EM.stop
|
131
|
+
}
|
132
|
+
}
|
133
|
+
}
|
134
|
+
end
|
135
|
+
|
136
|
+
it "locks a room an call a block" do
|
137
|
+
EM.run {
|
138
|
+
conn.room(304355) { |room|
|
139
|
+
room.lock {
|
140
|
+
EM.stop
|
141
|
+
}
|
142
|
+
}
|
143
|
+
}
|
144
|
+
end
|
145
|
+
|
146
|
+
it "is able to speak a text message" do
|
147
|
+
EM.run {
|
148
|
+
conn.room(304355) { |room|
|
149
|
+
room.text("some text") {
|
150
|
+
EM.stop
|
151
|
+
}
|
152
|
+
}
|
153
|
+
}
|
154
|
+
end
|
155
|
+
|
156
|
+
it "is able to speak a paste message" do
|
157
|
+
EM.run {
|
158
|
+
conn.room(304355) { |room|
|
159
|
+
room.paste("some\ntext") {
|
160
|
+
EM.stop
|
161
|
+
}
|
162
|
+
}
|
163
|
+
}
|
164
|
+
end
|
165
|
+
|
166
|
+
it "is able to speak a tweet" do
|
167
|
+
EM.run {
|
168
|
+
conn.room(304355) { |room|
|
169
|
+
room.tweet("http://twitter.com/message") {
|
170
|
+
EM.stop
|
171
|
+
}
|
172
|
+
}
|
173
|
+
}
|
174
|
+
end
|
175
|
+
|
176
|
+
it "is able to play a rimshot" do
|
177
|
+
EM.run {
|
178
|
+
conn.room(304355) { |room|
|
179
|
+
room.rimshot {
|
180
|
+
EM.stop
|
181
|
+
}
|
182
|
+
}
|
183
|
+
}
|
184
|
+
end
|
185
|
+
|
186
|
+
it "is able to play crickets" do
|
187
|
+
EM.run {
|
188
|
+
conn.room(304355) { |room|
|
189
|
+
room.crickets {
|
190
|
+
EM.stop
|
191
|
+
}
|
192
|
+
}
|
193
|
+
}
|
194
|
+
end
|
195
|
+
|
196
|
+
it "is able to play a trombone" do
|
197
|
+
EM.run {
|
198
|
+
conn.room(304355) { |room|
|
199
|
+
room.trombone {
|
200
|
+
EM.stop
|
201
|
+
}
|
202
|
+
}
|
203
|
+
}
|
204
|
+
end
|
205
|
+
|
206
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Firering::User do
|
4
|
+
|
5
|
+
it "gets a user info" do
|
6
|
+
EM.run {
|
7
|
+
conn.user(415731) do |user|
|
8
|
+
|
9
|
+
user.type.should == "Member"
|
10
|
+
user.created_at.should == Date.parse("2009/01/27 19:54:36 +0000")
|
11
|
+
user.email_address.should == "eoga@mail.com"
|
12
|
+
user.should_not be_admin
|
13
|
+
user.id.should == 415731
|
14
|
+
user.name.should == "Emmanuel"
|
15
|
+
|
16
|
+
EM.stop
|
17
|
+
end
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/spec/firering/data_spec.rb
CHANGED
@@ -1,21 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
class TestData < Firering::Data
|
4
|
-
|
4
|
+
data_attributes :a, :b
|
5
5
|
end
|
6
6
|
|
7
7
|
describe Firering::Data do
|
8
8
|
|
9
|
-
it "
|
10
|
-
object = TestData.
|
11
|
-
object.a.should == 1
|
12
|
-
object.b.should == 2
|
13
|
-
end
|
14
|
-
|
15
|
-
it "can be initialized from a json string" do
|
16
|
-
object = TestData.new('{"testdata" : { "a" : 1, "b" : 2}}', :testdata)
|
9
|
+
it "initializes an object from a hash with a base key, and defines accessors" do
|
10
|
+
object = TestData.instantiate(:connection, {:test_data => { :a => 1, :b => 2}}, :test_data)
|
17
11
|
object.a.should == 1
|
18
12
|
object.b.should == 2
|
13
|
+
object.connection.should == :connection
|
19
14
|
end
|
20
15
|
|
21
16
|
end
|
@@ -1,31 +1,58 @@
|
|
1
1
|
require 'open-uri'
|
2
2
|
|
3
|
-
|
3
|
+
class MyLogger < Logger
|
4
|
+
alias write <<
|
5
|
+
end
|
4
6
|
|
5
|
-
|
7
|
+
class FixtureServer < Struct.new(:logger)
|
8
|
+
def call(env)
|
9
|
+
req = Rack::Request.new(env)
|
10
|
+
res = Rack::Response.new
|
11
|
+
res.write read_fixture(req)
|
12
|
+
res.finish
|
13
|
+
end
|
6
14
|
|
7
|
-
|
8
|
-
|
15
|
+
def read_fixture(req)
|
16
|
+
return "It Works!" if req.path == "" || req.path == "/"
|
17
|
+
fixture = ([req.request_method.to_s.downcase] + req.path.split("/")).join("_").squeeze("_").gsub(/\d+/, "ID")
|
18
|
+
path = File.expand_path(File.join(File.dirname(__FILE__), "json", fixture))
|
19
|
+
logger.info("opening fixture: #{path}, #{File.file?(path)}")
|
20
|
+
output = File.file?(path) ? File.read(path) : "FIXTURE NOT FOUND #{path}"
|
21
|
+
logger.info("\n\n#{output}\n")
|
22
|
+
output
|
23
|
+
end
|
9
24
|
end
|
10
25
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
open(
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
26
|
+
def start_fixtures_server(port)
|
27
|
+
pid = fork do
|
28
|
+
require 'rack'
|
29
|
+
require 'logger'
|
30
|
+
|
31
|
+
$stdout = $stderr = File.open("/dev/null", "w")
|
32
|
+
|
33
|
+
logger = MyLogger.new(File.join(File.dirname(__FILE__), '..', '..', 'log', "specs.log"))
|
34
|
+
logger.info("\n#{'-'*80}\n")
|
35
|
+
|
36
|
+
app = FixtureServer.new(logger)
|
37
|
+
app = Rack::ShowStatus.new(Rack::ShowExceptions.new(app))
|
38
|
+
app = Rack::CommonLogger.new(app, logger)
|
39
|
+
|
40
|
+
Rack::Handler::WEBrick.run app, :Port => $specs_port
|
22
41
|
end
|
23
|
-
end
|
24
42
|
|
25
|
-
|
26
|
-
|
27
|
-
|
43
|
+
spawned, start = false, Time.now
|
44
|
+
|
45
|
+
while Time.now - start < 5
|
46
|
+
begin
|
47
|
+
open(URI("http://localhost:#{$specs_port}/"))
|
48
|
+
rescue
|
49
|
+
sleep 1
|
50
|
+
else
|
51
|
+
break spawned = true
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
raise "Could not run the fixtures server" unless spawned
|
28
56
|
|
29
|
-
|
30
|
-
Process.kill(:KILL, pid) if pid
|
57
|
+
pid
|
31
58
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,6 +5,18 @@ require 'firering'
|
|
5
5
|
require 'spec'
|
6
6
|
require 'spec/autorun'
|
7
7
|
require 'fixtures/load_server'
|
8
|
+
require 'support/helpers'
|
9
|
+
require 'ap'
|
8
10
|
|
9
11
|
Spec::Runner.configure do |config|
|
12
|
+
config.include Helpers
|
13
|
+
|
14
|
+
config.before :all do
|
15
|
+
$specs_logger = Logger.new(File.join(File.dirname(__FILE__), '..', 'log', "specs.log"))
|
16
|
+
$pid = start_fixtures_server($specs_port = 8909)
|
17
|
+
end
|
18
|
+
|
19
|
+
config.after :all do
|
20
|
+
Process.kill(:KILL, $pid) if $pid
|
21
|
+
end
|
10
22
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: firering
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
7
|
- 1
|
10
|
-
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Emmanuel Oga
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-16 00:00:00 -03:00
|
19
19
|
default_executable: campf-notify
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -119,16 +119,19 @@ files:
|
|
119
119
|
- examples/update_room.rb
|
120
120
|
- firering.gemspec
|
121
121
|
- lib/firering.rb
|
122
|
+
- lib/firering/connection.rb
|
122
123
|
- lib/firering/data.rb
|
123
124
|
- lib/firering/data/message.rb
|
124
125
|
- lib/firering/data/room.rb
|
125
126
|
- lib/firering/data/upload.rb
|
126
127
|
- lib/firering/data/user.rb
|
127
|
-
- lib/firering/http.rb
|
128
128
|
- lib/firering/requests.rb
|
129
|
-
-
|
129
|
+
- log/.gitignore
|
130
|
+
- spec/firering/connection_spec.rb
|
131
|
+
- spec/firering/data/message_spec.rb
|
132
|
+
- spec/firering/data/room_spec.rb
|
133
|
+
- spec/firering/data/user_spec.rb
|
130
134
|
- spec/firering/data_spec.rb
|
131
|
-
- spec/firering/requests_spec.rb
|
132
135
|
- spec/fixtures/headers/delete_messages_ID_star.json
|
133
136
|
- spec/fixtures/headers/get_room_ID.json
|
134
137
|
- spec/fixtures/headers/get_room_ID_live.json
|
@@ -166,8 +169,8 @@ files:
|
|
166
169
|
- spec/fixtures/json/put_room_ID.json
|
167
170
|
- spec/fixtures/load_server.rb
|
168
171
|
- spec/fixtures/retrieve.rb
|
169
|
-
- spec/fixtures/server.rb
|
170
172
|
- spec/spec_helper.rb
|
173
|
+
- spec/support/helpers.rb
|
171
174
|
has_rdoc: true
|
172
175
|
homepage: http://github.com/EmmanuelOga/firering
|
173
176
|
licenses: []
|
@@ -203,8 +206,11 @@ signing_key:
|
|
203
206
|
specification_version: 2
|
204
207
|
summary: Campfire API interface powered by EventMachine and Yajl.
|
205
208
|
test_files:
|
209
|
+
- spec/firering/connection_spec.rb
|
210
|
+
- spec/firering/data/message_spec.rb
|
211
|
+
- spec/firering/data/room_spec.rb
|
212
|
+
- spec/firering/data/user_spec.rb
|
206
213
|
- spec/firering/data_spec.rb
|
207
|
-
- spec/firering/requests_spec.rb
|
208
214
|
- spec/fixtures/headers/delete_messages_ID_star.json
|
209
215
|
- spec/fixtures/headers/get_room_ID.json
|
210
216
|
- spec/fixtures/headers/get_room_ID_live.json
|
@@ -242,5 +248,5 @@ test_files:
|
|
242
248
|
- spec/fixtures/json/put_room_ID.json
|
243
249
|
- spec/fixtures/load_server.rb
|
244
250
|
- spec/fixtures/retrieve.rb
|
245
|
-
- spec/fixtures/server.rb
|
246
251
|
- spec/spec_helper.rb
|
252
|
+
- spec/support/helpers.rb
|
data/lib/firering/http.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
module Firering
|
2
|
-
module HTTP
|
3
|
-
extend self
|
4
|
-
|
5
|
-
attr_accessor :host, :retry_delay
|
6
|
-
|
7
|
-
HTTP.host = "campfirenow.com"
|
8
|
-
HTTP.retry_delay = 2
|
9
|
-
|
10
|
-
# helper to perform an http request following redirects
|
11
|
-
def http(method, path, data = nil, user = Firering.token, password = "X", &block)
|
12
|
-
|
13
|
-
if (path =~ /^http/)
|
14
|
-
url = path
|
15
|
-
else
|
16
|
-
# handle nil subdomain for testing (e.g a fake localhost campfire server)
|
17
|
-
url = "http://#{[Firering.subdomain, HTTP.host].compact.join(".")}#{path}"
|
18
|
-
end
|
19
|
-
|
20
|
-
parameters = { :head => {'authorization' => [user, password], "Content-Type" => "application/json" } }
|
21
|
-
parameters.merge!(:body => data.is_a?(String) ? data : Yajl::Encoder.encode(data)) if data
|
22
|
-
|
23
|
-
http = EventMachine::HttpRequest.new(url).send method, parameters
|
24
|
-
|
25
|
-
http.errback do
|
26
|
-
if EventMachine.reactor_running?
|
27
|
-
puts "Error: #{http.error}. Trying again in #{HTTP.retry_delay} seconds..."
|
28
|
-
|
29
|
-
EventMachine::add_timer(HTTP.retry_delay) do
|
30
|
-
puts "reconnecting"
|
31
|
-
http(method, path, data, user, password, &block)
|
32
|
-
end
|
33
|
-
else
|
34
|
-
raise Firering::Error, "#{http.error}\n#{url}, #{method}, #{parameters.inspect}\n#{http.response_header.status}\n#{http.response}"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
http.callback do
|
39
|
-
case http.response_header.status.to_s
|
40
|
-
when /^2../
|
41
|
-
block.call(http)
|
42
|
-
when "302"
|
43
|
-
http(method, http.response_header["Location"], user, password, &block) # follow redirects
|
44
|
-
else
|
45
|
-
raise Firering::Error, "#{http.error}\n#{url}, #{method}, #{parameters.inspect}\n#{http.response_header.status}\n#{http.response}"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
http
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
end
|
data/lib/firering/streaming.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
module Firering
|
2
|
-
module Streaming
|
3
|
-
extend self
|
4
|
-
|
5
|
-
attr_accessor :protocol, :host, :reconnect_delay
|
6
|
-
|
7
|
-
Streaming.host = "streaming.campfirenow.com"
|
8
|
-
Streaming.protocol = "https"
|
9
|
-
Streaming.reconnect_delay = 5
|
10
|
-
|
11
|
-
# Streaming
|
12
|
-
#
|
13
|
-
# The Streaming API allows you to monitor a room in real time. The
|
14
|
-
# authenticated user must already have joined the room in order to use this
|
15
|
-
# API.
|
16
|
-
def stream(room_id, url = nil, &block)
|
17
|
-
parser = Yajl::Parser.new(:symbolize_keys => true)
|
18
|
-
|
19
|
-
parser.on_parse_complete = proc do |hash|
|
20
|
-
block.call(Firering::Message.new(hash))
|
21
|
-
end
|
22
|
-
|
23
|
-
url ||= "#{Streaming.protocol}://#{Streaming.host}/room/#{room_id}/live.json"
|
24
|
-
|
25
|
-
params = { :head => {'authorization' => [Firering.token, "X"], "Content-Type" => "application/json" } }
|
26
|
-
|
27
|
-
http = EventMachine::HttpRequest.new(url).get(params)
|
28
|
-
|
29
|
-
http.stream { |chunk| parser << chunk }
|
30
|
-
|
31
|
-
# campfire servers will try to hold the streaming connections open indefinitely.
|
32
|
-
# However, API clients must be able to handle occasional timeouts or
|
33
|
-
# disruptions. Upon unexpected disconnection, API clients should wait for a
|
34
|
-
# few seconds before trying to reconnect. Formats
|
35
|
-
http.errback do
|
36
|
-
if EventMachine.reactor_running?
|
37
|
-
puts "Error: #{http.error}. Reconnecting in #{Streaming.reconnect_delay} seconds..."
|
38
|
-
|
39
|
-
EventMachine::add_timer(Streaming.reconnect_delay) do
|
40
|
-
puts "reconnecting"
|
41
|
-
stream(room_id, url, &block)
|
42
|
-
end
|
43
|
-
else
|
44
|
-
puts "EventMachine loop stopped."
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|