tinder 0.1.4 → 0.1.5

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.
@@ -1,3 +1,7 @@
1
+ 0.1.5 - 2008-01-25
2
+ * Fixed Room#listen, which was broken by latest Campfire deploy
3
+ * Fixed timeout when listening but not speaking that will eventually log you out [Clinton R. Nixon]
4
+
1
5
  0.1.4 - 2007-07-23
2
6
  * Support for transcripts
3
7
  * Fixed Room#leave, which was broken by a Campfire deployment [Andy Smith]
@@ -6,7 +6,6 @@ require 'net/https'
6
6
  require 'open-uri'
7
7
  require 'hpricot'
8
8
 
9
-
10
9
  Dir[File.join(File.dirname(__FILE__), 'tinder/**/*.rb')].sort.each { |lib| require lib }
11
10
 
12
11
  module Tinder
@@ -19,6 +19,7 @@ module Tinder
19
19
  @cookie = nil
20
20
  @subdomain = subdomain
21
21
  @uri = URI.parse("#{options[:ssl] ? 'https' : 'http' }://#{subdomain}.campfirenow.com")
22
+ @logged_in = false
22
23
  end
23
24
 
24
25
  # Log in to campfire using your +email+ and +password+
@@ -129,7 +130,7 @@ module Tinder
129
130
  request.add_field 'Cookie', @cookie if @cookie
130
131
  if options[:ajax]
131
132
  request.add_field 'X-Requested-With', 'XMLHttpRequest'
132
- request.add_field 'X-Prototype-Version', '1.5.0_rc1'
133
+ request.add_field 'X-Prototype-Version', '1.5.1.1'
133
134
  end
134
135
  end
135
136
  end
@@ -171,4 +172,4 @@ module Tinder
171
172
  end
172
173
 
173
174
  end
