em-campfire 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+ require "rooms_helper"
3
+
4
+ def stub_message_post_request(response_code = 201)
5
+ message_post_url = "https://#{valid_params[:subdomain]}.campfirenow.com/room/123/speak.json"
6
+ stub_request(:post, message_post_url).
7
+ with(:headers => {'Authorization'=>[valid_params[:api_key], 'X'], 'Content-Type' => 'application/json'}).
8
+ to_return(:status => response_code, :body => "", :headers => {})
9
+ end
@@ -0,0 +1,98 @@
1
+ require "spec_helper"
2
+
3
+ def valid_room_cache_data
4
+ {
5
+ 123 => {
6
+ "id" => 123,
7
+ "name" => "foo",
8
+ "users" => []
9
+ },
10
+ 456 => {
11
+ "id" => 456,
12
+ "name" => "bar",
13
+ "users" => []
14
+ }
15
+ }
16
+ end
17
+
18
+ # Joining a room
19
+
20
+ def stub_join_room_request(room, response_code = 200)
21
+ url = "https://#{valid_params[:subdomain]}.campfirenow.com/room/#{room}/join.json"
22
+ stub_request(:post, url).
23
+ with(:headers => {'Authorization'=>[valid_params[:api_key], 'X'], 'Content-Type'=>'application/json'}).
24
+ to_return(:status => response_code, :body => "", :headers => {})
25
+ end
26
+
27
+ # Streaming a room
28
+
29
+ def stream_url_for_room(id)
30
+ "https://streaming.campfirenow.com/room/#{id}/live.json"
31
+ end
32
+
33
+ def stub_stream_room_request(room_id, body, response_code = 200)
34
+ stub_request(:get, stream_url_for_room(room_id)).
35
+ with(:headers => {'Authorization'=>[valid_params[:api_key], 'X']}).
36
+ to_return(:status => response_code, :body => body, :headers => {})
37
+ end
38
+
39
+ def stub_timeout_stream_room_request(room_id)
40
+ stub_request(:get, stream_url_for_room(room_id)).
41
+ with(:headers => {'Authorization'=>[valid_params[:api_key], 'X']}).
42
+ to_timeout
43
+ end
44
+
45
+ def stream_message(body = "This is the body of the message")
46
+ {:room_id=>19505, :created_at=>"2012/10/01 14:24:49 +0000", :body=>body, :starred=>false, :id=>685107688, :user_id=>599452, :type=>"TextMessage"}
47
+ end
48
+
49
+ def stream_message_json(body = "This is the body of the message")
50
+ Yajl::Encoder.encode stream_message(body)
51
+ end
52
+
53
+ # Individual room data requests
54
+
55
+ def room_data_url(room_id)
56
+ "https://#{valid_params[:subdomain]}.campfirenow.com/room/#{room_id}.json"
57
+ end
58
+
59
+ def stub_room_data_request(room_id, response_code = 200)
60
+ body = response_code == 200 ? Yajl::Encoder.encode(:room => valid_room_cache_data[room_id]) : ""
61
+ stub_request(:get, room_data_url(room_id)).
62
+ with(:headers => {'Authorization'=>['6124d98749365e3db2c9e5b27ca04db6', 'X'], 'Content-Type'=>'application/json'}).
63
+ to_return(:status => response_code, :body => body, :headers => {:ETag => etag_for_data(valid_room_cache_data[room_id])})
64
+ end
65
+
66
+ def stub_timeout_room_data_request(room_id)
67
+ stub_request(:get, room_data_url(room_id)).
68
+ with(:headers => {'Authorization'=>['6124d98749365e3db2c9e5b27ca04db6', 'X']}).
69
+ to_timeout
70
+ end
71
+
72
+ # Room list data requests
73
+
74
+ def rooms_data_url
75
+ "https://#{valid_params[:subdomain]}.campfirenow.com/rooms.json"
76
+ end
77
+
78
+ def stub_room_list_data_request(response_code = 200)
79
+ body = response_code == 200 ? Yajl::Encoder.encode(room_list_data_api_response) : ""
80
+ etag_header = response_code == 200 ? {:ETag => 'new etag'} : {:ETag => etag_for_room_list_data}
81
+ stub_request(:get, rooms_data_url).
82
+ with(:headers => {'Authorization'=>['6124d98749365e3db2c9e5b27ca04db6', 'X'], 'Content-Type'=>'application/json', 'ETag' => etag_for_room_list_data}).
83
+ to_return(:status => response_code, :body => body, :headers => etag_header)
84
+ end
85
+
86
+ def stub_timeout_room_list_data_request
87
+ stub_request(:get, rooms_data_url).
88
+ with(:headers => {'Authorization'=>['6124d98749365e3db2c9e5b27ca04db6', 'X'], 'Content-Type'=>'application/json'}).
89
+ to_timeout
90
+ end
91
+
92
+ def room_list_data_api_response
93
+ {'rooms' => valid_room_cache_data.map {|key, val| val}}
94
+ end
95
+
96
+ def etag_for_room_list_data
97
+ etag_for_data(room_list_data_api_response)
98
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,12 @@
1
+ require 'simplecov'
2
+ require 'digest'
3
+
4
+ SimpleCov.start do
5
+ add_filter "/spec/"
6
+ end
7
+
1
8
  require File.expand_path("../lib/em-campfire", File.dirname(__FILE__))
