private_pub 1.0.1 → 1.0.2
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.
- data/CHANGELOG.md +6 -1
- data/README.md +28 -0
- data/lib/private_pub.rb +8 -1
- data/spec/private_pub_spec.rb +31 -2
- metadata +31 -11
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -39,6 +39,29 @@ rackup private_pub.ru -s thin -E production
|
|
39
39
|
|
40
40
|
It's not necessary to include faye.js since that will be handled automatically for you.
|
41
41
|
|
42
|
+
## Serving Faye over HTTPS (with Thin)
|
43
|
+
|
44
|
+
To server Faye over HTTPS you could create a thin configuration file `config/private_pub_thin.yml` similar to the following:
|
45
|
+
|
46
|
+
```yaml
|
47
|
+
---
|
48
|
+
port: 4443
|
49
|
+
ssl: true
|
50
|
+
ssl_key_file: /path/to/server.pem
|
51
|
+
ssl_cert_file: /path/to/certificate_chain.pem
|
52
|
+
environment: production
|
53
|
+
rackup: private_pub.ru
|
54
|
+
```
|
55
|
+
|
56
|
+
The `certificate_chain.pem` file should contain your signed certificate, followed by intermediate certificates (if any) and the root certificate of the CA that signed the key.
|
57
|
+
|
58
|
+
Next reconfigure the URL in `config/private_pub.yml` to look like `https://your.hostname.com:4443/faye`
|
59
|
+
|
60
|
+
Finally start up Thin from the project root.
|
61
|
+
|
62
|
+
```
|
63
|
+
thin -C config/private_pub_thin.yml start
|
64
|
+
```
|
42
65
|
|
43
66
|
## Usage
|
44
67
|
|
@@ -107,6 +130,11 @@ The signature and timestamp checked on the Faye server to ensure users are only
|
|
107
130
|
The `publish_to` method will send a post request to the Faye server (using `Net::HTTP`) instructing it to send the given data back to the browser.
|
108
131
|
|
109
132
|
|
133
|
+
## Project Status
|
134
|
+
|
135
|
+
Unfortunately I have not had time to actively work on this project recently. If you find a critical issue where it does not work as documented please [ping me on Twitter](http://twitter.com/rbates) and I'll take a look.
|
136
|
+
|
137
|
+
|
110
138
|
## Development & Feedback
|
111
139
|
|
112
140
|
Questions or comments? Please use the [issue tracker](https://github.com/ryanb/private_pub/issues). Tests can be run with `bundle` and `rake` commands.
|
data/lib/private_pub.rb
CHANGED
@@ -31,7 +31,14 @@ module PrivatePub
|
|
31
31
|
# Sends the given message hash to the Faye server using Net::HTTP.
|
32
32
|
def publish_message(message)
|
33
33
|
raise Error, "No server specified, ensure private_pub.yml was loaded properly." unless config[:server]
|
34
|
-
|
34
|
+
url = URI.parse(config[:server])
|
35
|
+
|
36
|
+
form = Net::HTTP::Post.new(url.path.empty? ? '/' : url.path)
|
37
|
+
form.set_form_data(:message => message.to_json)
|
38
|
+
|
39
|
+
http = Net::HTTP.new(url.host, url.port)
|
40
|
+
http.use_ssl = url.scheme == "https"
|
41
|
+
http.start {|h| h.request(form)}
|
35
42
|
end
|
36
43
|
|
37
44
|
# Returns a message hash for sending to Faye
|
data/spec/private_pub_spec.rb
CHANGED
@@ -72,11 +72,40 @@ describe PrivatePub do
|
|
72
72
|
|
73
73
|
it "publish message as json to server using Net::HTTP" do
|
74
74
|
PrivatePub.config[:server] = "http://localhost"
|
75
|
-
message =
|
76
|
-
|
75
|
+
message = 'foo'
|
76
|
+
form = mock(:post).as_null_object
|
77
|
+
http = mock(:http).as_null_object
|
78
|
+
|
79
|
+
Net::HTTP::Post.should_receive(:new).with('/').and_return(form)
|
80
|
+
form.should_receive(:set_form_data).with(message: 'foo'.to_json)
|
81
|
+
|
82
|
+
Net::HTTP.should_receive(:new).with('localhost', 80).and_return(http)
|
83
|
+
http.should_receive(:start).and_yield(http)
|
84
|
+
http.should_receive(:request).with(form).and_return(:result)
|
85
|
+
|
77
86
|
PrivatePub.publish_message(message).should eq(:result)
|
78
87
|
end
|
79
88
|
|
89
|
+
it "it should use HTTPS if the server URL says so" do
|
90
|
+
PrivatePub.config[:server] = "https://localhost"
|
91
|
+
http = mock(:http).as_null_object
|
92
|
+
|
93
|
+
Net::HTTP.should_receive(:new).and_return(http)
|
94
|
+
http.should_receive(:use_ssl=).with(true)
|
95
|
+
|
96
|
+
PrivatePub.publish_message('foo')
|
97
|
+
end
|
98
|
+
|
99
|
+
it "it should not use HTTPS if the server URL says not to" do
|
100
|
+
PrivatePub.config[:server] = "http://localhost"
|
101
|
+
http = mock(:http).as_null_object
|
102
|
+
|
103
|
+
Net::HTTP.should_receive(:new).and_return(http)
|
104
|
+
http.should_receive(:use_ssl=).with(false)
|
105
|
+
|
106
|
+
PrivatePub.publish_message('foo')
|
107
|
+
end
|
108
|
+
|
80
109
|
it "raises an exception if no server is specified when calling publish_message" do
|
81
110
|
lambda {
|
82
111
|
PrivatePub.publish_message("foo")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: private_pub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faye
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: rake
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: rspec
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ~>
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: 2.8.0
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.8.0
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: jasmine
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,7 +69,12 @@ dependencies:
|
|
54
69
|
version: 1.1.1
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.1.1
|
58
78
|
description: Private pub/sub messaging in Rails through Faye.
|
59
79
|
email: ryan@railscasts.com
|
60
80
|
executables: []
|
@@ -102,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
122
|
version: 1.3.4
|
103
123
|
requirements: []
|
104
124
|
rubyforge_project: private_pub
|
105
|
-
rubygems_version: 1.8.
|
125
|
+
rubygems_version: 1.8.23
|
106
126
|
signing_key:
|
107
127
|
specification_version: 3
|
108
128
|
summary: Private pub/sub messaging in Rails.
|