tinder 1.3.1 → 1.10.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.
- checksums.yaml +7 -0
- data/.gemtest +0 -0
- data/.gitignore +6 -3
- data/.rspec +2 -0
- data/.travis.yml +11 -0
- data/CHANGELOG.txt +54 -0
- data/Gemfile +7 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +47 -0
- data/Rakefile +7 -63
- data/init.rb +1 -1
- data/lib/faraday/response/raise_on_authentication_failure.rb +10 -0
- data/lib/faraday/response/remove_whitespace.rb +10 -0
- data/lib/tinder/campfire.rb +28 -51
- data/lib/tinder/connection.rb +108 -9
- data/lib/tinder/room.rb +205 -97
- data/lib/tinder/version.rb +4 -0
- data/lib/tinder.rb +12 -8
- data/site/index.html +7 -7
- data/spec/fixtures/presence.json +26 -0
- data/spec/fixtures/rooms/recent.json +19 -0
- data/spec/fixtures/rooms/room80749.json +21 -0
- data/spec/fixtures/rooms/room80751.json +21 -0
- data/spec/fixtures/rooms/show.json +21 -0
- data/spec/fixtures/rooms.json +18 -0
- data/spec/fixtures/users/me.json +11 -0
- data/spec/spec_helper.rb +26 -2
- data/spec/tinder/campfire_spec.rb +112 -0
- data/spec/tinder/connection_spec.rb +104 -0
- data/spec/tinder/room_spec.rb +364 -0
- data/tinder.gemspec +26 -74
- metadata +206 -82
- data/Manifest.txt +0 -10
- data/README.txt +0 -54
- data/VERSION +0 -1
- data/lib/tinder/multipart.rb +0 -63
- data/spec/campfire_spec.rb +0 -225
- data/spec/html/full_lobby.html +0 -198
- data/spec/html/normal_lobby.html +0 -192
- data/spec/html/transcript.html +0 -133
- data/spec/spec.opts +0 -1
- data/test/remote/credentials.rb.example +0 -4
- data/test/remote/remote_campfire_test.rb +0 -59
- data/test/test_helper.rb +0 -2
@@ -0,0 +1,112 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Tinder::Campfire do
|
5
|
+
before do
|
6
|
+
@campfire = Tinder::Campfire.new('test', :token => 'mytoken')
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "rooms" do
|
10
|
+
before do
|
11
|
+
stub_connection(@campfire.connection) do |stub|
|
12
|
+
stub.get('/rooms.json') {[200, {}, fixture('rooms.json')]}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return rooms" do
|
17
|
+
expect(@campfire.rooms.size).to eq(2)
|
18
|
+
expect(@campfire.rooms.first).to be_kind_of(Tinder::Room)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should set the room name and id" do
|
22
|
+
room = @campfire.rooms.first
|
23
|
+
expect(room.name).to eq('Room 1')
|
24
|
+
expect(room.id).to eq(80749)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "presence" do
|
29
|
+
before do
|
30
|
+
stub_connection(@campfire.connection) do |stub|
|
31
|
+
stub.get('/presence.json') {[200, {}, fixture('presence.json')]}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return rooms" do
|
36
|
+
expect(@campfire.presence.size).to eq(3)
|
37
|
+
expect(@campfire.presence.first).to be_kind_of(Tinder::Room)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should set the room name and id" do
|
41
|
+
room = @campfire.presence.last
|
42
|
+
expect(room.name).to eq('Room 3')
|
43
|
+
expect(room.id).to eq(80754)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "find_room_by_id" do
|
48
|
+
before do
|
49
|
+
stub_connection(@campfire.connection) do |stub|
|
50
|
+
stub.get('/rooms.json') {[200, {}, fixture('rooms.json')]}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should return a Tinder::Room object when a match is found" do
|
55
|
+
room = @campfire.find_room_by_id 80749
|
56
|
+
expect(room).to be_kind_of(Tinder::Room)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should return nil when no match is found" do
|
60
|
+
room = @campfire.find_room_by_id 123
|
61
|
+
expect(room).to eq(nil)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "find_room_by_name" do
|
66
|
+
before do
|
67
|
+
stub_connection(@campfire.connection) do |stub|
|
68
|
+
stub.get('/rooms.json') {[200, {}, fixture('rooms.json')]}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should return a Tinder::Room object when a match is found" do
|
73
|
+
room = @campfire.find_room_by_name 'Room 1'
|
74
|
+
expect(room).to be_kind_of(Tinder::Room)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should return nil when no match is found" do
|
78
|
+
room = @campfire.find_room_by_name 'asdf'
|
79
|
+
expect(room).to eq(nil)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "users" do
|
84
|
+
before do
|
85
|
+
stub_connection(@campfire.connection) do |stub|
|
86
|
+
stub.get('/rooms.json') {[200, {}, fixture('rooms.json')]}
|
87
|
+
|
88
|
+
[80749, 80751].each do |id|
|
89
|
+
stub.get("/room/#{id}.json") {[200, {}, fixture("rooms/room#{id}.json")]}
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should return a sorted list of users in all rooms" do
|
95
|
+
expect(@campfire.users.length).to eq(2)
|
96
|
+
expect(@campfire.users.first[:name]).to eq("Jane Doe")
|
97
|
+
expect(@campfire.users.last[:name]).to eq("John Doe")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "me" do
|
102
|
+
before do
|
103
|
+
stub_connection(@campfire.connection) do |stub|
|
104
|
+
stub.get("/users/me.json") {[200, {}, fixture('users/me.json')]}
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should return the current user's information" do
|
109
|
+
expect(@campfire.me["name"]).to eq("John Doe")
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Tinder::Connection do
|
5
|
+
describe "authentication" do
|
6
|
+
it "should raise an exception with bad credentials" do
|
7
|
+
stub_connection(Tinder::Connection) do |stub|
|
8
|
+
stub.get("/rooms.json") {[401, {}, "Unauthorized"]}
|
9
|
+
end
|
10
|
+
|
11
|
+
connection = Tinder::Connection.new('test', :token => 'foo')
|
12
|
+
expect { connection.get('/rooms.json') }.to raise_error(Tinder::AuthenticationFailed)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should raise an exception when an invalid subdomain is specified" do
|
16
|
+
stub_connection(Tinder::Connection) do |stub|
|
17
|
+
stub.get("/rooms.json") {[404, {}, "Not found"]}
|
18
|
+
end
|
19
|
+
|
20
|
+
connection = Tinder::Connection.new('test', :token => 'foo')
|
21
|
+
expect { connection.get('/rooms.json') }.to raise_error(Tinder::AuthenticationFailed)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should lookup token when username/password provided" do
|
25
|
+
stub_connection(Tinder::Connection) do |stub|
|
26
|
+
stub.get("/users/me.json") {[200, {}, fixture('users/me.json')]}
|
27
|
+
end
|
28
|
+
|
29
|
+
connection = Tinder::Connection.new('test', :username => 'user', :password => 'pass')
|
30
|
+
expect(connection.token).to eq("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should use basic auth for credentials" do
|
34
|
+
stub_connection(Tinder::Connection) do |stub|
|
35
|
+
stub.get("/rooms.json") {[200, {}, fixture('rooms.json')]}
|
36
|
+
end
|
37
|
+
connection = Tinder::Connection.new('test', :token => 'mytoken')
|
38
|
+
expect { connection.get('/rooms.json') }.not_to raise_error
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "oauth" do
|
44
|
+
let (:oauth_token) { "myoauthtoken" }
|
45
|
+
let (:connection) { Tinder::Connection.new('test', :oauth_token => oauth_token) }
|
46
|
+
|
47
|
+
before do
|
48
|
+
stub_connection(Tinder::Connection) do |stub|
|
49
|
+
stub.get("/rooms.json") {[200, {}, fixture('rooms.json')]}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should authenticate" do
|
54
|
+
expect { connection.get('/rooms.json') }.to_not raise_error
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should set the oauth_token" do
|
58
|
+
connection.get('/rooms.json')
|
59
|
+
expect(connection.options[:oauth_token]).to eq(oauth_token)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should set an Authorization header" do
|
63
|
+
connection.get('/rooms.json')
|
64
|
+
expect(connection.connection.headers["Authorization"]).to eq("Bearer #{oauth_token}")
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "ssl" do
|
70
|
+
it "should turn on ssl by default" do
|
71
|
+
stub_connection(Tinder::Connection) do |stub|
|
72
|
+
stub.get("/users/me.json") {[200, {}, fixture('users/me.json')]}
|
73
|
+
end
|
74
|
+
|
75
|
+
connection = Tinder::Connection.new('test', :username => 'user', :password => 'pass')
|
76
|
+
expect(connection.ssl?).to eq(true)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should should allow peer verification to be turned off" do
|
80
|
+
stub_connection(Tinder::Connection) do |stub|
|
81
|
+
stub.get("/users/me.json") {[200, {}, fixture('users/me.json')]}
|
82
|
+
end
|
83
|
+
|
84
|
+
connection = Tinder::Connection.new('test', :username => 'user', :password => 'pass', :ssl_verify => false)
|
85
|
+
expect(connection.connection.ssl.verify?).to eq(false)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should allow passing any ssl_options to Faraday" do
|
89
|
+
stub_connection(Tinder::Connection) do |stub|
|
90
|
+
stub.get("/users/me.json") {[200, {}, fixture('users/me.json')]}
|
91
|
+
end
|
92
|
+
connection = Tinder::Connection.new('test',
|
93
|
+
:username => 'user',
|
94
|
+
:password => 'pass',
|
95
|
+
:ssl_options => {
|
96
|
+
:verify => false,
|
97
|
+
:ca_path => "/usr/lib/ssl/certs",
|
98
|
+
:ca_file => "/etc/ssl/custom"
|
99
|
+
}
|
100
|
+
)
|
101
|
+
expect(connection.connection.ssl.to_hash).to eq(:verify => false, :ca_path => "/usr/lib/ssl/certs", :ca_file => "/etc/ssl/custom")
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,364 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
describe Tinder::Room do
|
6
|
+
|
7
|
+
def mock_listen_callbacks(stream)
|
8
|
+
expect(stream).to receive(:each_item).with(any_args).and_return(true)
|
9
|
+
expect(stream).to receive(:on_error)
|
10
|
+
expect(stream).to receive(:on_max_reconnects)
|
11
|
+
end
|
12
|
+
|
13
|
+
before do
|
14
|
+
@connection = Tinder::Connection.new('test', :token => 'mytoken')
|
15
|
+
|
16
|
+
stub_connection(@connection) do |stub|
|
17
|
+
stub.get('/room/80749.json') {[200, {}, fixture('rooms/show.json')]}
|
18
|
+
end
|
19
|
+
|
20
|
+
@room = Tinder::Room.new(@connection, 'id' => 80749, 'name' => 'Room 1')
|
21
|
+
|
22
|
+
# Get EventMachine out of the way. We could be using em-spec, but seems like overkill
|
23
|
+
require 'twitter/json_stream'
|
24
|
+
module EventMachine; def self.run; yield end end
|
25
|
+
expect(EventMachine).to receive(:reactor_running?).at_most(:once).and_return(true)
|
26
|
+
|
27
|
+
@stream = double(Twitter::JSONStream)
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "join" do
|
31
|
+
before do
|
32
|
+
stub_connection(@connection) do |stub|
|
33
|
+
stub.post('/room/80749/join.json') {[200, {}, ""]}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should post to join url" do
|
38
|
+
@room.join
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "leave" do
|
43
|
+
before do
|
44
|
+
stub_connection(@connection) do |stub|
|
45
|
+
stub.post('/room/80749/leave.json') {[200, {}, ""]}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should post to leave url" do
|
50
|
+
@room.leave
|
51
|
+
end
|
52
|
+
|
53
|
+
it "stops listening" do
|
54
|
+
expect(@room).to receive(:stop_listening)
|
55
|
+
@room.leave
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "lock" do
|
60
|
+
before do
|
61
|
+
stub_connection(@connection) do |stub|
|
62
|
+
stub.post('/room/80749/lock.json') {[200, {}, ""]}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should post to lock url" do
|
67
|
+
@room.lock
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "search" do
|
72
|
+
before do
|
73
|
+
stub_connection(@connection) do |stub|
|
74
|
+
stub.get('/search/foo.json') {[200, {}, fixture("rooms/recent.json")]}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should GET the search endpoint with the search term and filter by room" do
|
79
|
+
expect(@room).to receive(:id).twice.and_return(490096)
|
80
|
+
expect(@room).to receive(:parse_message).exactly(2).times
|
81
|
+
@room.search("foo")
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should return empty array if no messages in room" do
|
85
|
+
expect(@room).not_to receive(:parse_message)
|
86
|
+
expect(@room.search("foo")).to be_empty
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "transcript" do
|
91
|
+
it "should GET the transcript endpoint with the provided date" do
|
92
|
+
stub_connection(@connection) do |stub|
|
93
|
+
stub.get('/room/80749/transcript/2012/10/15.json') {[200, {}, fixture("rooms/recent.json")]}
|
94
|
+
end
|
95
|
+
expect(@room).to receive(:parse_message).exactly(2).times
|
96
|
+
@room.transcript(Date.parse('2012-10-15'))
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should default to today's date" do
|
100
|
+
stub_connection(@connection) do |stub|
|
101
|
+
stub.get('/room/80749/transcript/1981/03/21.json') {[200, {}, fixture("rooms/recent.json")]}
|
102
|
+
end
|
103
|
+
expect(Date).to receive(:today).and_return(Date.parse('1981-03-21'))
|
104
|
+
expect(@room).to receive(:parse_message).exactly(2).times
|
105
|
+
@room.transcript
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should return an array of messages" do
|
109
|
+
stub_connection(@connection) do |stub|
|
110
|
+
stub.get('/room/80749/transcript/2012/10/15.json') {[200, {}, fixture('rooms/recent.json')]}
|
111
|
+
stub.get('/users/1158839.json') {[200, {}, fixture('users/me.json')]}
|
112
|
+
stub.get('/users/1158837.json') {[200, {}, fixture('users/me.json')]}
|
113
|
+
end
|
114
|
+
|
115
|
+
expect(@room.transcript(Date.parse('2012-10-15'))).to be_a(Array)
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should have messages with attributes" do
|
119
|
+
stub_connection(@connection) do |stub|
|
120
|
+
stub.get('/room/80749/transcript/2012/10/15.json') {[200, {}, fixture("rooms/recent.json")]}
|
121
|
+
stub.get('/users/1158839.json') {[200, {}, fixture('users/me.json')]}
|
122
|
+
stub.get('/users/1158837.json') {[200, {}, fixture('users/me.json')]}
|
123
|
+
end
|
124
|
+
|
125
|
+
message = @room.transcript(Date.parse('2012-10-15')).first
|
126
|
+
|
127
|
+
expect(message[:id]).to be_a(Integer)
|
128
|
+
expect(message[:user][:id]).to be_a(Integer)
|
129
|
+
expect(message[:body]).to be_a(String)
|
130
|
+
expect(message[:created_at]).to be_a(Time)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "unlock" do
|
135
|
+
before do
|
136
|
+
stub_connection(@connection) do |stub|
|
137
|
+
stub.post('/room/80749/unlock.json') {[200, {}, ""]}
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should post to unlock url" do
|
142
|
+
@room.unlock
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "guest_url" do
|
147
|
+
it "should use guest_invite_code if active" do
|
148
|
+
expect(@room).to receive(:guest_access_enabled?).and_return(true)
|
149
|
+
expect(@room).to receive(:guest_invite_code).and_return('123')
|
150
|
+
expect(@room.guest_url).to eq("https://test.campfirenow.com/123")
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should return nil when guest access is not enabled" do
|
154
|
+
expect(@room).to receive(:guest_access_enabled?).and_return(false)
|
155
|
+
expect(@room.guest_url).to be_nil
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should set guest_invite_code" do
|
160
|
+
expect(@room.guest_invite_code).to eq("90cf7")
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should set guest_access_enabled?" do
|
164
|
+
expect(@room.guest_access_enabled?).to eq(true)
|
165
|
+
end
|
166
|
+
|
167
|
+
describe "topic" do
|
168
|
+
it "should get the current topic" do
|
169
|
+
expect(@room.topic).to eq("Testing")
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should get the current topic even if it's changed" do
|
173
|
+
expect(@room.topic).to eq("Testing")
|
174
|
+
|
175
|
+
# reinitialize a new connection since we can't modify the
|
176
|
+
# faraday stack after a request has already been submitted
|
177
|
+
@connection = Tinder::Connection.new('test', :token => 'mytoken')
|
178
|
+
|
179
|
+
# returning a different room's json to get a diff topic
|
180
|
+
stub_connection(@connection) do |stub|
|
181
|
+
stub.get('/room/80749.json') {[200, {}, fixture('rooms/room80751.json')]}
|
182
|
+
end
|
183
|
+
|
184
|
+
expect(@room.topic).to eq("Testing 2")
|
185
|
+
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
describe "name=" do
|
191
|
+
it "should put to update the room" do
|
192
|
+
stub_connection(@connection) do |stub|
|
193
|
+
stub.put('/room/80749.json') {[200, {}, ""]}
|
194
|
+
end
|
195
|
+
|
196
|
+
@room.name = "Foo"
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
describe "listen" do
|
201
|
+
before do
|
202
|
+
stub_connection(@connection) do |stub|
|
203
|
+
stub.post('/room/80749/join.json') {[200, {}, ""]}
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should get from the streaming url" do
|
208
|
+
expect(Twitter::JSONStream).to receive(:connect).with(
|
209
|
+
{
|
210
|
+
:host=>"streaming.campfirenow.com",
|
211
|
+
:path=>"/room/80749/live.json",
|
212
|
+
:auth=>"mytoken:X",
|
213
|
+
:timeout=>6,
|
214
|
+
:ssl=>true
|
215
|
+
}
|
216
|
+
).and_return(@stream)
|
217
|
+
mock_listen_callbacks(@stream)
|
218
|
+
@room.listen { }
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should raise an exception if no block is given" do
|
222
|
+
expect {
|
223
|
+
@room.listen
|
224
|
+
}.to raise_error(ArgumentError, "no block provided")
|
225
|
+
end
|
226
|
+
|
227
|
+
it "marks the room as listening" do
|
228
|
+
expect(Twitter::JSONStream).to receive(:connect).and_return(@stream)
|
229
|
+
mock_listen_callbacks(@stream)
|
230
|
+
expect {
|
231
|
+
@room.listen { }
|
232
|
+
}.to change(@room, :listening?).from(false).to(true)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
describe "stop_listening" do
|
237
|
+
before do
|
238
|
+
stub_connection(@connection) do |stub|
|
239
|
+
stub.post('/room/80749/join.json') {[200, {}, ""]}
|
240
|
+
end
|
241
|
+
|
242
|
+
expect(Twitter::JSONStream).to receive(:connect).and_return(@stream)
|
243
|
+
expect(@stream).to receive(:stop)
|
244
|
+
end
|
245
|
+
|
246
|
+
it "changes a listening room to a non-listening room" do
|
247
|
+
mock_listen_callbacks(@stream)
|
248
|
+
@room.listen { }
|
249
|
+
expect {
|
250
|
+
@room.stop_listening
|
251
|
+
}.to change(@room, :listening?).from(true).to(false)
|
252
|
+
end
|
253
|
+
|
254
|
+
it "tells the json stream to stop" do
|
255
|
+
mock_listen_callbacks(@stream)
|
256
|
+
@room.listen { }
|
257
|
+
@room.stop_listening
|
258
|
+
end
|
259
|
+
|
260
|
+
it "does nothing if the room is not listening" do
|
261
|
+
mock_listen_callbacks(@stream)
|
262
|
+
@room.listen { }
|
263
|
+
@room.stop_listening
|
264
|
+
@room.stop_listening
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
describe "recent" do
|
269
|
+
before do
|
270
|
+
stub_connection(@connection) do |stub|
|
271
|
+
stub.get('/room/80749/recent.json') {[
|
272
|
+
200, {}, fixture('rooms/recent.json')
|
273
|
+
]}
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
it "should get a list of parsed recent messages" do
|
278
|
+
expect(@room).to receive(:parse_message).exactly(2).times
|
279
|
+
messages = @room.recent
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
describe "parse_message" do
|
284
|
+
it "expands user and parses created_at" do
|
285
|
+
unparsed_message = {
|
286
|
+
:user_id => 123,
|
287
|
+
:body => 'An aunt is worth two nieces',
|
288
|
+
:created_at => '2012/02/14 16:21:00 +0000'
|
289
|
+
}
|
290
|
+
expected = {
|
291
|
+
:user => {
|
292
|
+
:name => 'Dr. Noodles'
|
293
|
+
},
|
294
|
+
:body => 'An aunt is worth two nieces',
|
295
|
+
:created_at => Time.parse('2012/02/14 16:21:00 +0000')
|
296
|
+
}
|
297
|
+
expect(@room).to receive(:user).with(123).and_return({ :name => 'Dr. Noodles' })
|
298
|
+
|
299
|
+
actual = @room.parse_message(unparsed_message)
|
300
|
+
expect(actual).to eq(expected)
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
describe "user" do
|
305
|
+
before do
|
306
|
+
expect(@room).to receive(:current_users).and_return([
|
307
|
+
{ :id => 1, :name => 'The Amazing Crayon Executive'},
|
308
|
+
{ :id => 2, :name => 'Lord Pants'},
|
309
|
+
])
|
310
|
+
@not_current_user = { :id => 3, :name => 'Patriot Sally'}
|
311
|
+
end
|
312
|
+
|
313
|
+
it "looks up user if not already in room's cache" do
|
314
|
+
expect(@room).to receive(:fetch_user).with(3).
|
315
|
+
and_return(@not_current_user)
|
316
|
+
expect(@room.user(3)).to eq(@not_current_user)
|
317
|
+
end
|
318
|
+
|
319
|
+
it "pulls user from room's cache if user in participant list" do
|
320
|
+
expect(@room).not_to receive(:fetch_user)
|
321
|
+
user = @room.user(1)
|
322
|
+
end
|
323
|
+
|
324
|
+
it "adds user to cache after first lookup" do
|
325
|
+
expect(@room).to receive(:fetch_user).with(3).at_most(:once).
|
326
|
+
and_return(@not_current_user)
|
327
|
+
expect(@room.user(3)).to eq(@not_current_user)
|
328
|
+
expect(@room.user(3)).to eq(@not_current_user)
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
describe "fetch_user" do
|
333
|
+
before do
|
334
|
+
stub_connection(@connection) do |stub|
|
335
|
+
stub.get("/users/5.json") {[200, {}, fixture('users/me.json')]}
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
it "requests via GET and returns the requested user's information" do
|
340
|
+
expect(@room.fetch_user(5)['name']).to eq('John Doe')
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
describe "current_users" do
|
345
|
+
it "returns list of currently participating users" do
|
346
|
+
current_users = @room.current_users
|
347
|
+
expect(current_users.size).to eq(1)
|
348
|
+
expect(current_users.first[:name]).to eq('Brandon Keepers')
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
describe "users" do
|
353
|
+
it "returns current users if cache has not been initialized yet" do
|
354
|
+
expect(@room).to receive(:current_users).and_return(:the_whole_spittoon)
|
355
|
+
expect(@room.users).to eq(:the_whole_spittoon)
|
356
|
+
end
|
357
|
+
|
358
|
+
it "returns current users plus any added cached users" do
|
359
|
+
expect(@room).to receive(:current_users).and_return([:mia_cuttlefish])
|
360
|
+
@room.users << :guy_wearing_new_mexico_as_a_hat
|
361
|
+
expect(@room.users).to eq([:mia_cuttlefish, :guy_wearing_new_mexico_as_a_hat])
|
362
|
+
end
|
363
|
+
end
|
364
|
+
end
|
data/tinder.gemspec
CHANGED
@@ -1,79 +1,31 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'tinder/version'
|
5
4
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.add_dependency 'eventmachine', '~> 1.0'
|
7
|
+
gem.add_dependency 'faraday', '~> 0.9.0'
|
8
|
+
gem.add_dependency 'faraday_middleware', '~> 0.9'
|
9
|
+
gem.add_dependency 'hashie', ['>= 1.0']
|
10
|
+
gem.add_dependency 'json', '~> 1.8.0'
|
11
|
+
gem.add_dependency 'mime-types'
|
12
|
+
gem.add_dependency 'multi_json', '~> 1.7'
|
13
|
+
gem.add_dependency 'twitter-stream', '~> 0.1'
|
9
14
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
s.description = %q{An API for interfacing with Campfire, the 37Signals chat application.}
|
14
|
-
s.email = %q{brandon@opensoul.org}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"README.txt"
|
17
|
-
]
|
18
|
-
s.files = [
|
19
|
-
".gitignore",
|
20
|
-
"CHANGELOG.txt",
|
21
|
-
"Manifest.txt",
|
22
|
-
"README.txt",
|
23
|
-
"Rakefile",
|
24
|
-
"VERSION",
|
25
|
-
"init.rb",
|
26
|
-
"lib/tinder.rb",
|
27
|
-
"lib/tinder/campfire.rb",
|
28
|
-
"lib/tinder/connection.rb",
|
29
|
-
"lib/tinder/multipart.rb",
|
30
|
-
"lib/tinder/room.rb",
|
31
|
-
"site/index.html",
|
32
|
-
"site/stylesheets/style.css",
|
33
|
-
"spec/campfire_spec.rb",
|
34
|
-
"spec/html/full_lobby.html",
|
35
|
-
"spec/html/normal_lobby.html",
|
36
|
-
"spec/html/transcript.html",
|
37
|
-
"spec/spec.opts",
|
38
|
-
"spec/spec_helper.rb",
|
39
|
-
"test/remote/credentials.rb.example",
|
40
|
-
"test/remote/remote_campfire_test.rb",
|
41
|
-
"test/test_helper.rb",
|
42
|
-
"tinder.gemspec"
|
43
|
-
]
|
44
|
-
s.homepage = %q{http://github.com/collectiveidea/tinder}
|
45
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
46
|
-
s.require_paths = ["lib"]
|
47
|
-
s.rubyforge_project = %q{tinder}
|
48
|
-
s.rubygems_version = %q{1.3.5}
|
49
|
-
s.summary = %q{An (unofficial) Campfire API}
|
50
|
-
s.test_files = [
|
51
|
-
"spec/campfire_spec.rb",
|
52
|
-
"spec/spec_helper.rb",
|
53
|
-
"test/remote/remote_campfire_test.rb",
|
54
|
-
"test/test_helper.rb"
|
55
|
-
]
|
15
|
+
gem.add_development_dependency 'fakeweb'
|
16
|
+
gem.add_development_dependency 'rake'
|
17
|
+
gem.add_development_dependency 'rspec'
|
56
18
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
s.add_dependency(%q<mime-types>, [">= 0"])
|
70
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
71
|
-
end
|
72
|
-
else
|
73
|
-
s.add_dependency(%q<activesupport>, [">= 0"])
|
74
|
-
s.add_dependency(%q<httparty>, [">= 0"])
|
75
|
-
s.add_dependency(%q<mime-types>, [">= 0"])
|
76
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
77
|
-
end
|
19
|
+
gem.authors = ["Brandon Keepers", "Brian Ryckbost", "Tony Coconate"]
|
20
|
+
gem.description = %q{A Ruby API for interfacing with Campfire, the 37Signals chat application.}
|
21
|
+
gem.email = ['brandon@opensoul.org', 'bryckbost@gmail.com', 'me@tonycoconate.com']
|
22
|
+
gem.extra_rdoc_files = ['README.markdown']
|
23
|
+
gem.files = `git ls-files`.split("\n")
|
24
|
+
gem.homepage = 'http://github.com/collectiveidea/tinder'
|
25
|
+
gem.name = 'tinder'
|
26
|
+
gem.require_paths = ['lib']
|
27
|
+
gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
|
28
|
+
gem.summary = %q{Ruby wrapper for the Campfire API}
|
29
|
+
gem.test_files = `git ls-files -- spec/*`.split("\n")
|
30
|
+
gem.version = Tinder::VERSION
|
78
31
|
end
|
79
|
-
|