2
9
 
3
- require 'mocha'
4
10
  require 'webmock/rspec'
5
11
 
6
12
  RSpec.configure do |config|
@@ -13,66 +19,28 @@ def a klass, params={}
13
19
  params = valid_params.merge(params) if klass == EM::Campfire
14
20
  klass.new(params)
15
21
  end
16
-
17
- # Urg
18
- def mock_logger
22
+
23
+ def mock_logger(klass = EM::Campfire)
19
24
  @logger_string = StringIO.new
20
25
  @fake_logger = Logger.new(@logger_string)
21
- EM::Campfire.any_instance.expects(:logger).at_least(1).returns(@fake_logger)
26
+ klass.any_instance.expects(:logger).at_least(1).returns(@fake_logger)
22
27
  end
23
-
24
- # Bleurgh
28
+
25
29
  def logger_output
26
30
  str = @logger_string.dup
27
31
  str.rewind
28
32
  str.read
29
33
  end
30
34
 
31
- def valid_user_cache_data
32
- {123 => {"name" => "foo"}, 456 => {"name" => "bar"}, 'me' => {"name" => "bot", "id" => 123}}
33
- end
34
-
35
- def valid_room_cache_data
36
- {
37
- 123 => {
38
- "id" => 123,
39
- "name" => "foo",
40
- "users" => []
41
- },
42
- 456 => {
43
- "id" => 456,
44
- "name" => "bar",
45
- "users" => []
46
- }
47
- }
35
+ def etag_for_data(data)
36
+ "\"#{Digest::SHA2.hexdigest(data.to_s)}\""
48
37
  end
49
38
 
50
39
  def valid_params
51
- {:api_key => "6124d98749365e3db2c9e5b27ca04db6", :subdomain => "oxygen"}
52
- end
53
-
54
- def stub_join_room_request(room)
55
- url = "https://#{valid_params[:subdomain]}.campfirenow.com/room/#{room}/join.json"
56
- stub_request(:post, url).
57
- with(:headers => {'Authorization'=>[valid_params[:api_key], 'X'], 'Content-Type'=>'application/json'}).
58
- to_return(:status => 200, :body => "", :headers => {})
59
- end
60
-
61
- def stub_rooms_data_request
62
- stub_request(:get, "https://#{valid_params[:subdomain]}.campfirenow.com/rooms.json").
63
- with(:headers => {'Authorization'=>['6124d98749365e3db2c9e5b27ca04db6', 'X']}).
64
- to_return(:status => 200, :body => Yajl::Encoder.encode(:rooms => valid_room_cache_data.values), :headers => {})
65
- end
66
-
67
- def stub_message_post_request
68
- message_post_url = "https://#{valid_params[:subdomain]}.campfirenow.com/room/123/speak.json"
69
- stub_request(:post, message_post_url).
70
- with(:headers => {'Authorization'=>[valid_params[:api_key], 'X'], 'Content-Type' => 'application/json'}).
71
- to_return(:status => 201, :body => "", :headers => {})
40
+ {:api_key => "6124d98749365e3db2c9e5b27ca04db6", :subdomain => "oxygen", :ignore_self => false}
72
41
  end
