pusher 0.2.1 → 0.2.3

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.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/pusher.rb +25 -12
  3. metadata +1 -1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.3
data/lib/pusher.rb CHANGED
@@ -1,5 +1,6 @@
1
- require 'rest_client'
2
1
  require 'json'
2
+ require 'uri'
3
+ require 'net/http'
3
4
 
4
5
  class Pusher
5
6
 
@@ -13,32 +14,44 @@ class Pusher
13
14
 
14
15
  def self.[](channel_id)
15
16
  @channels ||= {}
16
- @channels[channel_id.to_sym] ||= Channel.new(@key, channel_id)
17
+ @channels[channel_id.to_s] ||= Channel.new(@key, channel_id)
17
18
  end
18
19
 
19
20
  class Channel
20
21
  def initialize(key, id)
21
- @http = RestClient::Resource.new(
22
- "http://#{Pusher.host}:#{Pusher.port}/app/#{key}/channel/#{id}"
23
- )
22
+ @uri = URI.parse("http://#{Pusher.host}:#{Pusher.port}/app/#{key}/channel/#{id}")
23
+ @http = Net::HTTP.new(@uri.host, @uri.port)
24
24
  end
25
25
 
26
26
  def trigger(event_name, data)
27
27
  begin
28
- @http.post(:event => JSON.generate({
29
- :event => event_name,
30
- :data => data
31
- }))
28
+ @http.post(
29
+ @uri.path,
30
+ self.class.turn_into_json({
31
+ :event => event_name,
32
+ :data => data
33
+ }),
34
+ {'Content-Type'=> 'application/json'}
35
+ )
32
36
  rescue StandardError => e
33
37
  handle_error e
34
38
  end
35
39
  end
40
+
41
+ def self.turn_into_json(data)
42
+ j = if Object.const_defined?('ActiveSupport')
43
+ data.to_json
44
+ else
45
+ JSON.generate(data)
46
+ end
47
+ j
48
+ end
36
49
 
37
50
  private
38
51
 
39
- def handle_error(e)
40
- puts e.inspect
41
- end
52
+ def handle_error(e)
53
+ puts e.inspect
54
+ end
42
55
 
43
56
  end
44
57
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pusher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wildfalcon