pubnub 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of pubnub might be problematic. Click here for more details.

Files changed (2) hide show
  1. data/lib/pubnub.rb +13 -77
  2. metadata +2 -2
data/lib/pubnub.rb CHANGED
@@ -15,15 +15,13 @@ require 'base64'
15
15
  require 'open-uri'
16
16
  require 'uri'
17
17
  require 'net/http'
18
+ require 'net/https'
18
19
  require 'json'
19
20
  require 'pp'
20
21
  require 'rubygems'
21
22
  require 'securerandom'
22
23
  require 'digest'
23
24
  require 'pubnub_crypto'
24
- require 'eventmachine'
25
- require 'em-http'
26
- require 'fiber'
27
25
 
28
26
  class Pubnub
29
27
  MAX_RETRIES = 3
@@ -54,54 +52,6 @@ class Pubnub
54
52
  end
55
53
  end
56
54
 
57
- #**
58
- #* Pubnub 3.0 Compatibility
59
- #*
60
- #* Init the Pubnub Client API
61
- #*
62
- #* @param string publish_key required key to send messages.
63
- #* @param string subscribe_key required key to receive messages.
64
- #* @param string secret_key required key to sign messages.
65
- #* @param boolean ssl required for 2048 bit encrypted messages.
66
- #*
67
- def initialize( publish_key, subscribe_key, secret_key, ssl_on )
68
- @publish_key = publish_key
69
- @subscribe_key = subscribe_key
70
- @secret_key = secret_key
71
- @cipher_key = ''
72
- @ssl = ssl_on
73
- @origin = 'pubsub.pubnub.com'
74
-
75
- if @ssl
76
- @origin = 'https://' + @origin
77
- else
78
- @origin = 'http://' + @origin
79
- end
80
- end
81
-
82
- #**
83
- #* Pubnub 2.0 Compatibility
84
- #*
85
- #* Init the Pubnub Client API
86
- #*
87
- #* @param string publish_key required key to send messages.
88
- #* @param string subscribe_key required key to receive messages.
89
- #*
90
- def initialize( publish_key, subscribe_key )
91
- @publish_key = publish_key
92
- @subscribe_key = subscribe_key
93
- @secret_key = ''
94
- @cipher_key = ''
95
- @ssl = false
96
- @origin = 'pubsub.pubnub.com'
97
-
98
- if @ssl
99
- @origin = 'https://' + @origin
100
- else
101
- @origin = 'http://' + @origin
102
- end
103
- end
104
-
105
55
  #**
106
56
  #* Publish
107
57
  #*
@@ -178,12 +128,12 @@ class Pubnub
178
128
  end
179
129
 
180
130
  ## EventMachine loop
181
- EventMachine.run do
131
+ #EventMachine.run do
182
132
  timetoken = 0
183
133
  request = [ 'subscribe', @subscribe_key, channel, '0', timetoken.to_s ]
184
134
  args['request'] = request
185
135
  _subscribe(args)
186
- end
136
+ #end
187
137
  end
188
138
 
189
139
  #**
@@ -258,9 +208,8 @@ class Pubnub
258
208
  url = @origin + url
259
209
 
260
210
  # Execute Request
261
- http = EventMachine::HttpRequest.new(url, :connect_timeout => 310, :inactivity_timeout => 0).get
262
- http.callback {
263
- http_response = JSON.parse(http.response)
211
+ open(url) do |f|
212
+ http_response = JSON.parse(f.read)
264
213
  messages = http_response[0]
265
214
  timetoken = http_response[1]
266
215
 
@@ -292,11 +241,7 @@ class Pubnub
292
241
  args['request'] = request
293
242
  # Recusive call to _subscribe
294
243
  _subscribe(args)
295
- }
296
- http.errback {
297
- http.error
298
- # TODO: check for time function and reconnect
299
- }
244
+ end
300
245
  end
301
246
 
302
247
  #**
@@ -306,16 +251,13 @@ class Pubnub
306
251
  #* @return array from JSON response.
307
252
  #*
308
253
  def _request(args)
309
- request = args['request']
254
+ request = args['request']
310
255
  callback = args['callback']
311
256
  url = encode_URL(request)
312
257
  url = @origin + url
313
- EventMachine.run {
314
- # Execute Request
315
- http = EventMachine::HttpRequest.new(url, :connect_timeout => 310, :inactivity_timeout => 0).get
316
- http.callback {
258
+ open(url) do |f|
259
+ response = JSON.parse(f.read)
317
260
  if request[0] == 'history'
318
- response = JSON.parse(http.response)
319
261
  if @cipher_key.length > 0
320
262
  myarr=Array.new()
321
263
  response.each do |message|
@@ -329,20 +271,14 @@ class Pubnub
329
271
  end
330
272
  callback.call(myarr)
331
273
  else
332
- callback.call(reponse)
274
+ callback.call(response)
333
275
  end
334
276
  elsif request[0] == 'publish'
335
- callback.call(JSON.parse(http.response))
277
+ callback.call(response)
336
278
  else
337
- callback.call(JSON.parse(http.response))
279
+ callback.call(response)
338
280
  end
339
- EventMachine.stop
340
- }
341
- http.errback {
342
- puts http.error
343
- EventMachine.stop
344
- }
345
- }
281
+ end
346
282
  end
347
283
 
348
284
  def encode_URL(request)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 11
9
- version: 0.1.11
8
+ - 12
9
+ version: 0.1.12
10
10
  platform: ruby
11
11
  authors:
12
12
  - Luke Carpenter / PubNub.com