73
42
 
74
- def stub_stream_room_request(room)
75
- stub_request(:get, "https://streaming.campfirenow.com/room/#{room}/live.json").
76
- with(:headers => {'Authorization'=>[valid_params[:api_key], 'X']}).
77
- to_return(:status => 200, :body => "", :headers => {})
43
+ class ModuleHarness
44
+ def subdomain; valid_params[:subdomain]; end
45
+ def api_key; valid_params[:api_key]; end
78
46
  end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ def valid_user_cache_data
4
+ {123 => {"name" => "foo"}, 456 => {"name" => "bar"}, 'me' => {"name" => "bot", "id" => 789}}
5
+ end
6
+
7
+ # Fetching data about users
8
+
9
+ def stub_user_data_request(user_id, response_code = 200)
10
+ body = response_code == 200 ? Yajl::Encoder.encode(:user => valid_user_cache_data[user_id]) : ""
11
+ stub_request(:get, "https://#{valid_params[:subdomain]}.campfirenow.com/users/#{user_id}.json").
12
+ with(:headers => {'Authorization'=>['6124d98749365e3db2c9e5b27ca04db6', 'X'], 'Content-Type'=>'application/json'}).
13
+ to_return(:status => response_code, :body => body, :headers => {:ETag => etag_for_data(valid_user_cache_data[user_id])})
14
+ end
15
+
16
+ def stub_timeout_user_data_request(user_id)
17
+ stub_request(:get, "https://#{valid_params[:subdomain]}.campfirenow.com/users/#{user_id}.json").
18
+ with(:headers => {'Authorization'=>['6124d98749365e3db2c9e5b27ca04db6', 'X'], 'Content-Type'=>'application/json'}).
19
+ to_timeout
20
+ end
21
+
22
+ # Fetching data about self
23
+
24
+ def stub_self_data_request(response_code = 200)
25
+ body = response_code == 200 ? Yajl::Encoder.encode(:user => valid_user_cache_data['me']) : ""
26
+ stub_request(:get, "https://#{valid_params[:subdomain]}.campfirenow.com/users/me.json").
27
+ with(:headers => {'Authorization'=>['6124d98749365e3db2c9e5b27ca04db6', 'X'], 'Content-Type'=>'application/json'}).
28
+ to_return(:status => response_code, :body => body, :headers => {:ETag => etag_for_data(valid_user_cache_data['me'])})
29
+ end
30
+
31
+ def stub_timeout_self_data_request
32
+ stub_request(:get, "https://#{valid_params[:subdomain]}.campfirenow.com/users/me.json").
33
+ with(:headers => {'Authorization'=>['6124d98749365e3db2c9e5b27ca04db6', 'X'], 'Content-Type'=>'application/json'}).
34
+ to_timeout
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-campfire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,85 +9,136 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-18 00:00:00.000000000 Z
12
+ date: 2012-10-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
16
- requirement: &70274674754820 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 1.0.0.beta.4
21
+ version: '1.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70274674754820
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: yajl-ruby
27
- requirement: &70274674754280 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
31
36
  - !ruby/object:Gem::Version
32
- version: 0.8.3
37
+ version: '1.1'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70274674754280
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.1'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: em-http-request
38
- requirement: &70274674753780 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
42
52
  - !ruby/object:Gem::Version
