shove 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shove (1.0.1)
4
+ shove (1.0.3)
5
5
  confstruct (>= 0.2.1)
6
6
  em-http-request (>= 1.0.0)
7
7
  em-ws-client (>= 0.1.2)
@@ -13,11 +13,11 @@ GEM
13
13
  addressable (2.2.6)
14
14
  albino (1.3.3)
15
15
  posix-spawn (>= 0.3.6)
16
- confstruct (0.2.1)
16
+ confstruct (0.2.2)
17
17
  cookiejar (0.3.0)
18
18
  crack (0.3.1)
19
19
  diff-lcs (1.1.3)
20
- em-http-request (1.0.1)
20
+ em-http-request (1.0.2)
21
21
  addressable (>= 2.2.3)
22
22
  cookiejar
23
23
  em-socksify
data/bin/shove CHANGED
@@ -107,12 +107,21 @@ begin
107
107
  client = Shove.connect
108
108
  client.authorize(app_dir.key(app))
109
109
 
110
+ client.on("connect") do |error|
111
+ puts "Connected"
112
+ end
113
+
110
114
  client.on("error") do |error|
111
115
  puts "Watch Error #{error}"
112
116
  EM.stop
113
117
  end
114
118
 
115
119
  channel = client.channel(channel)
120
+
121
+ channel.on("subscribe_denied") do
122
+ puts "Subscribe Denied"
123
+ end
124
+
116
125
  channel.on("subscribe") do
117
126
  puts "Subscribed"
118
127
  end
@@ -120,6 +129,7 @@ begin
120
129
  channel.on("message") do |msg|
121
130
  puts "#{Time.now}: #{msg}"
122
131
  end
132
+
123
133
  end
124
134
 
125
135
  else
data/lib/shove/app.rb CHANGED
@@ -17,6 +17,11 @@ module Shove
17
17
  end
18
18
 
19
19
  def configure params={}, &block
20
+
21
+ @config.configure do
22
+ api_url Shove.config.api_url || "https://api.shove.io"
23
+ end
24
+
20
25
  if params
21
26
  @config.configure params
22
27
  end
@@ -25,8 +30,8 @@ module Shove
25
30
  @config.configure(&block)
26
31
  end
27
32
 
28
- unless @config.app_id && @config.app_key
29
- raise ShoveException.new("App ID and App Key are required")
33
+ unless @config.app_id
34
+ raise ShoveException.new("App ID required")
30
35
  end
31
36
  end
32
37
 
@@ -24,6 +24,12 @@ module Shove
24
24
  def authorize app_key=nil
25
25
  send_data :opcode => AUTHORIZE, :data => (app_key || @config.app_key)
26
26
  end
27
+
28
+ # Enable or disable debugging
29
+ # +on+ true to enable debugging
30
+ def debug on=true
31
+ @debug = on
32
+ end
27
33
 
28
34
  # Connect to the shove stream server
29
35
  def connect
@@ -89,7 +95,7 @@ module Shove
89
95
  if @hosts.empty?
90
96
  raise "Error fetching hosts for app #{@app_id}"
91
97
  end
92
- @url = "ws://#{@hosts.first}.shove.io/#{@config.app_id}"
98
+ @url = "ws://#{@hosts.first}/#{@config.app_id}"
93
99
  end
94
100
  @url
95
101
  end
@@ -15,8 +15,8 @@ module Shove
15
15
  def publish message, &block
16
16
  if @channel == "*"
17
17
  raise ShoveException.new("Cannot publish to *")
18
- elsif message.size > 8096
19
- raise ShoveException.new("Max message size is 8,096 bytes")
18
+ elsif message.size > 2048
19
+ raise ShoveException.new("Max message size is 2 KiB")
20
20
  end
21
21
  @app.request("publish?channel=#{@channel}").post(message, &block)
22
22
  end
@@ -43,9 +43,11 @@ module Shove
43
43
 
44
44
  req.basic_auth "", key
45
45
 
46
- res = Net::HTTP.start(uri.host, uri.port) { |http|
47
- http.request(req, normalize_body(params))
48
- }
46
+ http = Net::HTTP.new(uri.host, uri.port)
47
+ http.use_ssl = uri.scheme == "https"
48
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
49
+
50
+ res = http.request(req, normalize_body(params))
49
51
 
50
52
  result = Response.new(res.code, res.body, res.code.to_i >= 400)
51
53
  if block_given?
@@ -65,13 +67,17 @@ module Shove
65
67
 
66
68
  # handle error
67
69
  http.errback {
68
- block.call(Response.new(http.response_header.status, http.response, true))
70
+ if block
71
+ block.call(Response.new(http.response_header.status, http.response, true))
72
+ end
69
73
  }
70
74
 
71
75
  # handle success
72
76
  http.callback {
73
77
  status = http.response_header.status
74
- block.call(Response.new(status, http.response, status >= 400))
78
+ if block
79
+ block.call(Response.new(status, http.response, status >= 400))
80
+ end
75
81
  }
76
82
  end
77
83
 
data/lib/shove.rb CHANGED
@@ -2,6 +2,7 @@ $:.unshift File.dirname(__FILE__)
2
2
 
3
3
  require "rubygems"
4
4
  require "net/http"
5
+ require "net/https"
5
6
  require "em-http-request"
6
7
  require "em-ws-client"
7
8
  require "yajl"
@@ -16,7 +17,7 @@ require "confstruct"
16
17
  # See https://github.com/shove/shove for client documentation
17
18
  module Shove
18
19
 
19
- Version = "1.0.2"
20
+ Version = "1.0.3"
20
21
 
21
22
  class ShoveException < Exception; end
22
23
 
@@ -31,7 +32,7 @@ module Shove
31
32
 
32
33
  unless defined? @config
33
34
  @config = Confstruct::Configuration.new do
34
- api_url "https://api.shove.io/"
35
+ api_url "https://api.shove.io"
35
36
  end
36
37
  end
37
38
 
data/shove.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = "shove"
3
- s.version = "1.0.2"
3
+ s.version = "1.0.3"
4
4
  s.date = "2012-02-08"
5
5
  s.summary = "Ruby gem for leveraging shove.io, the web push platform"
6
6
  s.email = "dan@shove.io"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shove
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-02-08 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: em-http-request
16
- requirement: &20127560 !ruby/object:Gem::Requirement
16
+ requirement: &22523120 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *20127560
24
+ version_requirements: *22523120
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: em-ws-client
27
- requirement: &20102540 !ruby/object:Gem::Requirement
27
+ requirement: &22522380 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.1.2
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *20102540
35
+ version_requirements: *22522380
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: yajl-ruby
38
- requirement: &20101540 !ruby/object:Gem::Requirement
38
+ requirement: &22521920 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.1.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *20101540
46
+ version_requirements: *22521920
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: confstruct
49
- requirement: &20099280 !ruby/object:Gem::Requirement
49
+ requirement: &22521440 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 0.2.1
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *20099280
57
+ version_requirements: *22521440
58
58
  description: Client side implementation for the shove.io API. See http://shove.io/documentation
59
59
  email: dan@shove.io
60
60
  executables: