shove 0.6.0 → 0.51
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +34 -4
- data/bin/shove +1 -0
- data/lib/shove/client.rb +32 -11
- data/lib/shove/response.rb +2 -7
- data/lib/shove.rb +27 -21
- data/shove.gemspec +16 -7
- data/spec/shove_spec.rb +2 -34
- metadata +30 -10
- data/.gitignore +0 -3
data/README.md
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
:cluster => "cluster"
|
21
21
|
)
|
22
22
|
|
23
|
-
##
|
23
|
+
##Broadcast messages
|
24
24
|
|
25
25
|
# broadcast the "hello" event on the "default" channel with
|
26
26
|
# Hello World! as the data
|
@@ -30,20 +30,20 @@
|
|
30
30
|
puts response.message
|
31
31
|
end
|
32
32
|
|
33
|
-
##
|
33
|
+
##Direct messages
|
34
34
|
|
35
35
|
Shove.direct(userid, "hello", "Hello World!") do |response|
|
36
36
|
# handle response
|
37
37
|
end
|
38
38
|
|
39
|
-
##
|
39
|
+
##Authorize a user
|
40
40
|
|
41
41
|
# authorize user with id userid on channel "default"
|
42
42
|
Shove.authorize(userid, "default") do |response|
|
43
43
|
# handle response
|
44
44
|
end
|
45
45
|
|
46
|
-
##
|
46
|
+
##Stream all data from a channel
|
47
47
|
|
48
48
|
# stream all data on channel "default"
|
49
49
|
Shove.stream("default") do |msg|
|
@@ -56,6 +56,36 @@
|
|
56
56
|
puts msg[:data] # the payload
|
57
57
|
|
58
58
|
end
|
59
|
+
|
60
|
+
##Channel Management
|
61
|
+
Creating channels is a privileged operation. You can do it from the shove.io management console, or via the management API.
|
62
|
+
In the case of the ruby gem, you can manage it straight from ruby.
|
63
|
+
|
64
|
+
# Create a channel
|
65
|
+
options = {
|
66
|
+
:name => "funchannel", #this is the only required field
|
67
|
+
:restricted => false, #require authorization for subscription
|
68
|
+
:broadcastable => true, #allow clients to broadcast to other clients
|
69
|
+
:presence => true #when users subscribe/unsubscribe all other subscribers are notified
|
70
|
+
}
|
71
|
+
Shove.create_channel(options) do |response|
|
72
|
+
if response.error?
|
73
|
+
puts "boooo"
|
74
|
+
puts response.message
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Update a channel
|
79
|
+
Shove.update_channel("funchannel", :presence => false) do |response|
|
80
|
+
# ...
|
81
|
+
end
|
82
|
+
|
83
|
+
# Delete channel
|
84
|
+
# this will unsubscribe all subscribers from this channel
|
85
|
+
# nearly immediately, so make sure you want to do that.
|
86
|
+
Shove.delete_channel("funchannel") do |response|
|
87
|
+
# ...
|
88
|
+
end
|
59
89
|
|
60
90
|
##Block and Non-blocking
|
61
91
|
shover does both. If the shover code happens to run inside of an EM.run block, the HTTP calls
|
data/bin/shove
CHANGED
@@ -16,6 +16,7 @@ unless FileTest.exist?(ymlpath)
|
|
16
16
|
say "Please enter your network information."
|
17
17
|
say "Visit http://shove.io/customer/network/api_access for more info."
|
18
18
|
|
19
|
+
access[:cluster] = ask "Enter Cluster Group: "
|
19
20
|
access[:network] = ask "Enter Network Id: "
|
20
21
|
access[:key] = ask "Enter Network Key: "
|
21
22
|
|
data/lib/shove/client.rb
CHANGED
@@ -6,12 +6,13 @@ module Shove
|
|
6
6
|
# +key+ the api access key
|
7
7
|
# +opts+ hash with a few options, such as:
|
8
8
|
# :secure true or false
|
9
|
-
# :host leave as default unless you
|
9
|
+
# :host leave as default unless you are given a private cluster
|
10
10
|
def initialize opts={}
|
11
11
|
@network = opts[:network]
|
12
|
+
@cluster = opts[:cluster] || "a01"
|
12
13
|
@secure = opts[:secure] || false
|
13
|
-
@host = opts[:host] || "api.shove.io"
|
14
|
-
@
|
14
|
+
@host = opts[:host] || "api.#{@cluster}.shove.io"
|
15
|
+
@web_host = opts[:web_host] || "shove.io"
|
15
16
|
end
|
16
17
|
|
17
18
|
# broadcast a message
|
@@ -44,18 +45,38 @@ module Shove
|
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
47
|
-
#
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
# Channel methods
|
49
|
+
|
50
|
+
# create a channel
|
51
|
+
# +opts+ the hash containing channel options
|
52
|
+
# :restricted
|
53
|
+
# :name
|
54
|
+
def create_channel opts, &block
|
55
|
+
Request.new("#{channel_uri}").post({ :channel => opts }, &block)
|
56
|
+
end
|
57
|
+
|
58
|
+
# delete a channel
|
59
|
+
# +name+ the name of the channel to delete
|
60
|
+
def delete_channel name, &block
|
61
|
+
Request.new("#{channel_uri}/#{name}").delete(&block)
|
52
62
|
end
|
53
|
-
|
63
|
+
|
64
|
+
# update the attributes of a channel
|
65
|
+
# +name+ the name of the channel
|
66
|
+
# +opts+ the options hash to update
|
67
|
+
def update_channel name, opts, &block
|
68
|
+
Request.new("#{channel_uri}/#{name}").put({ :channel => opts }, &block)
|
69
|
+
end
|
70
|
+
|
54
71
|
protected
|
55
72
|
|
56
73
|
def uri
|
57
|
-
(@secure ? "https" : "http") + "://#{@host}
|
74
|
+
(@secure ? "https" : "http") + "://#{@host}/#{@network}"
|
75
|
+
end
|
76
|
+
|
77
|
+
def channel_uri
|
78
|
+
(@secure ? "https" : "http") + "://#{@web_host}/api/#{@network}/channels"
|
58
79
|
end
|
59
80
|
|
60
81
|
end
|
61
|
-
end
|
82
|
+
end
|
data/lib/shove/response.rb
CHANGED
@@ -14,14 +14,9 @@ module Shove
|
|
14
14
|
error
|
15
15
|
end
|
16
16
|
|
17
|
-
#
|
18
|
-
def parse
|
19
|
-
@parsed ||= Yajl::Parser.new(:symbolize_keys => true).parse(message)
|
20
|
-
end
|
21
|
-
|
22
|
-
# alias parse
|
17
|
+
# generate a hash from a json response
|
23
18
|
def to_hash
|
24
|
-
parse
|
19
|
+
@hash ||= Yajl::Parser.new(:symbolize_keys => true).parse(message)
|
25
20
|
end
|
26
21
|
|
27
22
|
end
|
data/lib/shove.rb
CHANGED
@@ -9,12 +9,10 @@ require "yaml"
|
|
9
9
|
##
|
10
10
|
# Shove
|
11
11
|
#
|
12
|
-
# See http://shove.io for an account
|
13
|
-
# See https://github.com/shove/shover for gem documentation
|
14
|
-
# See https://github.com/shove/shove for client documentation
|
12
|
+
# See http://shove.io for an account
|
15
13
|
module Shove
|
16
14
|
|
17
|
-
Version = 0.
|
15
|
+
Version = 0.51
|
18
16
|
|
19
17
|
class << self
|
20
18
|
|
@@ -26,7 +24,6 @@ module Shove
|
|
26
24
|
def configure settings
|
27
25
|
if settings.kind_of? String
|
28
26
|
self.config = YAML.load_file(settings)
|
29
|
-
self.config
|
30
27
|
elsif settings.kind_of? Hash
|
31
28
|
self.config = settings
|
32
29
|
else
|
@@ -64,32 +61,39 @@ module Shove
|
|
64
61
|
def validate
|
65
62
|
client.validate
|
66
63
|
end
|
64
|
+
|
65
|
+
# Channel methods
|
66
|
+
|
67
|
+
# create a channel
|
68
|
+
# +opts+ the hash containing channel options
|
69
|
+
def create_channel opts, &block
|
70
|
+
client.create_channel opts, &block
|
71
|
+
end
|
67
72
|
|
68
|
-
#
|
69
|
-
#
|
70
|
-
def
|
71
|
-
client.
|
73
|
+
# delete a channel
|
74
|
+
# +name+ the name of the channel to delete
|
75
|
+
def delete_channel name, &block
|
76
|
+
client.delete_channel name, &block
|
72
77
|
end
|
73
78
|
|
79
|
+
# update the attributes of a channel
|
80
|
+
# +name+ the name of the channel
|
81
|
+
# +opts+ the options hash to update
|
82
|
+
def update_channel name, opts, &block
|
83
|
+
client.update_channel name, opts, &block
|
84
|
+
end
|
85
|
+
|
86
|
+
|
74
87
|
# act as a stream client. requires EM
|
75
88
|
# +channel+ the channel to stream
|
76
89
|
def stream channel, &block
|
77
90
|
|
78
91
|
unless EM.reactor_running?
|
79
|
-
|
80
|
-
exit
|
81
|
-
end
|
82
|
-
|
83
|
-
## Fetch hosts
|
84
|
-
hostnames = hosts
|
85
|
-
|
86
|
-
if hostnames.empty?
|
87
|
-
puts "Error fetching hosts for network #{config[:network]}"
|
88
|
-
exit
|
92
|
+
raise "You can stream when running in an Eventmachine event loop. EM.run { #code here }"
|
89
93
|
end
|
90
94
|
|
91
95
|
uid = ""
|
92
|
-
http = EventMachine::HttpRequest.new("ws://ws
|
96
|
+
http = EventMachine::HttpRequest.new("ws://ws.shove.io/#{config[:network]}").get :timeout => 0
|
93
97
|
|
94
98
|
http.errback {
|
95
99
|
block.call("Connection Error")
|
@@ -101,7 +105,9 @@ module Shove
|
|
101
105
|
}
|
102
106
|
|
103
107
|
http.stream { |msg|
|
104
|
-
|
108
|
+
|
109
|
+
puts msg
|
110
|
+
|
105
111
|
parts = msg.split "!"
|
106
112
|
|
107
113
|
case parts[1]
|
data/shove.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
spec = Gem::Specification.new do |s|
|
2
2
|
s.name = "shove"
|
3
|
-
s.version = "0.
|
4
|
-
s.date = "2011-
|
3
|
+
s.version = "0.51"
|
4
|
+
s.date = "2011-03-12"
|
5
5
|
s.summary = "Ruby gem for leveraging shove.io, the web push platform"
|
6
6
|
s.email = "dan@shove.io"
|
7
7
|
s.homepage = "https://github.com/shove/shover"
|
@@ -13,11 +13,20 @@ spec = Gem::Specification.new do |s|
|
|
13
13
|
s.add_dependency("yajl-ruby", ">= 0.8.1")
|
14
14
|
|
15
15
|
s.bindir = "bin"
|
16
|
-
|
16
|
+
s.executables = ["shove"]
|
17
|
+
|
17
18
|
s.authors = ["Dan Simpson"]
|
18
19
|
|
19
|
-
s.files =
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
s.files = [
|
21
|
+
"README.md",
|
22
|
+
"shove.gemspec",
|
23
|
+
"Rakefile",
|
24
|
+
"spec/helper.rb",
|
25
|
+
"spec/shove_spec.rb",
|
26
|
+
"lib/shove.rb",
|
27
|
+
"lib/shove/request.rb",
|
28
|
+
"lib/shove/response.rb",
|
29
|
+
"lib/shove/client.rb",
|
30
|
+
"bin/shove"
|
31
|
+
]
|
23
32
|
end
|
data/spec/shove_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + "/helper"
|
|
3
3
|
describe Shove do
|
4
4
|
|
5
5
|
before do
|
6
|
-
Shove.configure "shove.yml"
|
6
|
+
Shove.configure "./shove.yml"
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should have a version" do
|
@@ -11,40 +11,8 @@ describe Shove do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should have config" do
|
14
|
-
Shove.config[
|
14
|
+
Shove.config["network"].should == "shove"
|
15
15
|
end
|
16
16
|
|
17
|
-
it "should be able to authorize with the server" do
|
18
|
-
response = Shove.validate
|
19
|
-
response.error?.should == false
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should get a set of hosts for the network" do
|
23
|
-
response = Shove.hosts
|
24
|
-
response.status.should == 200
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should be able to broadcast a message" do
|
28
|
-
Shove.broadcast("default", "event", "test") do |response|
|
29
|
-
response.error?.should == false
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should be able to broadcast a message with EM" do
|
34
|
-
EM.run do
|
35
|
-
|
36
|
-
##
|
37
|
-
# Setup stream and capture for validation
|
38
|
-
##
|
39
|
-
|
40
|
-
Shove.broadcast("default", "event", "test2") do |response|
|
41
|
-
response.error?.should == false
|
42
|
-
end
|
43
|
-
|
44
|
-
EM.add_timer(0.2) do
|
45
|
-
EM.stop
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
17
|
|
50
18
|
end
|
metadata
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shove
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 51
|
8
|
+
version: "0.51"
|
6
9
|
platform: ruby
|
7
10
|
authors:
|
8
11
|
- Dan Simpson
|
@@ -10,7 +13,8 @@ autorequire:
|
|
10
13
|
bindir: bin
|
11
14
|
cert_chain: []
|
12
15
|
|
13
|
-
date: 2011-
|
16
|
+
date: 2011-03-12 00:00:00 -08:00
|
17
|
+
default_executable:
|
14
18
|
dependencies:
|
15
19
|
- !ruby/object:Gem::Dependency
|
16
20
|
name: em-http-request
|
@@ -20,6 +24,10 @@ dependencies:
|
|
20
24
|
requirements:
|
21
25
|
- - "="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 3
|
30
|
+
- 0
|
23
31
|
version: 0.3.0
|
24
32
|
type: :runtime
|
25
33
|
version_requirements: *id001
|
@@ -31,6 +39,10 @@ dependencies:
|
|
31
39
|
requirements:
|
32
40
|
- - ">="
|
33
41
|
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 4
|
44
|
+
- 0
|
45
|
+
- 3
|
34
46
|
version: 4.0.3
|
35
47
|
type: :runtime
|
36
48
|
version_requirements: *id002
|
@@ -42,6 +54,10 @@ dependencies:
|
|
42
54
|
requirements:
|
43
55
|
- - ">="
|
44
56
|
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
- 8
|
60
|
+
- 1
|
45
61
|
version: 0.8.1
|
46
62
|
type: :runtime
|
47
63
|
version_requirements: *id003
|
@@ -54,17 +70,17 @@ extensions: []
|
|
54
70
|
extra_rdoc_files: []
|
55
71
|
|
56
72
|
files:
|
57
|
-
- .gitignore
|
58
73
|
- README.md
|
74
|
+
- shove.gemspec
|
59
75
|
- Rakefile
|
60
|
-
-
|
76
|
+
- spec/helper.rb
|
77
|
+
- spec/shove_spec.rb
|
61
78
|
- lib/shove.rb
|
62
|
-
- lib/shove/client.rb
|
63
79
|
- lib/shove/request.rb
|
64
80
|
- lib/shove/response.rb
|
65
|
-
- shove.
|
66
|
-
-
|
67
|
-
|
81
|
+
- lib/shove/client.rb
|
82
|
+
- bin/shove
|
83
|
+
has_rdoc: true
|
68
84
|
homepage: https://github.com/shove/shover
|
69
85
|
licenses: []
|
70
86
|
|
@@ -78,17 +94,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
94
|
requirements:
|
79
95
|
- - ">="
|
80
96
|
- !ruby/object:Gem::Version
|
97
|
+
segments:
|
98
|
+
- 0
|
81
99
|
version: "0"
|
82
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
101
|
none: false
|
84
102
|
requirements:
|
85
103
|
- - ">="
|
86
104
|
- !ruby/object:Gem::Version
|
105
|
+
segments:
|
106
|
+
- 0
|
87
107
|
version: "0"
|
88
108
|
requirements: []
|
89
109
|
|
90
110
|
rubyforge_project:
|
91
|
-
rubygems_version: 1.
|
111
|
+
rubygems_version: 1.3.7
|
92
112
|
signing_key:
|
93
113
|
specification_version: 3
|
94
114
|
summary: Ruby gem for leveraging shove.io, the web push platform
|
data/.gitignore
DELETED