174
- end
175
+ end
@@ -17,14 +17,16 @@ module Tinder
17
17
  @user_id = room.body.scan(/\"userID\": (\d+)/).to_s
18
18
  @last_cache_id = room.body.scan(/\"lastCacheID\": (\d+)/).to_s
19
19
  @timestamp = room.body.scan(/\"timestamp\": (\d+)/).to_s
20
+ @idle_since = Time.now
20
21
  end if @room.nil? || force
22
+ ping
21
23
  true
22
24
  end
23
25
 
24
26
  # Leave a room
25
27
  def leave
26
28
  returning verify_response(post("room/#{id}/leave"), :redirect) do
27
- @room, @membership_key, @user_id, @last_cache_id, @timestamp = nil
29
+ @room, @membership_key, @user_id, @last_cache_id, @timestamp, @idle_since = nil
28
30
  end
29
31
  end
30
32
 
@@ -42,11 +44,13 @@ module Tinder
42
44
  end
43
45
 
44
46
  def guest_access_enabled?
47
+ join
45
48
  !guest_url.nil?
46
49
  end
47
50
 
48
51
  # The invite code use for guest
49
52
  def guest_invite_code
53
+ join
50
54
  guest_url.scan(/\/(\w*)$/).to_s
51
55
  end
52
56
 
@@ -71,19 +75,26 @@ module Tinder
71
75
  verify_response(post("room/#{id}/unlock", {}, :ajax => true), :success)
72
76
  end
73
77
 
78
+ def ping(force = false)
79
+ returning verify_response(post("room/#{id}/tabs", { }, :ajax => true), :success) do
80
+ @idle_since = Time.now
81
+ end if @idle_since < 1.minute.ago || force
82
+ end
83
+
74
84
  def destroy
75
85
  verify_response(post("account/delete/room/#{id}"), :success)
76
86
  end
77
87
 
78
88
  # Post a new message to the chat room
79
- def speak(message)
89
+ def speak(message, options = {})
80
90
  join
81
- send message
91
+ message if verify_response(post("room/#{id}/speak", {:message => message,
92
+ :t => Time.now.to_i}.merge(options), :ajax => true), :success)
82
93
  end
83
-
94
+
84
95
  def paste(message)
85
96
  join
86
- send message, { :paste => true }
97
+ speak message, :paste => true
87
98
  end
88
99
 
89
100
  # Get the list of users currently chatting for this room
@@ -91,7 +102,7 @@ module Tinder
91
102
  @campfire.users name
92
103
  end
93
104
 
94
- # Get and array of the messages that have been posted to the room since you joined. Each
105
+ # Get and array of the messages that have been posted to the room. Each
95
106
  # messages is a hash with:
96
107
  # * +:person+: the display name of the person that posted the message
97
108
  # * +:message+: the body of the message
@@ -101,46 +112,25 @@ module Tinder
101
112
  # room.listen
102
113
  # #=> [{:person=>"Brandon", :message=>"I'm getting very sleepy", :user_id=>"148583", :id=>"16434003"}]
103
114
  #
104
- # listen also takes an optional block, which then polls for new messages every 5 seconds
105
- # and calls the block for each message.
115
+ # Called without a block, listen will return an array of messages that have been
116
+ # posted since you joined. listen also takes an optional block, which then polls
117
+ # for new messages every 5 seconds and calls the block for each message.
106
118
  #
107
119
  # room.listen do |m|
108
120
  # room.speak "#{m[:person]}, Go away!" if m[:message] =~ /Java/i
109
121
  # end
110
122
  #
111
- def listen
112
- # FIXME: this method needs refactored!
123
+ def listen(interval = 5)
113
124
  join
114
- continue = true
115
- while(continue)
116
- messages = []
117
- response = post("poll.fcgi", :l => @last_cache_id, :m => @membership_key, :s => @timestamp, :t => "#{Time.now.to_i}000")
118
- if response.body.length > 1
119
- lines = response.body.split("\r\n")
120
- if lines.length > 0
121
- @last_cache_id = lines.pop.scan(/chat.poller.lastCacheID = (\d+)/).to_s
122
- lines.each do |msg|
123
- unless msg.match(/timestamp_message/)
124
- messages << {
125
- :id => msg.scan(/message_(\d+)/).to_s,
126
- :user_id => msg.scan(/user_(\d+)/).to_s,
127
- :person => msg.scan(/<span>(.+)<\/span>/).to_s,
128
- :message => msg.scan(/<div>(.+)<\/div>/).to_s
129
- }
130
- end
131
- end
132
- end
133
- end
134
- if block_given?
135
- messages.each do |msg|
136
- yield msg
137
- end
138
- sleep 5
139
- else
140
- continue = false
125
+ if block_given?
126
+ loop do
127
+ ping
128
+ self.messages.each {|msg| yield msg }
129
+ sleep interval
141
130
  end
131
+ else
132
+ self.messages
142
133
  end
143
- messages
144
134
  end
145
135
 
146
136
  # Get the dates for the available transcripts for this room
@@ -165,8 +155,39 @@ module Tinder
165
155
  end
166
156
  end
167
157
 
168
- private
158
+ protected
159
+
160
+ def messages
161
+ returning [] do |messages|
162
+ response = post("poll.fcgi", {:l => @last_cache_id, :m => @membership_key,
163
+ :s => @timestamp, :t => "#{Time.now.to_i}000"}, :ajax => true)
164
+ if response.body.length > 1
165
+ # deal with "chat.redirectTo('/');" - relogin
166
+ join(true) && self.messages if response.body.match('chat\.redirectTo')
169
167
 
168
+ lines = response.body.split("\r\n")
169
+
170
+ if lines.length > 0
171
+ @last_cache_id = lines.pop.scan(/chat.poller.lastCacheID = (\d+)/).to_s
172
+ lines.each do |msg|
173
+ unless msg.match(/timestamp_message/)
174
+ # pull out only the chat.transcript.queueMessage part for now
175
+ msg = msg.scan(/(chat\.transcript\.queueMessage(?:.+?);)/).to_s
176
+ if msg.length > 0
177
+ messages << {
178
+ :id => msg.scan(/message_(\d+)/).to_s,
179
+ :user_id => msg.scan(/user_(\d+)/).to_s,
180
+ :person => msg.scan(/\\u003Ctd class=\\"person\\"\\u003E(?:\\u003Cspan\\u003E)?(.+?)(?:\\u003C\/span\\u003E)?\\u003C\/td\\u003E/).to_s,
181
+ :message => msg.scan(/\\u003Ctd class=\\"body\\"\\u003E\\u003Cdiv\\u003E(.+?)\\u003C\/div\\u003E\\u003C\/td\\u003E/).to_s
182
+ }
183
+ end
184
+ end
185
+ end
186
+ end
187
+ end
188
+ end
189
+ end
190
+
170
191
  def post(*args)
171
192
  @campfire.send :post, *args
172
193
  end
@@ -179,9 +200,5 @@ module Tinder
179
200
  @campfire.send :verify_response, *args
180
201
  end
181
202
 
182
- def send(message, options = {})
183
- message if verify_response(post("room/#{id}/speak", { :message => message, :t => Time.now.to_i }.merge(options), :ajax => true), :success)
184
- end
185
-
186
203
  end
187
- end
204
+ end
@@ -2,7 +2,7 @@ module Tinder #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 4
5
+ TINY = 5
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -4,7 +4,7 @@ class RemoteCampfireTest < Test::Unit::TestCase
4
4
 
5
5
  def setup
6
6
  @campfire = Tinder::Campfire.new 'domain'
7
- #@user, @pass = 'email@example.com', 'password'
7
+ # @user, @pass = 'email@example.com', 'password'
8
8
  raise "Set your campfire credentials before running the remote tests" unless @user && @pass
9
9
  end
10
10
 
@@ -29,7 +29,7 @@ class RemoteCampfireTest < Test::Unit::TestCase
29
29
  end
30
30
 
31
31
  def test_failed_login
32
- assert !@campfire.login(@user, 'notmypassword')
32
+ assert_raises(Tinder::Error) { @campfire.login(@user, 'notmypassword') }
33
33
  assert !@campfire.logged_in?
34
34
  end
35
35
 
metadata CHANGED
@@ -1,84 +1,90 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
3
- specification_version: 1
4
2
  name: tinder
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.1.4
7
- date: 2007-07-23 00:00:00 +03:00
8
- summary: An (unofficial) Campfire API
9
- require_paths:
10
- - lib
11
- email: brandon@opensoul.org
12
- homepage: http://tinder.rubyforge.org
13
- rubyforge_project: tinder
14
- description: An API for interfacing with Campfire, the 37Signals chat application.
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.1.5
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Brandon Keepers
31
- files:
32
- - CHANGELOG.txt
33
- - Manifest.txt
34
- - README.txt
35
- - Rakefile
36
- - init.rb
37
- - lib/tinder.rb
38
- - lib/tinder/campfire.rb
39
- - lib/tinder/room.rb
40
- - lib/tinder/version.rb
41
- test_files:
42
- - test/remote/remote_campfire_test.rb
43
- - test/unit/room_test.rb
44
- rdoc_options:
45
- - --main
46
- - README.txt
47
- extra_rdoc_files:
48
- - CHANGELOG.txt
49
- - Manifest.txt
50
- - README.txt
51
- executables: []
52
-
53
- extensions: []
54
-
55
- requirements: []
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
56
11
 
12
+ date: 2008-01-25 00:00:00 -05:00
13
+ default_executable:
57
14
  dependencies:
58
15
  - !ruby/object:Gem::Dependency
59
16
  name: activesupport
60
17
  version_requirement:
61
- version_requirements: !ruby/object:Gem::Version::Requirement
18
+ version_requirements: !ruby/object:Gem::Requirement
62
19
  requirements:
63
- - - ">"
20
+ - - ">="
64
21
  - !ruby/object:Gem::Version
65
- version: 0.0.0
22
+ version: "0"
66
23
  version:
67
24
  - !ruby/object:Gem::Dependency
68
25
  name: hpricot
69
26
  version_requirement:
70
- version_requirements: !ruby/object:Gem::Version::Requirement
27
+ version_requirements: !ruby/object:Gem::Requirement
71
28
  requirements:
72
- - - ">"
29
+ - - ">="
73
30
  - !ruby/object:Gem::Version
74
- version: 0.0.0
31
+ version: "0"
75
32
  version:
76
33
  - !ruby/object:Gem::Dependency
77
34
  name: hoe
78
35
  version_requirement:
79
- version_requirements: !ruby/object:Gem::Version::Requirement
36
+ version_requirements: !ruby/object:Gem::Requirement
80
37
  requirements:
81
38
  - - ">="
82
39
  - !ruby/object:Gem::Version
83
- version: 1.2.1
40
+ version: 1.4.0
84
41
  version:
42
+ description: An API for interfacing with Campfire, the 37Signals chat application.
43
+ email: brandon@opensoul.org
44
+ executables: []
45
+
46
+ extensions: []
47
+
48
+ extra_rdoc_files:
49
+ - CHANGELOG.txt
50
+ - Manifest.txt
51
+ - README.txt
52
+ files:
53
+ - CHANGELOG.txt
54
+ - Manifest.txt
55
+ - README.txt
56
+ - Rakefile
57
+ - init.rb
58
+ - lib/tinder.rb
59
+ - lib/tinder/campfire.rb
60
+ - lib/tinder/room.rb
61
+ - lib/tinder/version.rb
62
+ has_rdoc: true
63
+ homepage: http://tinder.rubyforge.org
64
+ post_install_message:
65
+ rdoc_options:
66
+ - --main
67
+ - README.txt
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ version:
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ version:
82
+ requirements: []
83
+
84
+ rubyforge_project: tinder
85
+ rubygems_version: 1.0.1
86
+ signing_key:
87
+ specification_version: 2
88
+ summary: An (unofficial) Campfire API
89
+ test_files:
90
+ - test/remote/remote_campfire_test.rb
@@ -1,30 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper'
2
-
3
- class RoomTest < Test::Unit::TestCase
4
-
5
- def setup
6
- @campfire = Tinder::Campfire.new("foobar")
7
- @room = Tinder::Room.new(@campfire, 1, "Room 1")
8
- end
9
-
10
- def test_toggle_guest_access_rejoins_room
11
- @response = mock("response")
12
- @response.expects(:code).returns("200")
13
- @campfire.expects(:post).with('room/1/toggle_guest_access').returns(@response)
14
- @campfire.expects(:get).with('room/1').returns(@response)
15
- @room.toggle_guest_access
16
- end
17
-
18
- def test_guest_access?
19
- mock_response :guest_access_enabled
20
- assert @room.guest_access_enabled?
21
- end
22
-
23
- private
24
-
25
- def mock_response(response)
26
- FakeWeb.register_uri('http://foobar.campfirenow.com/room/1',
27
- :file => "#{FIXTURE_DIR}/pages/room/#{response}.html")
28
- end
29
-
30
- end