firering 1.0.3 → 1.0.4
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 +4 -0
- data/Rakefile +3 -9
- data/firering.gemspec +8 -8
- data/lib/firering/connection.rb +1 -1
- data/lib/firering/data/message.rb +43 -40
- data/lib/firering/data/room.rb +96 -94
- data/lib/firering/data/upload.rb +5 -4
- data/lib/firering/data/user.rb +14 -12
- data/lib/firering/instantiator.rb +22 -0
- data/lib/firering.rb +9 -9
- data/spec/firering/data/message_spec.rb +3 -3
- data/spec/firering/data/room_spec.rb +4 -4
- data/spec/firering/data/user_spec.rb +1 -1
- data/spec/firering/data_spec.rb +6 -4
- data/spec/spec_helper.rb +3 -4
- metadata +20 -20
- data/lib/firering/data.rb +0 -42
data/README.rdoc
CHANGED
|
@@ -78,6 +78,10 @@ For more details take a look at spec/fixtures/load_server.rb file.
|
|
|
78
78
|
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
|
79
79
|
* Send me a pull request. Bonus points for topic branches.
|
|
80
80
|
|
|
81
|
+
== Contributors
|
|
82
|
+
|
|
83
|
+
* indirect (Andre Arko), https://github.com/EmmanuelOga/firering/pull/1
|
|
84
|
+
|
|
81
85
|
== Copyright
|
|
82
86
|
|
|
83
87
|
Copyright (c) 2010 Emmanuel Oga. See LICENSE for details.
|
data/Rakefile
CHANGED
|
@@ -43,17 +43,11 @@ end
|
|
|
43
43
|
#
|
|
44
44
|
#############################################################################
|
|
45
45
|
|
|
46
|
-
require '
|
|
46
|
+
require 'rspec/core/rake_task'
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
spec.
|
|
50
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
|
54
|
-
spec.libs << 'lib' << 'spec'
|
|
48
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
49
|
+
spec.ruby_opts = '-I lib'
|
|
55
50
|
spec.pattern = 'spec/**/*_spec.rb'
|
|
56
|
-
spec.rcov = true
|
|
57
51
|
end
|
|
58
52
|
|
|
59
53
|
task :default => :spec
|
data/firering.gemspec
CHANGED
|
@@ -4,8 +4,8 @@ Gem::Specification.new do |s|
|
|
|
4
4
|
s.rubygems_version = '1.3.5'
|
|
5
5
|
|
|
6
6
|
s.name = 'firering'
|
|
7
|
-
s.version = '1.0.
|
|
8
|
-
s.date = '
|
|
7
|
+
s.version = '1.0.4'
|
|
8
|
+
s.date = '2011-02-24'
|
|
9
9
|
s.rubyforge_project = 'firering'
|
|
10
10
|
|
|
11
11
|
s.summary = "Campfire API interface powered by eventmachine em-http-request and yajl-ruby."
|
|
@@ -23,12 +23,12 @@ Gem::Specification.new do |s|
|
|
|
23
23
|
s.rdoc_options = ["--charset=UTF-8"]
|
|
24
24
|
s.extra_rdoc_files = %w[README.rdoc LICENSE]
|
|
25
25
|
|
|
26
|
-
s.add_dependency('eventmachine', ["
|
|
27
|
-
s.add_dependency('em-http-request', ["
|
|
28
|
-
s.add_dependency('yajl-ruby', ["
|
|
26
|
+
s.add_dependency('eventmachine', ["~> 0.12.10"])
|
|
27
|
+
s.add_dependency('em-http-request', ["~> 0.3.0"])
|
|
28
|
+
s.add_dependency('yajl-ruby', ["~> 0.7.6"])
|
|
29
29
|
|
|
30
|
-
s.add_development_dependency('rspec', ["
|
|
31
|
-
s.add_development_dependency('
|
|
30
|
+
s.add_development_dependency('rspec', ["~> 2.1.0"])
|
|
31
|
+
s.add_development_dependency('rack', [">= 1.2.0"])
|
|
32
32
|
|
|
33
33
|
# = MANIFEST =
|
|
34
34
|
s.files = %w[
|
|
@@ -44,11 +44,11 @@ Gem::Specification.new do |s|
|
|
|
44
44
|
firering.gemspec
|
|
45
45
|
lib/firering.rb
|
|
46
46
|
lib/firering/connection.rb
|
|
47
|
-
lib/firering/data.rb
|
|
48
47
|
lib/firering/data/message.rb
|
|
49
48
|
lib/firering/data/room.rb
|
|
50
49
|
lib/firering/data/upload.rb
|
|
51
50
|
lib/firering/data/user.rb
|
|
51
|
+
lib/firering/instantiator.rb
|
|
52
52
|
lib/firering/requests.rb
|
|
53
53
|
log/.gitignore
|
|
54
54
|
spec/firering/connection_spec.rb
|
data/lib/firering/connection.rb
CHANGED
|
@@ -101,7 +101,7 @@ module Firering
|
|
|
101
101
|
# Campfire servers will try to hold the streaming connections open indefinitely.
|
|
102
102
|
# However, API clients must be able to handle occasional timeouts or
|
|
103
103
|
# disruptions. Upon unexpected disconnection, API clients should wait for a
|
|
104
|
-
# few seconds before trying to reconnect.
|
|
104
|
+
# few seconds before trying to reconnect.
|
|
105
105
|
http.errback do
|
|
106
106
|
perform_retry(http) do
|
|
107
107
|
room.stream(&callback)
|
|
@@ -1,49 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
module Firering
|
|
2
|
+
Message = Struct.new(:connection, :id, :room_id, :user_id, :body, :created_at, :type)
|
|
3
|
+
|
|
4
|
+
class Message
|
|
5
|
+
extend Instantiator
|
|
6
|
+
|
|
7
|
+
MESSAGE_TYPES = %w[
|
|
8
|
+
TextMessage PasteMessage SoundMessage AdvertisementMessage
|
|
9
|
+
AllowGuestsMessage DisallowGuestsMessage IdleMessage KickMessage
|
|
10
|
+
LeaveMessage SystemMessage TimestampMessage TopicChangeMessage
|
|
11
|
+
UnidleMessage UnlockMessage UploadMessage
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
# txs activesupport
|
|
15
|
+
underscore = proc do |word|
|
|
16
|
+
w = word.to_s.gsub(/::/, '/')
|
|
17
|
+
w = w.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
|
18
|
+
w = w.gsub(/([a-z\d])([A-Z])/,'\1_\2')
|
|
19
|
+
w.tr("-", "_").downcase
|
|
20
|
+
end
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
MESSAGE_TYPES.each do |message_type|
|
|
23
|
+
current_type = (message_type =~ /(.+)Message/) && $1
|
|
24
|
+
define_method("#{underscore[current_type]}?") do
|
|
25
|
+
type == message_type
|
|
26
|
+
end
|
|
24
27
|
end
|
|
25
|
-
end
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
def from_user?
|
|
30
|
+
!user_id.nil? && (!user_id.instance_of?(String) || user_id !~ /^\s*$/)
|
|
31
|
+
end
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
# Highlights a message / Removes a message highlight.
|
|
34
|
+
def star(id, yes_or_no = true, &callback)
|
|
35
|
+
connection.star_message(id, yes_or_no, &callback)
|
|
36
|
+
end
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
def room(&callback)
|
|
39
|
+
connection.room(room_id, &callback)
|
|
40
|
+
end
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
def user(&callback)
|
|
43
|
+
if from_user?
|
|
44
|
+
connection.user(user_id, &callback)
|
|
45
|
+
else
|
|
46
|
+
callback.call(nil, connection)
|
|
47
|
+
end
|
|
45
48
|
end
|
|
46
|
-
end
|
|
47
49
|
|
|
48
|
-
|
|
50
|
+
alias_method :to_s, :body
|
|
51
|
+
end
|
|
49
52
|
end
|
data/lib/firering/data/room.rb
CHANGED
|
@@ -1,120 +1,122 @@
|
|
|
1
|
-
|
|
1
|
+
module Firering
|
|
2
|
+
Room = Struct.new(:connection, :id, :name, :topic, :membership_limit, :full, :open_to_guests, :active_token_value, :updated_at, :created_at, :users, :locked)
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
class Room
|
|
5
|
+
extend Instantiator
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
alias_method :locked?, :locked
|
|
8
|
+
alias_method :full?, :full
|
|
9
|
+
alias_method :open_to_guests?, :open_to_guests
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
def stream(&callback)
|
|
12
|
+
join { |data, http| connection.stream(self, &callback) }
|
|
13
|
+
end
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
# we perform a request each time so
|
|
16
|
+
# 1) we always are are up to date with the users currently on the room (even if some left)
|
|
17
|
+
# 2) we make sure the users are here even if the room was instantiated from a
|
|
18
|
+
# /rooms request
|
|
19
|
+
def users(&callback)
|
|
20
|
+
connection.http(:get, "/room/#{id}.json") do |data, http| # data can be blank on locked rooms
|
|
21
|
+
callback.call(data ? data[:room][:users].map { |user| Firering::User.instantiate(self, user) } : Array.new) if callback
|
|
22
|
+
end
|
|
21
23
|
end
|
|
22
|
-
end
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
# Updates an existing room. Only admins can rename a room, although any
|
|
26
|
+
# user (except guests) may set the topic. Omitting either key results in
|
|
27
|
+
# that attribute being ignored. To remove a room topic, simply provide an
|
|
28
|
+
# empty topic key.
|
|
29
|
+
#
|
|
30
|
+
# update "name" => "Name", "topic" => "Topic"
|
|
31
|
+
def update(data, &callback)
|
|
32
|
+
connection.http(:put, "/room/#{id}.json", { :room => data }, &callback)
|
|
33
|
+
end
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
# Returns a collection of upto 100 recent messages in the room. Accepts an
|
|
36
|
+
# additional optional parameter ‘limit’ to restrict the number of messages
|
|
37
|
+
# returned.
|
|
38
|
+
def recent_messages(limit = nil, &callback)
|
|
39
|
+
connection.http(:get, "/room/#{id}/recent.json", (limit ? { :limit => limit } : nil)) do |data, http|
|
|
40
|
+
callback.call(data[:messages].map { |msg| Firering::Message.instantiate(connection, msg) }) if callback
|
|
41
|
+
end
|
|
40
42
|
end
|
|
41
|
-
end
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
# Returns all the messages sent today to a room.
|
|
45
|
+
def today_transcript(&callback)
|
|
46
|
+
connection.http(:get, "/room/#{id}/transcript.json") do |data, http|
|
|
47
|
+
callback.call(data[:messages].map { |msg| Firering::Message.instantiate(connection, msg) }) if callback
|
|
48
|
+
end
|
|
47
49
|
end
|
|
48
|
-
end
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
# Returns all the messages sent on a specific date to a room.
|
|
52
|
+
def transcript(year, month, day, &callback)
|
|
53
|
+
connection.http(:get, "/room/#{id}/transcript/#{year}/#{month}/#{day}.json") do |data, http|
|
|
54
|
+
callback.call(data[:messages].map { |msg| Firering::Message.instantiate(connection, msg) }) if callback
|
|
55
|
+
end
|
|
54
56
|
end
|
|
55
|
-
end
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
# Join a room.
|
|
59
|
+
def join(&callback)
|
|
60
|
+
connection.http(:post, "/room/#{id}/join.json", &callback)
|
|
61
|
+
end
|
|
61
62
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
# Leave a room.
|
|
64
|
+
def leave(&callback)
|
|
65
|
+
connection.http(:post, "/room/#{id}/leave.json", &callback)
|
|
66
|
+
end
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
# Locks a room.
|
|
69
|
+
def lock(&callback)
|
|
70
|
+
connection.http(:post, "/room/#{id}/lock.json", &callback)
|
|
71
|
+
end
|
|
71
72
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
# Unlocks a room.
|
|
74
|
+
def unlock(&callback)
|
|
75
|
+
connection.http(:post, "/room/#{id}/unlock.json", &callback)
|
|
76
|
+
end
|
|
76
77
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
78
|
+
# Sends a new message with the currently authenticated user as the sender.
|
|
79
|
+
# The XML for the new message is returned on a successful request.
|
|
80
|
+
#
|
|
81
|
+
# The valid types are:
|
|
82
|
+
#
|
|
83
|
+
# * TextMessage (regular chat message)
|
|
84
|
+
# * PasteMessage (pre-formatted message, rendered in a fixed-width font)
|
|
85
|
+
# * SoundMessage (plays a sound as determined by the message, which can be either “rimshot”, “crickets”, or “trombone”)
|
|
86
|
+
# * TweetMessage (a Twitter status URL to be fetched and inserted into the chat)
|
|
87
|
+
#
|
|
88
|
+
# If an explicit type is omitted, it will be inferred from the content (e.g.,
|
|
89
|
+
# if the message contains new line characters, it will be considered a paste).
|
|
90
|
+
#
|
|
91
|
+
# :type => "TextMessage", :body => "Hello"
|
|
92
|
+
def speak(data, &callback)
|
|
93
|
+
connection.http(:post, "/room/#{id}/speak.json", "message" => data) do |data, http| # Response Status: 201 Created
|
|
94
|
+
callback.call(Firering::Message.instantiate(connection, data, "message"))
|
|
95
|
+
end
|
|
94
96
|
end
|
|
95
|
-
end
|
|
96
97
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
def text(text, &callback)
|
|
99
|
+
speak({:type => "TextMessage", :body => text}, &callback)
|
|
100
|
+
end
|
|
100
101
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
def paste(paste, &callback)
|
|
103
|
+
speak({:type => "PasteMessage", :body => paste}, &callback)
|
|
104
|
+
end
|
|
104
105
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
def rimshot(&callback)
|
|
107
|
+
speak({:type => "SoundMessage", :body => "rimshot"}, &callback)
|
|
108
|
+
end
|
|
108
109
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
def crickets(&callback)
|
|
111
|
+
speak({:type => "SoundMessage", :body => "crickets"}, &callback)
|
|
112
|
+
end
|
|
112
113
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
def trombone(&callback)
|
|
115
|
+
speak({:type => "SoundMessage", :body => "trombone"}, &callback)
|
|
116
|
+
end
|
|
116
117
|
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
def tweet(tweet_url, &callback)
|
|
119
|
+
speak({:type => "TweetMessage", :body => tweet_url}, &callback)
|
|
120
|
+
end
|
|
119
121
|
end
|
|
120
122
|
end
|
data/lib/firering/data/upload.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
data_attributes :id, :name, :room_id, :user_id, :byte_size, :content_type,
|
|
4
|
-
:full_url, :created_at
|
|
1
|
+
module Firering
|
|
2
|
+
Upload = Struct.new(:connection, :id, :name, :room_id, :user_id, :byte_size, :content_type, :full_url, :created_at)
|
|
5
3
|
|
|
4
|
+
class Upload
|
|
5
|
+
extend Instantiator
|
|
6
|
+
end
|
|
6
7
|
end
|
data/lib/firering/data/user.rb
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
module Firering
|
|
2
|
+
User = Struct.new(:connection, :id, :name, :email_address, :admin, :created_at, :type, :api_auth_token)
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
class User
|
|
5
|
+
extend Instantiator
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
alias_method :token, :api_auth_token
|
|
8
|
+
alias_method :admin?, :admin
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
def member?
|
|
11
|
+
type == "Member"
|
|
12
|
+
end
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
def gest?
|
|
15
|
+
type == "Guest"
|
|
16
|
+
end
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
alias_method :to_s, :name
|
|
19
|
+
end
|
|
18
20
|
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Firering
|
|
2
|
+
module Instantiator
|
|
3
|
+
|
|
4
|
+
def instantiate(conn, data, base_key = nil, &callback)
|
|
5
|
+
instance = new
|
|
6
|
+
instance.connection = conn
|
|
7
|
+
|
|
8
|
+
attributes = data.is_a?(Hash) ? data : Yajl::Parser.parse(data, :symbolize_keys => true)
|
|
9
|
+
attributes = attributes[base_key] if base_key
|
|
10
|
+
attributes ||= Hash.new
|
|
11
|
+
|
|
12
|
+
attributes.each do |key, val|
|
|
13
|
+
value = ( key.to_s =~ /(_at|_on)$/ ) ? (Time.parse(val) rescue val) : val
|
|
14
|
+
instance.send("#{key}=", value)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
callback.call(instance) if callback
|
|
18
|
+
instance
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/firering.rb
CHANGED
|
@@ -5,16 +5,16 @@ require 'yajl'
|
|
|
5
5
|
require 'em-http'
|
|
6
6
|
|
|
7
7
|
module Firering
|
|
8
|
-
VERSION = '1.0.
|
|
8
|
+
VERSION = '1.0.4'
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Error = Class.new(StandardError)
|
|
11
11
|
|
|
12
|
-
autoload :Requests
|
|
13
|
-
autoload :Connection
|
|
12
|
+
autoload :Requests , "firering/requests"
|
|
13
|
+
autoload :Connection , "firering/connection"
|
|
14
14
|
|
|
15
|
-
autoload :
|
|
16
|
-
autoload :User
|
|
17
|
-
autoload :Message
|
|
18
|
-
autoload :Room
|
|
19
|
-
autoload :Upload
|
|
15
|
+
autoload :Instantiator , "firering/instantiator"
|
|
16
|
+
autoload :User , "firering/data/user"
|
|
17
|
+
autoload :Message , "firering/data/message"
|
|
18
|
+
autoload :Room , "firering/data/room"
|
|
19
|
+
autoload :Upload , "firering/data/upload"
|
|
20
20
|
end
|
|
@@ -14,7 +14,7 @@ describe Firering::Message do
|
|
|
14
14
|
message = messages.first
|
|
15
15
|
message.should be_timestamp
|
|
16
16
|
message.room_id.should == 304355
|
|
17
|
-
message.created_at.should ==
|
|
17
|
+
message.created_at.should == Time.parse("2010/05/29 22:05:00 +0000")
|
|
18
18
|
message.body.should be_nil
|
|
19
19
|
message.id.should == 224587718
|
|
20
20
|
message.user_id.should be_nil
|
|
@@ -38,8 +38,8 @@ describe Firering::Message do
|
|
|
38
38
|
message = messages.last
|
|
39
39
|
message.should be_text
|
|
40
40
|
message.room_id.should == 177718
|
|
41
|
-
message.created_at.should ==
|
|
42
|
-
message.body.should == "q: should i add :case_sensitive
|
|
41
|
+
message.created_at.should == Time.parse("2009/06/02 21:20:32 +0000")
|
|
42
|
+
message.body.should == "q: should i add :case_sensitive => false to the validation of title name? Looks harmless but who knows..."
|
|
43
43
|
message.id.should == 134405854
|
|
44
44
|
message.user_id.should == 415731
|
|
45
45
|
|
|
@@ -7,8 +7,8 @@ describe Firering::Room do
|
|
|
7
7
|
conn.room(304355) do |room|
|
|
8
8
|
|
|
9
9
|
room.name.should == "test2"
|
|
10
|
-
room.created_at.should ==
|
|
11
|
-
room.updated_at.should ==
|
|
10
|
+
room.created_at.should == Time.parse("2010/05/29 21:38:02 +0000")
|
|
11
|
+
room.updated_at.should == Time.parse("2010/05/29 21:38:02 +0000")
|
|
12
12
|
room.topic.should == "this and the test room should be deleted by a campfire admin."
|
|
13
13
|
room.should_not be_full
|
|
14
14
|
room.id.should == 304355
|
|
@@ -66,7 +66,7 @@ describe Firering::Room do
|
|
|
66
66
|
|
|
67
67
|
message.should be_paste
|
|
68
68
|
message.room_id.should == 304355
|
|
69
|
-
message.created_at.should ==
|
|
69
|
+
message.created_at.should == Time.parse("2010/05/29 22:41:34 +0000")
|
|
70
70
|
message.body.should == "paste\ntext"
|
|
71
71
|
message.id.should == 224590114
|
|
72
72
|
message.user_id.should == 415731
|
|
@@ -92,7 +92,7 @@ describe Firering::Room do
|
|
|
92
92
|
|
|
93
93
|
message.should be_paste
|
|
94
94
|
message.room_id.should == 304355
|
|
95
|
-
message.created_at.should ==
|
|
95
|
+
message.created_at.should == Time.parse("2010/05/29 22:41:34 +0000")
|
|
96
96
|
message.body.should == "paste\ntext"
|
|
97
97
|
message.id.should == 224590114
|
|
98
98
|
message.user_id.should == 415731
|
|
@@ -7,7 +7,7 @@ describe Firering::User do
|
|
|
7
7
|
conn.user(415731) do |user|
|
|
8
8
|
|
|
9
9
|
user.type.should == "Member"
|
|
10
|
-
user.created_at.should ==
|
|
10
|
+
user.created_at.should == Time.parse("2009/01/27 19:54:36 +0000")
|
|
11
11
|
user.email_address.should == "eoga@mail.com"
|
|
12
12
|
user.should_not be_admin
|
|
13
13
|
user.id.should == 415731
|
data/spec/firering/data_spec.rb
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
TestData = Struct.new(:connection, :a, :b)
|
|
4
|
+
|
|
5
|
+
class TestData
|
|
6
|
+
extend Firering::Instantiator
|
|
5
7
|
end
|
|
6
8
|
|
|
7
|
-
describe Firering::
|
|
9
|
+
describe Firering::Instantiator do
|
|
8
10
|
|
|
9
|
-
it "initializes an object from a hash with a base key
|
|
11
|
+
it "initializes an object from a hash with a base key" do
|
|
10
12
|
object = TestData.instantiate(:connection, {:test_data => { :a => 1, :b => 2}}, :test_data)
|
|
11
13
|
object.a.should == 1
|
|
12
14
|
object.b.should == 2
|
data/spec/spec_helper.rb
CHANGED
|
@@ -2,13 +2,12 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
3
3
|
|
|
4
4
|
require 'firering'
|
|
5
|
-
require '
|
|
6
|
-
require '
|
|
5
|
+
require 'rspec'
|
|
6
|
+
require 'rspec/autorun'
|
|
7
7
|
require 'fixtures/load_server'
|
|
8
8
|
require 'support/helpers'
|
|
9
|
-
require 'ap'
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
RSpec.configure do |config|
|
|
12
11
|
config.include Helpers
|
|
13
12
|
|
|
14
13
|
config.before :all do
|
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: 31
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 1
|
|
8
8
|
- 0
|
|
9
|
-
-
|
|
10
|
-
version: 1.0.
|
|
9
|
+
- 4
|
|
10
|
+
version: 1.0.4
|
|
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:
|
|
18
|
+
date: 2011-02-24 00:00:00 -03:00
|
|
19
19
|
default_executable: campf-notify
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|
|
@@ -24,7 +24,7 @@ dependencies:
|
|
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
|
25
25
|
none: false
|
|
26
26
|
requirements:
|
|
27
|
-
- -
|
|
27
|
+
- - ~>
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
29
|
hash: 59
|
|
30
30
|
segments:
|
|
@@ -40,14 +40,14 @@ dependencies:
|
|
|
40
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
|
41
41
|
none: false
|
|
42
42
|
requirements:
|
|
43
|
-
- -
|
|
43
|
+
- - ~>
|
|
44
44
|
- !ruby/object:Gem::Version
|
|
45
|
-
hash:
|
|
45
|
+
hash: 19
|
|
46
46
|
segments:
|
|
47
47
|
- 0
|
|
48
|
-
-
|
|
49
|
-
-
|
|
50
|
-
version: 0.
|
|
48
|
+
- 3
|
|
49
|
+
- 0
|
|
50
|
+
version: 0.3.0
|
|
51
51
|
type: :runtime
|
|
52
52
|
version_requirements: *id002
|
|
53
53
|
- !ruby/object:Gem::Dependency
|
|
@@ -56,7 +56,7 @@ dependencies:
|
|
|
56
56
|
requirement: &id003 !ruby/object:Gem::Requirement
|
|
57
57
|
none: false
|
|
58
58
|
requirements:
|
|
59
|
-
- -
|
|
59
|
+
- - ~>
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
61
|
hash: 15
|
|
62
62
|
segments:
|
|
@@ -72,30 +72,30 @@ dependencies:
|
|
|
72
72
|
requirement: &id004 !ruby/object:Gem::Requirement
|
|
73
73
|
none: false
|
|
74
74
|
requirements:
|
|
75
|
-
- -
|
|
75
|
+
- - ~>
|
|
76
76
|
- !ruby/object:Gem::Version
|
|
77
|
-
hash:
|
|
77
|
+
hash: 11
|
|
78
78
|
segments:
|
|
79
|
+
- 2
|
|
79
80
|
- 1
|
|
80
|
-
- 3
|
|
81
81
|
- 0
|
|
82
|
-
version: 1.
|
|
82
|
+
version: 2.1.0
|
|
83
83
|
type: :development
|
|
84
84
|
version_requirements: *id004
|
|
85
85
|
- !ruby/object:Gem::Dependency
|
|
86
|
-
name:
|
|
86
|
+
name: rack
|
|
87
87
|
prerelease: false
|
|
88
88
|
requirement: &id005 !ruby/object:Gem::Requirement
|
|
89
89
|
none: false
|
|
90
90
|
requirements:
|
|
91
91
|
- - ">="
|
|
92
92
|
- !ruby/object:Gem::Version
|
|
93
|
-
hash:
|
|
93
|
+
hash: 31
|
|
94
94
|
segments:
|
|
95
95
|
- 1
|
|
96
|
+
- 2
|
|
96
97
|
- 0
|
|
97
|
-
|
|
98
|
-
version: 1.0.0
|
|
98
|
+
version: 1.2.0
|
|
99
99
|
type: :development
|
|
100
100
|
version_requirements: *id005
|
|
101
101
|
description: Campfire API interface powered by eventmachine em-http-request and yajl-ruby.
|
|
@@ -120,11 +120,11 @@ files:
|
|
|
120
120
|
- firering.gemspec
|
|
121
121
|
- lib/firering.rb
|
|
122
122
|
- lib/firering/connection.rb
|
|
123
|
-
- lib/firering/data.rb
|
|
124
123
|
- lib/firering/data/message.rb
|
|
125
124
|
- lib/firering/data/room.rb
|
|
126
125
|
- lib/firering/data/upload.rb
|
|
127
126
|
- lib/firering/data/user.rb
|
|
127
|
+
- lib/firering/instantiator.rb
|
|
128
128
|
- lib/firering/requests.rb
|
|
129
129
|
- log/.gitignore
|
|
130
130
|
- spec/firering/connection_spec.rb
|
data/lib/firering/data.rb
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
module Firering
|
|
2
|
-
class Data
|
|
3
|
-
# Generates methods to access the data stored in the @data Hash
|
|
4
|
-
def self.data_attributes(*keys)
|
|
5
|
-
include Module.new {
|
|
6
|
-
keys.each do |key|
|
|
7
|
-
module_eval <<-CODE, __FILE__, __LINE__
|
|
8
|
-
def #{key}
|
|
9
|
-
@_attributes[#{key.to_sym.inspect}]
|
|
10
|
-
end
|
|
11
|
-
CODE
|
|
12
|
-
end
|
|
13
|
-
}
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
attr_accessor :connection
|
|
17
|
-
|
|
18
|
-
# factory method to instantiate data classes
|
|
19
|
-
def self.instantiate(conn, data, base_key= nil, &callback)
|
|
20
|
-
instance = new
|
|
21
|
-
instance.connection = conn
|
|
22
|
-
instance.initialize_attributes(data, base_key)
|
|
23
|
-
callback.call(instance) if callback
|
|
24
|
-
instance
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# data is a hash or a json encoded hash (String)
|
|
28
|
-
# base_key if present is the main data key on the hash.
|
|
29
|
-
def initialize_attributes(data, base_key = nil)
|
|
30
|
-
@_attributes = data.is_a?(Hash) ? data : Yajl::Parser.parse(data, :symbolize_keys => true)
|
|
31
|
-
@_attributes = @_attributes[base_key] if base_key
|
|
32
|
-
@_attributes ||= Hash.new
|
|
33
|
-
@_attributes.each do |key, val|
|
|
34
|
-
@_attributes[key] = Date.parse(val) rescue val if key.to_s =~ /(_at|_on)$/
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def inspect
|
|
39
|
-
"<#{self.class.name} #{@_attributes.inspect}>"
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|