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 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 'spec/rake/spectask'
46
+ require 'rspec/core/rake_task'
47
47
 
48
- Spec::Rake::SpecTask.new(:spec) do |spec|
49
- spec.libs << 'lib' << '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.3'
8
- s.date = '2010-10-12'
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', [">= 0.12.10"])
27
- s.add_dependency('em-http-request', [">= 0.2.10"])
28
- s.add_dependency('yajl-ruby', [">= 0.7.6"])
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', [">= 1.3.0"])
31
- s.add_development_dependency('sinatra', [">= 1.0.0"])
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
@@ -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. Formats
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
- class Firering::Message < Firering::Data
2
-
3
- data_attributes :id, :room_id, :user_id, :body, :created_at, :type
4
-
5
- MESSAGE_TYPES = %w[
6
- TextMessage PasteMessage SoundMessage AdvertisementMessage
7
- AllowGuestsMessage DisallowGuestsMessage IdleMessage KickMessage
8
- LeaveMessage SystemMessage TimestampMessage TopicChangeMessage
9
- UnidleMessage UnlockMessage UploadMessage
10
- ]
11
-
12
- # txs activesupport
13
- underscore = proc do |word|
14
- w = word.to_s.gsub(/::/, '/')
15
- w = w.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
16
- w = w.gsub(/([a-z\d])([A-Z])/,'\1_\2')
17
- w.tr("-", "_").downcase
18
- end
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
- MESSAGE_TYPES.each do |message_type|
21
- current_type = (message_type =~ /(.+)Message/) && $1
22
- define_method("#{underscore[current_type]}?") do
23
- type == message_type
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
- def from_user?
28
- !user_id.nil? && (!user_id.instance_of?(String) || user_id !~ /^\s*$/)
29
- end
29
+ def from_user?
30
+ !user_id.nil? && (!user_id.instance_of?(String) || user_id !~ /^\s*$/)
31
+ end
30
32
 
31
- # Highlights a message / Removes a message highlight.
32
- def star(id, yes_or_no = true, &callback)
33
- connection.star_message(id, yes_or_no, &callback)
34
- end
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
- def room(&callback)
37
- connection.room(room_id, &callback)
38
- end
38
+ def room(&callback)
39
+ connection.room(room_id, &callback)
40
+ end
39
41
 
40
- def user(&callback)
41
- if from_user?
42
- connection.user(user_id, &callback)
43
- else
44
- callback.call(nil, connection)
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
- alias_method :to_s, :body
50
+ alias_method :to_s, :body
51
+ end
49
52
  end
@@ -1,120 +1,122 @@
1
- class Firering::Room < Firering::Data
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
- data_attributes :id, :name, :topic, :membership_limit, :full, :open_to_guests,
4
- :active_token_value, :updated_at, :created_at, :users, :locked
4
+ class Room
5
+ extend Instantiator
5
6
 
6
- alias_method :locked?, :locked
7
- alias_method :full?, :full
8
- alias_method :open_to_guests?, :open_to_guests
7
+ alias_method :locked?, :locked
8
+ alias_method :full?, :full
9
+ alias_method :open_to_guests?, :open_to_guests
9
10
 
10
- def stream(&callback)
11
- join { |data, http| connection.stream(self, &callback) }
12
- end
11
+ def stream(&callback)
12
+ join { |data, http| connection.stream(self, &callback) }
13
+ end
13
14
 
