pusher 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,6 +12,11 @@ Request pusher credentials from <http://pusherapp.com> and configure the gem
12
12
  Trigger an event
13
13
 
14
14
  Pusher['arbitrary-channel-name'].trigger({:some => 'data'})
15
+
16
+ Logging
17
+ Errors are logger to Pusher.logger. You can set that to any logger you want, ie:
18
+
19
+ Pusher.logger = Rails.logger
15
20
 
16
21
  Copyright
17
22
  ---------
data/Rakefile CHANGED
@@ -6,13 +6,14 @@ begin
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "pusher"
8
8
  gem.summary = %Q{Pusher App client}
9
- gem.description = %Q{Pusher App integartion: Use to make your app send messages to Pushr}
9
+ gem.description = %Q{Pusher App integration: Use to make your app send messages to Pusher}
10
10
  gem.email = "info@new-bamboo.co.uk"
11
11
  gem.homepage = "http://github.com/newbamboo/pusher-gem"
12
12
  gem.authors = ["Wildfalcon", "Ismasan"]
13
13
  # gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
14
  gem.add_dependency "rest-client"
15
15
  gem.add_dependency "json"
16
+ gem.add_development_dependency "rspec", ">= 1.2.9"
16
17
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
18
  end
18
19
  Jeweler::GemcutterTasks.new
@@ -20,36 +21,35 @@ rescue LoadError
20
21
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
22
  end
22
23
 
23
- require 'rake/testtask'
24
- Rake::TestTask.new(:test) do |test|
25
- test.libs << 'lib' << 'test'
26
- test.pattern = 'test/**/test_*.rb'
27
- test.verbose = true
24
+ require 'spec/rake/spectask'
25
+ Spec::Rake::SpecTask.new(:spec) do |spec|
26
+ spec.libs << 'lib' << 'spec'
27
+ spec.spec_files = FileList['spec/**/*_spec.rb']
28
28
  end
29
29
 
30
- begin
31
- require 'rcov/rcovtask'
32
- Rcov::RcovTask.new do |test|
33
- test.libs << 'test'
34
- test.pattern = 'test/**/test_*.rb'
35
- test.verbose = true
36
- end
37
- rescue LoadError
38
- task :rcov do
39
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
- end
30
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
31
+ spec.libs << 'lib' << 'spec'
32
+ spec.pattern = 'spec/**/*_spec.rb'
33
+ spec.rcov = true
34
+ end
35
+
36
+
37
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
38
+ spec.libs << 'lib' << 'spec'
39
+ spec.pattern = 'spec/**/*_spec.rb'
40
+ spec.rcov = true
41
41
  end
42
42
 
43
- task :test => :check_dependencies
43
+ task :spec => :check_dependencies
44
44
 
45
- task :default => :test
45
+ task :default => :spec
46
46
 
47
47
  require 'rake/rdoctask'
48
48
  Rake::RDocTask.new do |rdoc|
49
49
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
50
 
51
51
  rdoc.rdoc_dir = 'rdoc'
52
- rdoc.title = "pusher #{version}"
52
+ rdoc.title = "test #{version}"
53
53
  rdoc.rdoc_files.include('README*')
54
54
  rdoc.rdoc_files.include('lib/**/*.rb')
55
55
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
data/lib/pusher.rb CHANGED
@@ -1,20 +1,29 @@
1
1
  require 'json'
2
2
  require 'uri'
3
3
  require 'net/http'
4
+ require 'logger'
4
5
 
5
6
  class Pusher
6
-
7
+
8
+ class ArgumentError < ::ArgumentError
9
+ def message
10
+ 'You must configure both Pusher.key and Pusher.secret in order to authenticate your Pusher app'
11
+ end
12
+ end
13
+
7
14
  class << self
8
- attr_accessor :host, :port
15
+ attr_accessor :host, :port, :logger
9
16
  attr_writer :key, :secret
10
17
  end
11
18
 
12
- self.host = 'api.pusherapp.com'
13
- self.port = 80
19
+ self.host = 'api.pusherapp.com'
20
+ self.port = 80
21
+ self.logger = Logger.new($STDOUT)
14
22
 
15
23
  def self.[](channel_id)
24
+ raise ArgumentError unless (@key && @secret)
16
25
  @channels ||= {}
17
- @channels[channel_id.to_s] ||= Channel.new(@key, channel_id)
26
+ @channels[channel_id.to_s] = Channel.new(@key, channel_id)
18
27
  end
19
28
 
20
29
  class Channel
@@ -51,7 +60,7 @@ class Pusher
51
60
  private
52
61
 
53
62
  def handle_error(e)
54
- puts e.inspect
63
+ self.logger.error(e.backtrace.join("\n"))
55
64
  end
56
65
 
57
66
  end
