shove 0.52 → 1.0.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.
- data/.gitignore +5 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +63 -0
- data/README.markdown +263 -0
- data/Rakefile +47 -0
- data/bin/shove +128 -106
- data/lib/shove/app.rb +78 -0
- data/lib/shove/app_directory.rb +104 -0
- data/lib/shove/client/callback.rb +24 -0
- data/lib/shove/client/channel.rb +81 -0
- data/lib/shove/client/connection.rb +167 -0
- data/lib/shove/http/channel_context.rb +60 -0
- data/lib/shove/http/client_context.rb +82 -0
- data/lib/shove/http/request.rb +94 -0
- data/lib/shove/http/response.rb +30 -0
- data/lib/shove/protocol.rb +53 -0
- data/lib/shove.rb +60 -78
- data/shove.gemspec +11 -20
- data/spec/app_directory_spec.rb +66 -0
- data/spec/cassettes/should_authorize_oneself.yml +24 -0
- data/spec/cassettes/should_be_able_to_authorize_with_the_server.yml +24 -0
- data/spec/cassettes/should_cancel_a_binding.yml +24 -0
- data/spec/cassettes/should_configure_the_default.yml +24 -0
- data/spec/cassettes/should_configure_the_from_the_previous_test.yml +24 -0
- data/spec/cassettes/should_create_a_channel_context.yml +24 -0
- data/spec/cassettes/should_deny_a_connection.yml +24 -0
- data/spec/cassettes/should_deny_a_control_to_a_client.yml +24 -0
- data/spec/cassettes/should_deny_a_publishing_to_a_client.yml +24 -0
- data/spec/cassettes/should_deny_a_subscriptions_to_a_client.yml +24 -0
- data/spec/cassettes/should_deny_publishing_on_a_channel_context.yml +24 -0
- data/spec/cassettes/should_deny_subscriptions_on_a_channel_context.yml +24 -0
- data/spec/cassettes/should_get_a_set_of_nodes_for_the_network.yml +24 -0
- data/spec/cassettes/should_get_a_subscribe_granted_event.yml +24 -0
- data/spec/cassettes/should_grant_a_connection.yml +24 -0
- data/spec/cassettes/should_grant_a_control_to_a_client.yml +24 -0
- data/spec/cassettes/should_grant_a_publishing_to_a_client.yml +24 -0
- data/spec/cassettes/should_grant_a_subscriptions_to_a_client.yml +24 -0
- data/spec/cassettes/should_grant_publishing_on_a_channel_context.yml +24 -0
- data/spec/cassettes/should_grant_subscriptions_on_a_channel_context.yml +24 -0
- data/spec/cassettes/should_publish.yml +24 -0
- data/spec/cassettes/should_publish_on_a_channel_context.yml +24 -0
- data/spec/cassettes/should_publish_to_a_client.yml +24 -0
- data/spec/cassettes/should_receive_an_unsubscribe_event.yml +24 -0
- data/spec/cassettes/should_receive_messages_on_a_channel.yml +24 -0
- data/spec/cassettes/should_send_a_connect_op.yml +24 -0
- data/spec/cassettes/should_send_a_connect_op_with_an_id.yml +24 -0
- data/spec/cassettes/should_spawn_a_client.yml +24 -0
- data/spec/cassettes/should_subscribe_to_a_channel.yml +24 -0
- data/spec/cassettes/should_trigger_a_connect_denied_event.yml +24 -0
- data/spec/cassettes/should_trigger_a_connect_event.yml +24 -0
- data/spec/cassettes/should_trigger_a_disconnect_event.yml +24 -0
- data/spec/cassettes/should_trigger_an_error_event.yml +24 -0
- data/spec/cassettes/should_unsubscribe_from_a_channel.yml +24 -0
- data/spec/cassettes/should_update_the_default_app.yml +24 -0
- data/spec/helper.rb +60 -0
- data/spec/shove_client_spec.rb +194 -0
- data/spec/shove_http_spec.rb +142 -0
- metadata +111 -81
- data/README.md +0 -71
- data/lib/shove/client.rb +0 -54
- data/lib/shove/request.rb +0 -80
- data/lib/shove/response.rb +0 -23
- data/spec/shove_spec.rb +0 -40
data/lib/shove/request.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
module Shove
|
2
|
-
class Request
|
3
|
-
|
4
|
-
include EventMachine::HttpEncoding
|
5
|
-
|
6
|
-
attr_accessor :url, :headers
|
7
|
-
|
8
|
-
def initialize url, headers={}
|
9
|
-
self.url = url
|
10
|
-
self.headers = headers.merge({
|
11
|
-
"api-key" => Shove.config[:key]
|
12
|
-
})
|
13
|
-
end
|
14
|
-
|
15
|
-
# HTTP Delete request
|
16
|
-
def delete &block
|
17
|
-
exec :delete, &block
|
18
|
-
end
|
19
|
-
|
20
|
-
# HTTP Post request for new content
|
21
|
-
def post params={}, &block
|
22
|
-
exec :post, params, &block
|
23
|
-
end
|
24
|
-
|
25
|
-
# HTTP Put request for updates
|
26
|
-
def put params={}, &block
|
27
|
-
exec :put, params, &block
|
28
|
-
end
|
29
|
-
|
30
|
-
# HTTP Get request
|
31
|
-
def get &block
|
32
|
-
exec :get, &block
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
# exec a HTTP request, and callback with
|
38
|
-
# a response via block
|
39
|
-
def exec method, params={}, &block
|
40
|
-
|
41
|
-
# run async so we don't block if EM is running
|
42
|
-
if EM.reactor_running?
|
43
|
-
http = EventMachine::HttpRequest.new(url).send(method, {
|
44
|
-
:body => params,
|
45
|
-
:head => headers
|
46
|
-
})
|
47
|
-
|
48
|
-
# handle error
|
49
|
-
http.errback {
|
50
|
-
block.call(Response.new(http.response_header.status, http.response, true)) if block_given?
|
51
|
-
}
|
52
|
-
|
53
|
-
# handle success
|
54
|
-
http.callback {
|
55
|
-
status = http.response_header.status
|
56
|
-
block.call(Response.new(status, http.response, status >= 400)) if block_given?
|
57
|
-
}
|
58
|
-
|
59
|
-
# fallback to standard lib for http
|
60
|
-
else
|
61
|
-
uri = URI.parse(url)
|
62
|
-
case method
|
63
|
-
when :post, :put
|
64
|
-
res = Net::HTTP.new(uri.host, uri.port).send(method, uri.path, normalize_body(params), headers)
|
65
|
-
when :get, :delete
|
66
|
-
res = Net::HTTP.new(uri.host, uri.port).send(method, uri.path, headers)
|
67
|
-
end
|
68
|
-
block.call(Response.new(res.code, res.body, res.code.to_i >= 400)) if block_given?
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def normalize_body(body)
|
73
|
-
body.is_a?(Hash) ? form_encode_body(body) : body
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
|
80
|
-
|
data/lib/shove/response.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module Shove
|
2
|
-
class Response
|
3
|
-
|
4
|
-
attr_accessor :status, :message, :error
|
5
|
-
|
6
|
-
def initialize status, message, error=false
|
7
|
-
self.status = status.to_i
|
8
|
-
self.message = message
|
9
|
-
self.error = error
|
10
|
-
end
|
11
|
-
|
12
|
-
# was there an error with the request?
|
13
|
-
def error?
|
14
|
-
error
|
15
|
-
end
|
16
|
-
|
17
|
-
# generate a hash from a json response
|
18
|
-
def to_hash
|
19
|
-
@hash ||= Yajl::Parser.new(:symbolize_keys => true).parse(message)
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
data/spec/shove_spec.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/helper"
|
2
|
-
|
3
|
-
describe Shove do
|
4
|
-
|
5
|
-
before do
|
6
|
-
Shove.configure "./shove.yml"
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should have a version" do
|
10
|
-
Shove.const_defined?("Version").should == true
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should have config" do
|
14
|
-
Shove.config[:network].should == "deadbeef"
|
15
|
-
end
|
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 be able to broadcast a message" do
|
23
|
-
Shove.broadcast("default", "event", "test") do |response|
|
24
|
-
response.error?.should == false
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should be able to broadcast a message with EM" do
|
29
|
-
EM.run do
|
30
|
-
Shove.broadcast("default", "event", "test") do |response|
|
31
|
-
response.error?.should == false
|
32
|
-
end
|
33
|
-
|
34
|
-
EM.add_timer(0.5) do
|
35
|
-
EM.stop
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|