tinder 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ 1.4.1 - 2010-10-09
2
+ * Make SSL the default since it is available for all Campfire accounts.
3
+ * Added MIT License
4
+
1
5
  1.4 - 2010-05-11
2
6
  * Remove methods no longer supported by API
3
7
  Campfire#available_transcripts, Room#ping, Room#destroy, Room#toggle_guest_access
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2006-2010 Brandon Keepers, Collective Idea
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOa AND
17
+ NONINFRINGEMENT. IN NO EVENT SaALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -44,7 +44,7 @@ end
44
44
  task :spec => :check_dependencies
45
45
 
46
46
  task :default do
47
- %w(2.3.5 3.0.0.beta3).each do |version|
47
+ %w(2.3.5 2.3.9 3.0.0).each do |version|
48
48
  puts "Running specs with Rails #{version}"
49
49
  system("RAILS_VERSION=#{version} rake -s spec;")
50
50
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.0
1
+ 1.4.1
@@ -23,7 +23,7 @@ module Tinder
23
23
 
24
24
  def initialize(subdomain, options = {})
25
25
  @subdomain = subdomain
26
- @options = { :ssl => false, :proxy => ENV['HTTP_PROXY'] }.merge(options)
26
+ @options = { :ssl => true, :proxy => ENV['HTTP_PROXY'] }.merge(options)
27
27
  @uri = URI.parse("#{@options[:ssl] ? 'https' : 'http' }://#{subdomain}.#{HOST}")
28
28
  @token = options[:token]
29
29
 
@@ -18,6 +18,7 @@ module Tinder
18
18
  # Leave a room
19
19
  def leave
20
20
  post 'leave'
21
+ stop_listening
21
22
  end
22
23
 
23
24
  # Get the url for guest access
@@ -46,7 +47,7 @@ module Tinder
46
47
  def topic=(topic)
47
48
  update :topic => topic
48
49
  end
49
-
50
+
50
51
  def update(attrs)
51
52
  connection.put("/room/#{@id}.json", :body => {:room => attrs}.to_json)
52
53
  end
@@ -94,11 +95,11 @@ module Tinder
94
95
  user_data = connection.get("/users/#{id}.json")
95
96
  user = user_data && user_data[:user]
96
97
  end
97
- user[:created_at] = Time.parse(user[:created_at])
98
+ user[:created_at] = Time.parse(user[:created_at])
98
99
  user
99
100
  end
100
101
  end
101
-
102
+
102
103
  # Listen for new messages in the room, yielding them to the provided block as they arrive.
103
104
  # Each message is a hash with:
104
105
  # * +:body+: the body of the message
@@ -118,12 +119,12 @@ module Tinder
118
119
  # room.speak "Go away!" if m[:body] =~ /Java/i
119
120
  # end
120
121
  def listen(options = {})
121
- raise "no block provided" unless block_given?
122
+ raise ArgumentError, "no block provided" unless block_given?
122
123
 
123
124
  join # you have to be in the room to listen
124
125
 
125
126
  require 'twitter/json_stream'
126
-
127
+
127
128
  auth = connection.default_options[:basic_auth]
128
129
  options = {
129
130
  :host => "streaming.#{Connection::HOST}",
@@ -133,18 +134,29 @@ module Tinder
133
134
  :ssl => connection.options[:ssl]
134
135
  }.merge(options)
135
136
  EventMachine::run do
136
- stream = Twitter::JSONStream.connect(options)
137
- stream.each_item do |message|
137
+ @stream = Twitter::JSONStream.connect(options)
138
+ @stream.each_item do |message|
138
139
  message = HashWithIndifferentAccess.new(JSON.parse(message))
139
140
  message[:user] = user(message.delete(:user_id))
140
141
  message[:created_at] = Time.parse(message[:created_at])
141
142
  yield(message)
142
143
  end
143
- # if we really get disconnected
144
+ # if we really get disconnected
144
145
  raise ListenFailed.new("got disconnected from #{@name}!") if !EventMachine.reactor_running?
