tinder 0.1.0 → 0.1.1

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.1 - 2007-01-27
2
+ * fix bug preventing speak from working
3
+ * incorporated "watching" from http://soylentfoo.jnewland.com/articles/2006/12/07/updates-to-marshmallow-the-campfire-bot
4
+
1
5
  0.1.0 - 2007-01-23
2
6
  * Initial release as gem
3
7
  * Get the users in a room [Tero Parviainen]
@@ -9,3 +9,4 @@ lib/tinder/room.rb
9
9
  lib/tinder/version.rb
10
10
  test/remote/remote_campfire_test.rb
11
11
  test/test_helper.rb
12
+ test/unit/campfire_test.rb
@@ -92,12 +92,14 @@ module Tinder
92
92
  end
93
93
 
94
94
  def verify_response(response, options = {})
95
- if options.is_a? Symbol
96
- response.code == case options
97
- when :success then "200"
98
- end
95
+ if options.is_a?(Symbol)
96
+ case options
97
+ when :success then [200]
98
+ when :redirect then 300..399
99
+ else raise ArgumentError.new("Unknown response #{options}")
100
+ end.include?(response.code.to_i)
99
101
  elsif options[:redirect_to]
100
- response.code == "302" && response['location'] == options[:redirect_to]
102
+ verify_response(response, :redirect) && response['location'] == options[:redirect_to]
101
103
  else
102
104
  false
103
105
  end
@@ -6,6 +6,15 @@ module Tinder
6
6
  @campfire = campfire
7
7
  self.id = id
8
8
  self.name = name
9
+ @room = get("room/#{self.id}")
10
+ @membership_key = @room.body.scan(/\"membershipKey\": \"([a-z0-9]+)\"/).to_s
11
+ @user_id = @room.body.scan(/\"userID\": (\d+)/).to_s
12
+ @last_cache_id = @room.body.scan(/\"lastCacheID\": (\d+)/).to_s
13
+ @timestamp = @room.body.scan(/\"timestamp\": (\d+)/).to_s
14
+ end
15
+
16
+ def leave
17
+ verify_response get("/room/#{@room_id}/leave"), :redirect
9
18
  end
10
19
 
11
20
  def toggle_guest_access
@@ -13,7 +22,7 @@ module Tinder
13
22
  end
14
23
 
15
24
  def guest_url
16
- (Hpricot(@campfire.send(:get, "room/#{self.id}").body)/"#guest_access h4").first.inner_html
25
+ (Hpricot(get("room/#{self.id}").body)/"#guest_access h4").first.inner_html
17
26
  end
18
27
 
19
28
  def guest_invite_code
@@ -51,6 +60,40 @@ module Tinder
51
60
  def users
52
61
  @campfire.users self.name
53
62
  end
63
+
64
+ def listen
65
+ continue = true
66
+ while(continue)
67
+ messages = []
68
+ response = post("poll.fcgi", :l => @last_cache_id, :m => @membership_key, :s => @timestamp, :t => "#{Time.now.to_i}000")
69
+ if response.body.length > 1
70
+ lines = response.body.split("\r\n")
71
+ if lines.length > 0
72
+ @last_cache_id = lines.pop.scan(/chat.poller.lastCacheID = (\d+)/).to_s
73
+ lines.each do |msg|
74
+ unless msg.match(/timestamp_message/)
75
+ messages << {
76
+ :id => msg.scan(/message_(\d+)/).to_s,
77
+ :user_id => msg.scan(/user_(\d+)/).to_s,
78
+ :person => msg.scan(/<span>(.+)<\/span>/).to_s,
79
+ :message => msg.scan(/<div>(.+)<\/div>/).to_s
80
+ }
81
+ end
82
+ end
83
+ end
84
+ end
85
+ if block_given?
86
+ messages.each do |msg|
87
+ yield msg
88
+ end
89
+ sleep 5
90
+ else
91
+ continue = false
92
+ messages
93
+ end
94
+ end
95
+ end
96
+
54
97
 
55
98
  private
56
99
 
@@ -67,7 +110,7 @@ module Tinder
67
110
  end
68
111
 
69
112
  def send(message, options = {})
70
- message if verify_response(post("room/#{self.id}/speak", { :message => message, }.merge(options), :ajax => true), :success)
113
+ message if verify_response(post("room/#{self.id}/speak", { :message => message, :t => Time.now.to_i }.merge(options), :ajax => true), :success)
71
114
  end
72
115
 
73
116
  end
@@ -2,7 +2,7 @@ module Tinder #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -1,4 +1,6 @@
1
1
  require 'test/unit'
2
2
  require 'rubygems'
3
3
  require 'active_support'
4
- require File.dirname(__FILE__) + '/../lib/tinder.rb'
4
+ require File.dirname(__FILE__) + '/../lib/tinder.rb'
5
+ require 'mocha'
6
+ require 'stubba'
@@ -0,0 +1,43 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class CampfireTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @campfire = Tinder::Campfire.new("foobar")
7
+ @response = mock("response")
8
+ end
9
+
10
+ def test_verify_response_redirect_true
11
+ @response.expects(:code).returns(302)
12
+ assert true === @campfire.send(:verify_response, @response, :redirect)
13
+ end
14
+
15
+ def test_verify_response_redirect_false
16
+ @response.expects(:code).returns(200)
17
+ assert false === @campfire.send(:verify_response, @response, :redirect)
18
+ end
19
+
20
+ def test_verify_response_success
21
+ @response.expects(:code).returns(200)
22
+ assert true === @campfire.send(:verify_response, @response, :success)
23
+ end
24
+
25
+ def test_verify_response_redirect_to
26
+ @response.expects(:code).returns(304)
27
+ @response.expects(:[]).with('location').returns("/foobar")
28
+ assert true === @campfire.send(:verify_response, @response, :redirect_to => '/foobar')
29
+ end
30
+
31
+ def test_verify_response_redirect_to_without_redirect
32
+ @response.expects(:code).returns(200)
33
+ assert false === @campfire.send(:verify_response, @response, :redirect_to => '/foobar')
34
+ end
35
+
36
+ def test_verify_response_redirect_to_wrong_path
37
+ @response.expects(:code).returns(302)
38
+ @response.expects(:[]).with('location').returns("/baz")
39
+ assert false === @campfire.send(:verify_response, @response, :redirect_to => '/foobar')
40
+ end
41
+
42
+
43
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: tinder
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
7
- date: 2007-01-23 00:00:00 -05:00
6
+ version: 0.1.1
7
+ date: 2007-01-27 00:00:00 -05:00
8
8
  summary: An (unofficial) Campfire API
9
9
  require_paths:
10
10
  - lib
@@ -39,8 +39,10 @@ files:
39
39
  - lib/tinder/version.rb
40
40
  - test/remote/remote_campfire_test.rb
41
41
  - test/test_helper.rb
42
+ - test/unit/campfire_test.rb
42
43
  test_files:
43
44
  - test/remote/remote_campfire_test.rb
45
+ - test/unit/campfire_test.rb
44
46
  rdoc_options: []
45
47
 
46
48
  extra_rdoc_files: []