14
- # we perform a request each time so
15
- # 1) we always are are up to date with the users currently on the room (even if some left)
16
- # 2) we make sure the users are here even if the room was instantiated from a
17
- # /rooms request
18
- def users(&callback)
19
- connection.http(:get, "/room/#{id}.json") do |data, http| # data can be blank on locked rooms
20
- callback.call(data ? data[:room][:users].map { |user| Firering::User.instantiate(self, user) } : Array.new) if callback
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
- # Updates an existing room. Only admins can rename a room, although any
25
- # user (except guests) may set the topic. Omitting either key results in
26
- # that attribute being ignored. To remove a room topic, simply provide an
27
- # empty topic key.
28
- #
29
- # update "name" => "Name", "topic" => "Topic"
30
- def update(data, &callback)
31
- connection.http(:put, "/room/#{id}.json", { :room => data }, &callback)
32
- end
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
- # Returns a collection of upto 100 recent messages in the room. Accepts an
35
- # additional optional parameter ‘limit’ to restrict the number of messages
36
- # returned.
37
- def recent_messages(limit = nil, &callback)
38
- connection.http(:get, "/room/#{id}/recent.json", (limit ? { :limit => limit } : nil)) do |data, http|
39
- callback.call(data[:messages].map { |msg| Firering::Message.instantiate(connection, msg) }) if callback
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
- # Returns all the messages sent today to a room.
44
- def today_transcript(&callback)
45
- connection.http(:get, "/room/#{id}/transcript.json") do |data, http|
46
- callback.call(data[:messages].map { |msg| Firering::Message.instantiate(connection, msg) }) if callback
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
- # Returns all the messages sent on a specific date to a room.
51
- def transcript(year, month, day, &callback)
52
- connection.http(:get, "/room/#{id}/transcript/#{year}/#{month}/#{day}.json") do |data, http|
53
- callback.call(data[:messages].map { |msg| Firering::Message.instantiate(connection, msg) }) if callback
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
- # Join a room.
58
- def join(&callback)
59
- connection.http(:post, "/room/#{id}/join.json", &callback)
60
- end
58
+ # Join a room.
59
+ def join(&callback)
60
+ connection.http(:post, "/room/#{id}/join.json", &callback)
61
+ end
61
62
 
62
- # Leave a room.
63
- def leave(&callback)
64
- connection.http(:post, "/room/#{id}/leave.json", &callback)
65
- end
63
+ # Leave a room.
64
+ def leave(&callback)
65
+ connection.http(:post, "/room/#{id}/leave.json", &callback)
66
+ end
66
67
 
67
- # Locks a room.
68
- def lock(&callback)
69
- connection.http(:post, "/room/#{id}/lock.json", &callback)
70
- end
68
+ # Locks a room.
69
+ def lock(&callback)
70
+ connection.http(:post, "/room/#{id}/lock.json", &callback)
71
+ end
71
72
 
72
- # Unlocks a room.
73
- def unlock(&callback)
74
- connection.http(:post, "/room/#{id}/unlock.json", &callback)
75
- end
73
+ # Unlocks a room.
74
+ def unlock(&callback)
75
+ connection.http(:post, "/room/#{id}/unlock.json", &callback)
76
+ end
76
77
 
77
- # Sends a new message with the currently authenticated user as the sender.
78
- # The XML for the new message is returned on a successful request.
79
- #
80
- # The valid types are:
81
- #
82
- # * TextMessage (regular chat message)
83
- # * PasteMessage (pre-formatted message, rendered in a fixed-width font)
84
- # * SoundMessage (plays a sound as determined by the message, which can be either “rimshot”, “crickets”, or “trombone”)
85
- # * TweetMessage (a Twitter status URL to be fetched and inserted into the chat)
86
- #
87
- # If an explicit type is omitted, it will be inferred from the content (e.g.,
88
- # if the message contains new line characters, it will be considered a paste).
89
- #
90
- # :type => "TextMessage", :body => "Hello"
91
- def speak(data, &callback)
92
- connection.http(:post, "/room/#{id}/speak.json", "message" => data) do |data, http| # Response Status: 201 Created
93
- callback.call(Firering::Message.instantiate(connection, data))
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
- def text(text, &callback)
98
- speak({:type => "TextMessage", :body => text}, &callback)
99
- end
98
+ def text(text, &callback)
99
+ speak({:type => "TextMessage", :body => text}, &callback)
100
+ end
100
101
 
101
- def paste(paste, &callback)
102
- speak({:type => "PasteMessage", :body => paste}, &callback)
103
- end
102
+ def paste(paste, &callback)
103
+ speak({:type => "PasteMessage", :body => paste}, &callback)
104
+ end
104
105
 
105
- def rimshot(&callback)
106
- speak({:type => "SoundMessage", :body => "rimshot"}, &callback)
107
- end
106
+ def rimshot(&callback)
107
+ speak({:type => "SoundMessage", :body => "rimshot"}, &callback)
108
+ end
108
109
 
109
- def crickets(&callback)
110
- speak({:type => "SoundMessage", :body => "crickets"}, &callback)
111
- end
110
+ def crickets(&callback)
111
+ speak({:type => "SoundMessage", :body => "crickets"}, &callback)
112
+ end
112
113
 