145
146
  end
146
147
  end
147
148
 
149
+ def listening?
150
+ @stream != nil
151
+ end
152
+
153
+ def stop_listening
154
+ return unless listening?
155
+
156
+ @stream.stop
157
+ @stream = nil
158
+ end
159
+
148
160
  # Get the transcript for the given date (Returns a hash in the same format as #listen)
149
161
  #
150
162
  # room.transcript(room.available_transcripts.first)
@@ -7,7 +7,7 @@ describe Tinder::Campfire do
7
7
 
8
8
  describe "rooms" do
9
9
  before do
10
- FakeWeb.register_uri(:get, "http://mytoken:X@test.campfirenow.com/rooms.json",
10
+ FakeWeb.register_uri(:get, "https://mytoken:X@test.campfirenow.com/rooms.json",
11
11
  :body => fixture('rooms.json'), :content_type => "application/json")
12
12
  end
13
13
 
@@ -25,10 +25,10 @@ describe Tinder::Campfire do
25
25
 
26
26
  describe "users" do
27
27
  before do
28
- FakeWeb.register_uri(:get, "http://mytoken:X@test.campfirenow.com/rooms.json",
28
+ FakeWeb.register_uri(:get, "https://mytoken:X@test.campfirenow.com/rooms.json",
29
29
  :body => fixture('rooms.json'), :content_type => "application/json")
30
30
  [80749, 80751].each do |id|
31
- FakeWeb.register_uri(:get, "http://mytoken:X@test.campfirenow.com/room/#{id}.json",
31
+ FakeWeb.register_uri(:get, "https://mytoken:X@test.campfirenow.com/room/#{id}.json",
32
32
  :body => fixture("rooms/room#{id}.json"), :content_type => "application/json")
33
33
  end
34
34
  end
@@ -42,7 +42,7 @@ describe Tinder::Campfire do
42
42
 
43
43
  describe "me" do
44
44
  before do
45
- FakeWeb.register_uri(:get, "http://mytoken:X@test.campfirenow.com/users/me.json",
45
+ FakeWeb.register_uri(:get, "https://mytoken:X@test.campfirenow.com/users/me.json",
46
46
  :body => fixture('users/me.json'), :content_type => "application/json")
47
47
  end
48
48
 
@@ -3,14 +3,14 @@ require 'spec_helper'
3
3
  describe Tinder::Connection do
4
4
  describe "authentication" do
5
5
  it "should raise an exception with bad credentials" do
6
- FakeWeb.register_uri(:get, "http://foo:X@test.campfirenow.com/rooms.json",
6
+ FakeWeb.register_uri(:get, "https://foo:X@test.campfirenow.com/rooms.json",
7
7
  :status => ["401", "Unauthorized"])
8
8
  connection = Tinder::Connection.new('test', :token => 'foo')
9
9
  lambda { connection.get('/rooms.json') }.should raise_error(Tinder::AuthenticationFailed)
10
10
  end
11
11
 
12
12
  it "should lookup token when username/password provided" do
13
- FakeWeb.register_uri(:get, "http://user:pass@test.campfirenow.com/users/me.json",
13
+ FakeWeb.register_uri(:get, "https://user:pass@test.campfirenow.com/users/me.json",
14
14
  :body => fixture('users/me.json'), :content_type => "application/json")
15
15
  connection = Tinder::Connection.new('test', :username => 'user', :password => 'pass')
16
16
  connection.token.should.should == "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
@@ -18,7 +18,7 @@ describe Tinder::Connection do
18
18
 
19
19
 
20
20
  it "should use basic auth for credentials" do
21
- FakeWeb.register_uri(:get, "http://mytoken:X@test.campfirenow.com/rooms.json",
21
+ FakeWeb.register_uri(:get, "https://mytoken:X@test.campfirenow.com/rooms.json",
22
22
  :body => fixture('rooms.json'), :content_type => "application/json")
23
23
  connection = Tinder::Connection.new('test', :token => 'mytoken')
24
24
  lambda { connection.get('/rooms.json') }.should_not raise_error
@@ -2,14 +2,21 @@ require 'spec_helper'
2
2
 
3
3
  describe Tinder::Room do
4
4
  before do
5
- FakeWeb.register_uri(:get, "http://mytoken:X@test.campfirenow.com/room/80749.json",
5
+ FakeWeb.register_uri(:get, "https://mytoken:X@test.campfirenow.com/room/80749.json",
6
6
  :body => fixture('rooms/show.json'), :content_type => "application/json")
7
7
  @room = Tinder::Room.new(Tinder::Connection.new('test', :token => 'mytoken'), 'id' => 80749)
8
+
9
+ # Get EventMachine out of the way. We could be using em-spec, but seems like overkill
10
+ require 'twitter/json_stream'
11
+ module EventMachine; def self.run; yield end end
12
+ EventMachine.stub!(:reactor_running?).and_return(true)
13
+ @stream = mock(Twitter::JSONStream)
14
+ @stream.stub!(:each_item)
8
15
  end
9
-
16
+
10
17
  describe "join" do
11
- FakeWeb.register_uri(:post, "http://mytoken:X@test.campfirenow.com/room/80749/join.json", :status => '200')
12
-
18
+ FakeWeb.register_uri(:post, "https://mytoken:X@test.campfirenow.com/room/80749/join.json", :status => '200')
19
+
13
20
  it "should post to join url" do
14
21
  @room.join
15
22
  end
@@ -17,83 +24,112 @@ describe Tinder::Room do
17
24
 
18
25
  describe "leave" do
19
26
  before do
20
- FakeWeb.register_uri(:post, "http://mytoken:X@test.campfirenow.com/room/80749/leave.json", :status => '200')
27
+ FakeWeb.register_uri(:post, "https://mytoken:X@test.campfirenow.com/room/80749/leave.json", :status => '200')
21
28
  end
22
-
29
+
23
30
  it "should post to leave url" do
24
31
  @room.leave
25
32
  end
33
+
34
+ it "stops listening" do
35
+ @room.should_receive(:stop_listening)
36
+ @room.leave
37
+ end
26
38
  end
27
-
39
+
28
40
  describe "lock" do
29
41
  before do
30
- FakeWeb.register_uri(:post, "http://mytoken:X@test.campfirenow.com/room/80749/lock.json", :status => '200')
42
+ FakeWeb.register_uri(:post, "https://mytoken:X@test.campfirenow.com/room/80749/lock.json", :status => '200')
31
43
  end
32
-
44
+
33
45
  it "should post to lock url" do
34
46
  @room.lock
35
47
  end
36
48
  end
37
-
49
+
38
50
  describe "unlock" do
39
51
  before do
40
- FakeWeb.register_uri(:post, "http://mytoken:X@test.campfirenow.com/room/80749/unlock.json", :status => '200')
52
+ FakeWeb.register_uri(:post, "https://mytoken:X@test.campfirenow.com/room/80749/unlock.json", :status => '200')
41
53
  end
42
-
54
+
43
55
  it "should post to unlock url" do
44
56
  @room.unlock
45
57
  end
46
58
  end
47
-
59
+
48
60
  describe "guest_url" do
49
61
  it "should use guest_invite_code if active" do
50
62
  @room.stub!(:guest_access_enabled? => true, :guest_invite_code => '123')
51
- @room.guest_url.should == "http://test.campfirenow.com/123"
63
+ @room.guest_url.should == "https://test.campfirenow.com/123"
52
64
  end
53
-
65
+
54
66
  it "should return nil when guest access is not enabled" do
55
67
  @room.stub!(:guest_access_enabled?).and_return(false)
56
68
  @room.guest_url.should be_nil
57
69
  end
58
70
  end
59
-
71
+
60
72
  it "should set guest_invite_code" do
61
73
  @room.guest_invite_code.should == "90cf7"
62
74
  end
63
-
75
+
64
76
  it "should set guest_access_enabled?" do
65
77
  @room.guest_access_enabled?.should be_true
66
78
  end
67
-
79
+
68
80
  describe "name=" do
69
81
  it "should put to update the room" do
70
- FakeWeb.register_uri(:put, "http://mytoken:X@test.campfirenow.com/room/80749.json",
82
+ FakeWeb.register_uri(:put, "https://mytoken:X@test.campfirenow.com/room/80749.json",
71
83
  :status => '200')
72
84
  @room.name = "Foo"
73
85
  end
74
86
  end
75
-
87
+
76
88
  describe "listen" do
77
- before do
78
- require 'twitter/json_stream'
79
- # Get EventMachine out of the way. We could be using em-spec, but seems like overkill for testing one method.
80
- module EventMachine; def self.run; yield end end
81
- EventMachine.stub!(:reactor_running?).and_return(true)
82
- @stream = mock(Twitter::JSONStream)
83
- @stream.stub!(:each_item)
84
- end
85
-
86
89
  it "should get from the streaming url" do
87
90
  Twitter::JSONStream.should_receive(:connect).
88
- with({:host=>"streaming.campfirenow.com", :path=>"/room/80749/live.json", :auth=>"mytoken:X", :timeout=>6, :ssl=>false}).
91
+ with({:host=>"streaming.campfirenow.com", :path=>"/room/80749/live.json", :auth=>"mytoken:X", :timeout=>6, :ssl=>true}).
89
92
  and_return(@stream)
90
93
  @room.listen { }
91
94
  end
92
-
95
+
93
96
  it "should raise an exception if no block is given" do
94
97
  lambda {
95
98
  @room.listen
96
- }.should raise_error("no block provided")
99
+ }.should raise_error(ArgumentError, "no block provided")
100
+ end
101
+
102
+ it "marks the room as listening" do
103
+ Twitter::JSONStream.stub!(:connect).and_return(@stream)
104
+ lambda {
105
+ @room.listen { }
106
+ }.should change(@room, :listening?).from(false).to(true)
107
+ end
108
+ end
109
+
110
+ describe "stop_listening" do
111
+ before do
112
+ Twitter::JSONStream.stub!(:connect).and_return(@stream)
113
+ @stream.stub!(:stop)
114
+ end
115
+
116
+ it "changes a listening room to a non-listening room" do
117
+ @room.listen { }
118
+ lambda {
119
+ @room.stop_listening
120
+ }.should change(@room, :listening?).from(true).to(false)
121
+ end
122
+
123
+ it "tells the json stream to stop" do
124
+ @room.listen { }
125
+ @stream.should_receive(:stop)
126
+ @room.stop_listening
127
+ end
128
+
129
+ it "does nothing if the room is not listening" do
130
+ @room.listen { }
131
+ @room.stop_listening
132
+ @room.stop_listening
97
133
  end
98
134
  end
99
135
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tinder}
8
- s.version = "1.4.0"
8
+ s.version = "1.4.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brandon Keepers"]
12
- s.date = %q{2010-05-11}
12
+ s.date = %q{2010-10-09}
13
13
  s.description = %q{A Ruby API for interfacing with Campfire, the 37Signals chat application.}
14
14
  s.email = %q{brandon@opensoul.org}
15
15
  s.extra_rdoc_files = [
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.files = [
19
19
  ".gitignore",
20
20
  "CHANGELOG.txt",
21
+ "MIT-LICENSE",
21
22
  "README.markdown",
22
23
  "Rakefile",
23
24
  "VERSION",
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 4
8
- - 0
9
- version: 1.4.0
8
+ - 1
9
+ version: 1.4.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Brandon Keepers
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-11 00:00:00 -04:00
17
+ date: 2010-10-09 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -112,6 +112,7 @@ extra_rdoc_files:
112
112
  files:
113
113
  - .gitignore
114
114
  - CHANGELOG.txt
115
+ - MIT-LICENSE
115
116
  - README.markdown
116
117
  - Rakefile
117
118
  - VERSION