centrifuge 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4c60c2017ed840a854c4cb498ba8846ffc43f4a
4
- data.tar.gz: 75bf9f657b98acc2b954267e83a4fbb940e210f7
3
+ metadata.gz: a483bf8a32d0af6d5184c0a28f25464705106073
4
+ data.tar.gz: f972c1f3e9a25c58301a5073de97637b727f813f
5
5
  SHA512:
6
- metadata.gz: de2852d46ce56a14bb2267bc344c13681911e072ef5d071038bec3d378d0898790e105e879097bf19ae77c20d28f334f0f9a0d9f54078db7082fcab00fbf9713
7
- data.tar.gz: 06639e6c2c819ee7b28ac12adf0499a728737f9e385540c53b816cc2761a00d777d23580b214d92fb32a398e0c72c5c56660fde9450b7ae5ead0d493368bc466
6
+ metadata.gz: 7c6d42a81060a3da3f7e47c9bbd11d131ce1bdc025847b5caff58758552d6da63d849976027f60655b28fe54aa01da90c0c8917326f4326c500f85a5ff085693
7
+ data.tar.gz: 064ae4451a97f1869121e8c19439c65809f2381747fc75137a675c5a154601e5a7c55f52188c702e11f2faff6761afd51bd5ea2006d670f836e35e30c0afa25d
data/README.md CHANGED
@@ -72,6 +72,16 @@ Gets message history of the channel:
72
72
 
73
73
  client.history('test_channel')
74
74
 
75
+ ### JS Client token generation
76
+
77
+ Generates token for JS client:
78
+
79
+ client.token_for('testuser', '123123')
80
+
81
+ Where `123123` is UNIX timestamp. You can also add user info as valid json string as third parameter:
82
+
83
+ client.token_for('testuser', '123123', "{}")
84
+
75
85
  ### Other API
76
86
 
77
87
  Other API methods, like projects and channels management are unavailable now.
@@ -10,7 +10,7 @@ module Centrifuge
10
10
 
11
11
  def process
12
12
  body = { data: json(method, data) }
13
- body.merge!(sign: sign(body[:data]))
13
+ body.merge!(sign: client.sign(body[:data]))
14
14
  Centrifuge::Request.new(client.client, 'POST', client.url, nil, body).send
15
15
  end
16
16
 
@@ -19,18 +19,5 @@ module Centrifuge
19
19
  def json(method, params)
20
20
  MultiJson.dump({ method: method, params: params })
21
21
  end
22
-
23
- def sign(body)
24
- dig = OpenSSL::Digest.new('md5')
25
- OpenSSL::HMAC.hexdigest(dig, secret, "#{project_id}#{body}")
26
- end
27
-
28
- def project_id
29
- client.project_id
30
- end
31
-
32
- def secret
33
- client.secret
34
- end
35
22
  end
36
23
  end
@@ -59,6 +59,15 @@ module Centrifuge
59
59
  Centrifuge::Builder.new('history', { channel: channel }, self).process
60
60
  end
61
61
 
62
+ def token_for(user, timestamp, user_info = "")
63
+ sign("#{user}#{timestamp}#{user_info}")
64
+ end
65
+
66
+ def sign(body)
67
+ dig = OpenSSL::Digest.new('md5')
68
+ OpenSSL::HMAC.hexdigest(dig, secret, "#{project_id}#{body}")
69
+ end
70
+
62
71
  def client
63
72
  @client ||= begin
64
73
  HTTPClient.new.tap do |http|
@@ -1,3 +1,3 @@
1
1
  module Centrifuge
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: centrifuge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Bovykin