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 +4 -4
- data/README.md +10 -0
- data/lib/centrifuge/builder.rb +1 -14
- data/lib/centrifuge/client.rb +9 -0
- data/lib/centrifuge/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a483bf8a32d0af6d5184c0a28f25464705106073
|
4
|
+
data.tar.gz: f972c1f3e9a25c58301a5073de97637b727f813f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
data/lib/centrifuge/builder.rb
CHANGED
@@ -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
|
data/lib/centrifuge/client.rb
CHANGED
@@ -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|
|
data/lib/centrifuge/version.rb
CHANGED