pusher 0.5.0 → 0.5.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.
@@ -0,0 +1,6 @@
1
+ * master *
2
+
3
+ * Pusher v0.5.1 (20th May, 2010) *
4
+
5
+ * Use ActiveSupport::JSON.encode instead of #to_json to avoid conflicts with JSON gem. [OL]
6
+ * Support loading Pusher credentials from a PUSHER_URL environment variable. [ML]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.1
@@ -20,18 +20,44 @@ module Pusher
20
20
  def authentication_token
21
21
  Signature::Token.new(@key, @secret)
22
22
  end
23
+
24
+ # Builds a connection url for Pusherapp
25
+ def url
26
+ @url ||= URI::HTTP.build({
27
+ :host => self.host,
28
+ :port => self.port,
29
+ :path => "/apps/#{self.app_id}"
30
+ })
31
+ end
32
+
33
+ # Allows configuration from a url
34
+ def url=(url)
35
+ uri = URI.parse(url)
36
+ self.app_id = uri.path.split('/').last
37
+ self.key = uri.user
38
+ self.secret = uri.password
39
+ self.host = uri.host
40
+ self.port = uri.port
41
+ end
42
+
43
+ private
44
+
45
+ def configured?
46
+ host && port && key && secret && app_id
47
+ end
23
48
  end
24
49
 
25
- self.app_id = ENV["PUSHER_APP_ID"] if ENV["PUSHER_APP_ID"]
26
- self.key = ENV["PUSHER_KEY"] if ENV["PUSHER_KEY"]
27
- self.secret = ENV["PUSHER_SECRET"] if ENV["PUSHER_SECRET"]
28
- self.host = ENV["PUSHER_API_HOST"] || 'api.pusherapp.com'
29
- self.port = ENV["PUSHER_API_PORT"] || 80
50
+ self.host = 'api.pusherapp.com'
51
+ self.port = 80
52
+
53
+ if ENV['PUSHER_URL']
54
+ self.url = ENV['PUSHER_URL']
55
+ end
30
56
 
31
57
  def self.[](channel_name)
32
- raise ArgumentError, 'Missing configuration: please check that Pusher.app_id, Pusher.key, and Pusher.secret are all configured' unless @app_id && @key && @secret
58
+ raise ArgumentError, 'Missing configuration: please check that Pusher.url is configured' unless configured?
33
59
  @channels ||= {}
34
- @channels[channel_name.to_s] = Channel.new(@app_id, channel_name)
60
+ @channels[channel_name.to_s] = Channel.new(url, channel_name)
35
61
  end
36
62
  end
37
63
 
@@ -10,13 +10,10 @@ module Pusher
10
10
  class Channel
11
11
  attr_reader :name
12
12
 
13
- def initialize(app_id, name)
13
+ def initialize(base_url, name)
14
+ @uri = base_url.dup
15
+ @uri.path = @uri.path + "/channels/#{name}/events"
14
16
  @name = name
15
- @uri = URI::HTTP.build({
16
- :host => Pusher.host,
17
- :port => Pusher.port,
18
- :path => "/apps/#{app_id}/channels/#{name}/events"
19
- })
20
17
  end
21
18
 
22
19
  def trigger_async(event_name, data, socket_id = nil, &block)
@@ -29,7 +29,7 @@ module Pusher
29
29
 
30
30
  def self.turn_into_json(data)
31
31
  if Object.const_defined?('ActiveSupport')
32
- data.to_json
32
+ ActiveSupport::JSON.encode(data)
33
33
  else
34
34
  JSON.generate(data)
35
35
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{pusher}
8
- s.version = "0.5.0"
8
+ s.version = "0.5.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["New Bamboo"]
12
- s.date = %q{2010-05-14}
12
+ s.date = %q{2010-05-20}
13
13
  s.description = %q{Wrapper for pusherapp.com REST api}
14
14
  s.email = %q{support@pusherapp.com}
15
15
  s.extra_rdoc_files = [
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.files = [
20
20
  ".document",
21
21
  ".gitignore",
22
+ "CHANGELOG",
22
23
  "LICENSE",
23
24
  "README.md",
24
25
  "Rakefile",
@@ -10,7 +10,7 @@ describe Pusher do
10
10
  Pusher.host.should == 'api.pusherapp.com'
11
11
  end
12
12
 
13
- it 'should be preconfigured for pi port 80' do
13
+ it 'should be preconfigured for port 80' do
14
14
  Pusher.port.should == 80
15
15
  end
16
16
 
@@ -28,6 +28,26 @@ describe Pusher do
28
28
  end
29
29
  end
30
30
 
31
+ describe "configuration using url" do
32
+ after do
33
+ Pusher.app_id = nil
34
+ Pusher.key = nil
35
+ Pusher.secret = nil
36
+ Pusher.host = 'api.pusherapp.com'
37
+ Pusher.port = 80
38
+ end
39
+
40
+ it "should be possible to configure everything by setting the url" do
41
+ Pusher.url = "http://somekey:somesecret@api.staging.pusherapp.com:8080/apps/87"
42
+
43
+ Pusher.host.should == 'api.staging.pusherapp.com'
44
+ Pusher.port.should == 8080
45
+ Pusher.key.should == 'somekey'
46
+ Pusher.secret.should == 'somesecret'
47
+ Pusher.app_id.should == '87'
48
+ end
49
+ end
50
+
31
51
  describe 'configured' do
32
52
  before do
33
53
  Pusher.app_id = '20'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 0
9
- version: 0.5.0
8
+ - 1
9
+ version: 0.5.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - New Bamboo
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-14 00:00:00 +01:00
17
+ date: 2010-05-20 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -103,6 +103,7 @@ extra_rdoc_files:
103
103
  files:
104
104
  - .document
105
105
  - .gitignore
106
+ - CHANGELOG
106
107
  - LICENSE
107
108
  - README.md
108
109
  - Rakefile