113
- def trombone(&callback)
114
- speak({:type => "SoundMessage", :body => "trombone"}, &callback)
115
- end
114
+ def trombone(&callback)
115
+ speak({:type => "SoundMessage", :body => "trombone"}, &callback)
116
+ end
116
117
 
117
- def tweet(tweet_url, &callback)
118
- speak({:type => "TweetMessage", :body => tweet_url}, &callback)
118
+ def tweet(tweet_url, &callback)
119
+ speak({:type => "TweetMessage", :body => tweet_url}, &callback)
120
+ end
119
121
  end
120
122
  end
@@ -1,6 +1,7 @@
1
- class Firering::Upload < Firering::Data
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
@@ -1,18 +1,20 @@
1
- class Firering::User < Firering::Data
1
+ module Firering
2
+ User = Struct.new(:connection, :id, :name, :email_address, :admin, :created_at, :type, :api_auth_token)
2
3
 
3
- data_attributes :id, :name, :email_address, :admin, :created_at, :type,
4
- :api_auth_token
4
+ class User
5
+ extend Instantiator
5
6
 
6
- alias_method :token, :api_auth_token
7
- alias_method :admin?, :admin
7
+ alias_method :token, :api_auth_token
8
+ alias_method :admin?, :admin
8
9
 
9
- def member?
10
- type == "Member"
11
- end
10
+ def member?
11
+ type == "Member"
12
+ end
12
13
 
13
- def gest?
14
- type == "Guest"
15
- end
14
+ def gest?
15
+ type == "Guest"
16
+ end
16
17
 
17
- alias_method :to_s, :name
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.3'
8
+ VERSION = '1.0.4'
9
9
 
10
- class Error < StandardError; end
10
+ Error = Class.new(StandardError)
11
11
 
12
- autoload :Requests , "firering/requests"
13
- autoload :Connection , "firering/connection"
12
+ autoload :Requests , "firering/requests"
13
+ autoload :Connection , "firering/connection"
14
14
 
15
- autoload :Data , "firering/data"
16
- autoload :User , "firering/data/user"
17
- autoload :Message , "firering/data/message"
18
- autoload :Room , "firering/data/room"
19
- autoload :Upload , "firering/data/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 == Date.parse("2010/05/29 22:05:00 +0000")
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 == Date.parse("2009/06/02 21:20:32 +0000")
42
- message.body.should == "q: should i add :case_sensitive =\u003E false to the validation of title name? Looks harmless but who knows..."
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 == Date.parse("2010/05/29 21:38:02 +0000")
11
- room.updated_at.should == Date.parse("2010/05/29 21:38:02 +0000")
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 == Date.parse("2010/05/29 22:41:34 +0000")
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 == Date.parse("2010/05/29 22:41:34 +0000")
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 == Date.parse("2009/01/27 19:54:36 +0000")
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
@@ -1,12 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
- class TestData < Firering::Data
4
- data_attributes :a, :b
3
+ TestData = Struct.new(:connection, :a, :b)
4
+
5
+ class TestData
6
+ extend Firering::Instantiator
5
7
  end
6
8
 
7
- describe Firering::Data do
9
+ describe Firering::Instantiator do
8
10
 
9
- it "initializes an object from a hash with a base key, and defines accessors" do
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 'spec'
6
- require 'spec/autorun'
5
+ require 'rspec'
6
+ require 'rspec/autorun'
7
7
  require 'fixtures/load_server'
8
8
  require 'support/helpers'
9
- require 'ap'
10
9
 
11
- Spec::Runner.configure do |config|
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: 17
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 3
10
- version: 1.0.3
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: 2010-10-12 00:00:00 -03:00
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: 3
45
+ hash: 19
46
46
  segments:
47
47
  - 0
48
- - 2
49
- - 10
50
- version: 0.2.10
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: 27
77
+ hash: 11
78
78
  segments:
79
+ - 2
79
80
  - 1
80
- - 3
81
81
  - 0
82
- version: 1.3.0
82
+ version: 2.1.0
83
83
  type: :development
84
84
  version_requirements: *id004
85
85
  - !ruby/object:Gem::Dependency
86
- name: sinatra
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: 23
93
+ hash: 31
94
94
  segments:
95
95
  - 1
96
+ - 2
96
97
  - 0
97
- - 0
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