@@ -0,0 +1,102 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Pusher do
4
+
5
+ describe 'configuration' do
6
+ it 'should be preconfigured for api host' do
7
+ Pusher.host.should == 'api.pusherapp.com'
8
+ end
9
+
10
+ it 'should be preconfigured for pi port 80' do
11
+ Pusher.port.should == 80
12
+ end
13
+ end
14
+
15
+ describe 'unconfigured' do
16
+ describe 'with missing key and secret' do
17
+ it 'should raise exception' do
18
+ lambda {
19
+ Pusher['test-channel']
20
+ }.should raise_error(Pusher::ArgumentError)
21
+ end
22
+ end
23
+
24
+ describe 'with missing key' do
25
+ before {Pusher.secret = '1234567890'}
26
+ it 'should raise exception' do
27
+ lambda {
28
+ Pusher['test-channel']
29
+ }.should raise_error(Pusher::ArgumentError)
30
+ end
31
+ end
32
+
33
+ describe 'with missing secret' do
34
+ before {Pusher.key = '1234567890'}
35
+ it 'should raise exception' do
36
+ lambda {
37
+ Pusher['test-channel']
38
+ }.should raise_error(Pusher::ArgumentError)
39
+ end
40
+ end
41
+ end
42
+
43
+
44
+ describe 'configured' do
45
+ before do
46
+ Pusher.key = '12345678900000001'
47
+ Pusher.secret = '12345678900000001'
48
+ end
49
+
50
+ describe '.[]' do
51
+ before do
52
+ @channel = Pusher['test_channel']
53
+ end
54
+
55
+ it 'should return a new channel' do
56
+ @channel.should be_kind_of(Pusher::Channel)
57
+ end
58
+ end
59
+
60
+ describe 'calling Channel#trigger' do
61
+
62
+ before do
63
+ @http = mock('HTTP', :post => 'posting')
64
+ Net::HTTP.stub!(:new).and_return @http
65
+ end
66
+
67
+ it 'should configure HTTP library to talk to pusher API' do
68
+ Net::HTTP.should_receive(:new).with('api.pusherapp.com', 80).and_return @http
69
+ Pusher['test_channel'].trigger(
70
+ 'new_event',
71
+ 'Some data'
72
+ )
73
+ end
74
+
75
+ describe 'POSTing to api.pusherapp.com' do
76
+
77
+ it 'should POST JSON to p# usher API' do
78
+ @http.should_receive(:post) do |*args|
79
+ args[0].should == '/app/12345678900000001/channel/test_channel'
80
+ parsed = JSON.parse(args[1])
81
+ parsed['event'].should == 'new_event'
82
+ parsed['data']['name'].should == 'Pusher'
83
+ parsed['data']['last_name'].should == 'App'
84
+ parsed['socket_id'].should == nil
85
+ args[2].should == {'Content-Type'=> 'application/json'}
86
+ end
87
+ Pusher['test_channel'].trigger(
88
+ 'new_event',
89
+ :name => 'Pusher',
90
+ :last_name => 'App'
91
+ )
92
+ end
93
+ end
94
+ end
95
+
96
+ end
97
+
98
+ after do
99
+ Pusher.key = nil
100
+ Pusher.secret = nil
101
+ end
102
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -1,10 +1,8 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
-
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
3
  require 'pusher'
8
-
9
- class Test::Unit::TestCase
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+ Spec::Runner.configure do |config|
7
+
10
8
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 0
9
- version: 0.3.0
8
+ - 1
9
+ version: 0.3.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Wildfalcon
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-03-03 00:00:00 +00:00
18
+ date: 2010-03-28 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -42,7 +42,21 @@ dependencies:
42
42
  version: "0"
43
43
  type: :runtime
44
44
  version_requirements: *id002
45
- description: "Pusher App integartion: Use to make your app send messages to Pushr"
45
+ - !ruby/object:Gem::Dependency
46
+ name: rspec
47
+ prerelease: false
48
+ requirement: &id003 !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ segments:
53
+ - 1
54
+ - 2
55
+ - 9
56
+ version: 1.2.9
57
+ type: :development
58
+ version_requirements: *id003
59
+ description: "Pusher App integration: Use to make your app send messages to Pusher"
46
60
  email: info@new-bamboo.co.uk
47
61
  executables: []
48
62
 
@@ -59,8 +73,9 @@ files:
59
73
  - Rakefile
60
74
  - VERSION
61
75
  - lib/pusher.rb
62
- - test/helper.rb
63
- - test/test_pusher.rb
76
+ - spec/pusher_spec.rb
77
+ - spec/spec.opts
78
+ - spec/spec_helper.rb
64
79
  has_rdoc: true
65
80
  homepage: http://github.com/newbamboo/pusher-gem
66
81
  licenses: []
@@ -92,5 +107,5 @@ signing_key:
92
107
  specification_version: 3
93
108
  summary: Pusher App client
94
109
  test_files:
95
- - test/helper.rb
96
- - test/test_pusher.rb
110
+ - spec/pusher_spec.rb
111
+ - spec/spec_helper.rb
data/test/test_pusher.rb DELETED
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestPusher < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end