planga 0.0.3 → 0.0.4
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 +2 -2
- data/lib/planga.rb +32 -31
- 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: c6ffe01fdbb613efb04c25f71e7e0b973412d111
|
4
|
+
data.tar.gz: 6a8aecf7e8bb6f3e7445dbf946ddda833f2d0494
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09e511265f1ed2993bb4c812b934db8904b1058d44f01f38a70e4e59048dc805ff4bb0faebc0b662d58352fb11297a8a11f46087a0e76b9e05cb60e21d26adab'
|
7
|
+
data.tar.gz: 69549f8ff033da9a7bf0e0f26bcbd10b118325f7ed2521cd7e361418430759b822c329efb014c44fb1c62bb2b4fda521cd35ff6d1d454281035e7a00751ba6a5
|
data/README.md
CHANGED
@@ -11,7 +11,7 @@ Planga Ruby Wrapper:
|
|
11
11
|
```ruby
|
12
12
|
require 'planga'
|
13
13
|
|
14
|
-
|
14
|
+
planga = Planga.new(
|
15
15
|
:public_api_id => "foobar",
|
16
16
|
:private_api_key => "ePxoM3OTkW1z6j84JDurqw",
|
17
17
|
:conversation_id => "general",
|
@@ -20,7 +20,7 @@ conf = PlangaConfiguration.new(
|
|
20
20
|
:container_id => "my_container_div"
|
21
21
|
)
|
22
22
|
|
23
|
-
snippet =
|
23
|
+
snippet = planga.chat_snippet()
|
24
24
|
```
|
25
25
|
|
26
26
|
**Requirements:**
|
data/lib/planga.rb
CHANGED
@@ -3,28 +3,48 @@ require 'jose'
|
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
class Planga
|
6
|
-
|
6
|
+
attr_accessor :public_api_id, :private_api_key, :conversation_id,
|
7
|
+
:current_user_id, :current_user_name, :container_id, :remote_host
|
8
|
+
|
9
|
+
|
10
|
+
def initialize(**conf)
|
11
|
+
@public_api_id = conf[:public_api_id]
|
12
|
+
@private_api_key = conf[:private_api_key]
|
13
|
+
@conversation_id = conf[:conversation_id]
|
14
|
+
@current_user_id = conf[:current_user_id]
|
15
|
+
@current_user_name = conf[:current_user_name]
|
16
|
+
@container_id = conf[:container_id]
|
17
|
+
@remote_host = conf[:remote_host] || "//chat.planga.io"
|
18
|
+
|
19
|
+
if not container_id
|
20
|
+
@container_id = "planga-chat-" + SecureRandom.hex
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def chat_snippet
|
7
26
|
return %{
|
8
|
-
<script type=\"text/javascript\" src=\"#{
|
9
|
-
<div id=\"#{
|
27
|
+
<script type=\"text/javascript\" src=\"#{self.remote_host}/js/js_snippet.js\"></script>
|
28
|
+
<div id=\"#{self.container_id}\"></div>
|
10
29
|
<script type=\"text/javascript\">
|
11
|
-
new Planga(document.getElementById(\"#{
|
12
|
-
public_api_id: \"#{
|
13
|
-
encrypted_options: \"#{
|
14
|
-
socket_location: \"#{
|
30
|
+
new Planga(document.getElementById(\"#{self.container_id}\"), \{
|
31
|
+
public_api_id: \"#{self.public_api_id}\",
|
32
|
+
encrypted_options: \"#{encrypt_options()}\",
|
33
|
+
socket_location: \"#{self.remote_host}/socket\",
|
15
34
|
\});
|
16
35
|
</script>
|
17
36
|
}
|
18
37
|
end
|
19
38
|
|
39
|
+
|
20
40
|
private
|
21
|
-
def
|
22
|
-
key = JOSE::JWK.from({"k" =>
|
41
|
+
def encrypt_options
|
42
|
+
key = JOSE::JWK.from({"k" => self.private_api_key, "kty" => "oct"})
|
23
43
|
|
24
44
|
payload = {
|
25
|
-
"conversation_id":
|
26
|
-
"current_user_id":
|
27
|
-
"current_user_name":
|
45
|
+
"conversation_id": self.conversation_id,
|
46
|
+
"current_user_id": self.current_user_id,
|
47
|
+
"current_user_name": self.current_user_name
|
28
48
|
}
|
29
49
|
|
30
50
|
return JOSE::JWE.block_encrypt(
|
@@ -33,23 +53,4 @@ class Planga
|
|
33
53
|
{ "alg" => "A128GCMKW", "enc" => "A128GCM" }
|
34
54
|
).compact
|
35
55
|
end
|
36
|
-
end
|
37
|
-
|
38
|
-
class PlangaConfiguration
|
39
|
-
attr_accessor :public_api_id, :private_api_key, :conversation_id,
|
40
|
-
:current_user_id, :current_user_name, :container_id, :remote_host
|
41
|
-
|
42
|
-
def initialize(**conf)
|
43
|
-
@public_api_id = conf[:public_api_id]
|
44
|
-
@private_api_key = conf[:private_api_key]
|
45
|
-
@conversation_id = conf[:conversation_id]
|
46
|
-
@current_user_id = conf[:current_user_id]
|
47
|
-
@current_user_name = conf[:current_user_name]
|
48
|
-
@container_id = conf[:container_id]
|
49
|
-
@remote_host = conf[:remote_host] || "//planga.def"
|
50
|
-
|
51
|
-
if not container_id
|
52
|
-
@container_id = "planga-chat-" + SecureRandom.hex
|
53
|
-
end
|
54
|
-
end
|
55
56
|
end
|