43
- version: 1.0.0.beta.4
53
+ version: '1.0'
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *70274674753780
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rake
49
- requirement: &70274674753320 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
- - - ~>
67
+ - - ! '>='
53
68
  - !ruby/object:Gem::Version
54
- version: 0.9.2
69
+ version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70274674753320
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: rspec
60
- requirement: &70274674752720 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ~>
64
84
  - !ruby/object:Gem::Version
65
- version: 2.6.0
85
+ version: '2.11'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *70274674752720
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '2.11'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: mocha
71
- requirement: &70274674751940 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ~>
75
100
  - !ruby/object:Gem::Version
76
- version: 0.10.0
101
+ version: '0.12'
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *70274674751940
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '0.12'
80
110
  - !ruby/object:Gem::Dependency
81
111
  name: webmock
82
- requirement: &70274674751460 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 1.8.10
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
83
121
  none: false
84
122
  requirements:
85
123
  - - ~>
86
124
  - !ruby/object:Gem::Version
87
- version: 1.7.6
125
+ version: 1.8.10
126
+ - !ruby/object:Gem::Dependency
127
+ name: simplecov
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
88
134
  type: :development
89
135
  prerelease: false
90
- version_requirements: *70274674751460
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
91
142
  description: Eventmachine campfire API lib
92
143
  email:
93
144
  - will@willj.net
@@ -95,24 +146,31 @@ executables: []
95
146
  extensions: []
96
147
  extra_rdoc_files: []
97
148
  files:
149
+ - .gitignore
150
+ - CONTRIBUTING.md
98
151
  - Gemfile
99
- - Gemfile.lock
100
152
  - LICENSE.md
101
153
  - README.md
102
154
  - Rakefile
103
155
  - em-campfire.gemspec
104
156
  - examples/simple.rb
105
157
  - lib/em-campfire.rb
158
+ - lib/em-campfire/cache.rb
106
159
  - lib/em-campfire/connection.rb
107
160
  - lib/em-campfire/messages.rb
108
161
  - lib/em-campfire/rooms.rb
109
162
  - lib/em-campfire/users.rb
110
163
  - lib/em-campfire/version.rb
164
+ - spec/lib/cache_spec.rb
111
165
  - spec/lib/connection_spec.rb
112
166
  - spec/lib/em-campfire_spec.rb
113
167
  - spec/lib/messages_spec.rb
114
168
  - spec/lib/rooms_spec.rb
169
+ - spec/lib/users_spec.rb
170
+ - spec/messages_helper.rb
171
+ - spec/rooms_helper.rb
115
172
  - spec/spec_helper.rb
173
+ - spec/users_helper.rb
116
174
  homepage: https://github.com/wjessop/em-campfire
117
175
  licenses: []
118
176
  post_install_message:
@@ -125,21 +183,32 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
183
  - - ! '>='
126
184
  - !ruby/object:Gem::Version
127
185
  version: '0'
186
+ segments:
187
+ - 0
188
+ hash: 4475605419022692822
128
189
  required_rubygems_version: !ruby/object:Gem::Requirement
129
190
  none: false
130
191
  requirements:
131
192
  - - ! '>='
132
193
  - !ruby/object:Gem::Version
133
194
  version: '0'
195
+ segments:
196
+ - 0
197
+ hash: 4475605419022692822
134
198
  requirements: []
135
199
  rubyforge_project:
136
- rubygems_version: 1.8.10
200
+ rubygems_version: 1.8.24
137
201
  signing_key:
138
202
  specification_version: 3
139
203
  summary: Eventmachine campfire API lib
140
204
  test_files:
205
+ - spec/lib/cache_spec.rb
141
206
  - spec/lib/connection_spec.rb
142
207
  - spec/lib/em-campfire_spec.rb
143
208
  - spec/lib/messages_spec.rb
144
209
  - spec/lib/rooms_spec.rb
210
+ - spec/lib/users_spec.rb
211
+ - spec/messages_helper.rb
212
+ - spec/rooms_helper.rb
145
213
  - spec/spec_helper.rb
214
+ - spec/users_helper.rb