planga 0.5.0 → 0.6.0
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 +1 -1
- data/lib/planga.rb +44 -39
- 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: 763322693d99d01a54ad37f478207dec7c365ecd
|
|
4
|
+
data.tar.gz: 7ed0e2f0b23e28c375d787d520efb7400426f180
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 326d4f47b3f0615deed9cb74ea269ec83652c28216a61a51e8b1e05ce86391978eb49d133213b8660507fdf3d67427eba7127636fe9f82ba7f0a775e6007bd01
|
|
7
|
+
data.tar.gz: 9308434ab433890f5bc2800da817c49e45f08af14674c5054346e6f72d917b0ae8dfff704bdba47fc80f9d968b62fa45b929e84d7272da3f74ec3a247caef053
|
data/README.md
CHANGED
data/lib/planga.rb
CHANGED
|
@@ -6,10 +6,6 @@ require 'json'
|
|
|
6
6
|
# if included in a webpage, lets the visitor of that webpage
|
|
7
7
|
# connect with the Planga Chat Server and start chatting.
|
|
8
8
|
class Planga
|
|
9
|
-
attr_accessor :public_api_id, :private_api_key, :conversation_id,
|
|
10
|
-
:current_user_id, :current_user_name, :container_id, :remote_host, :debug
|
|
11
|
-
|
|
12
|
-
|
|
13
9
|
# The following configuration options are available:
|
|
14
10
|
#
|
|
15
11
|
# Required are:
|
|
@@ -17,18 +13,18 @@ class Planga
|
|
|
17
13
|
# * public_api_id: The public API ID that can be found in the Planga Dashboard.
|
|
18
14
|
# * private_api_key: The private API key that can be found in the Planga Dashboard.
|
|
19
15
|
# * conversation_id: The identifier that uniquely identifies the single conversation
|
|
20
|
-
#
|
|
16
|
+
# that the user can connect with in this chat. Examples would be "general", "product/1234" or "private/123/543".
|
|
21
17
|
# * current_user_id: The internal ID your application uses, which uniquely identifies
|
|
22
|
-
#
|
|
18
|
+
# the user currently using your application.
|
|
23
19
|
# * current_user_name: The name of this user. This name is shown in the chat interface
|
|
24
|
-
#
|
|
20
|
+
# next to the typed messages
|
|
25
21
|
#
|
|
26
22
|
# Optional are:
|
|
27
|
-
#
|
|
23
|
+
#
|
|
28
24
|
# * remote_host: This can point to another host, if you are hosting your own instance of Planga.
|
|
29
|
-
#
|
|
30
|
-
# * container_id: If you want a custom HTML ID attribute specified to the created HTML element,
|
|
31
|
-
#
|
|
25
|
+
# It defaults to the URL of Planga's main chat server. (`//chat.planga.io`)
|
|
26
|
+
# * container_id: If you want a custom HTML ID attribute specified to the created HTML element,
|
|
27
|
+
# you can enter it here.
|
|
32
28
|
# * debug: (defaults to `false`).
|
|
33
29
|
#
|
|
34
30
|
def initialize(**conf)
|
|
@@ -37,50 +33,59 @@ class Planga
|
|
|
37
33
|
@conversation_id = conf[:conversation_id]
|
|
38
34
|
@current_user_id = conf[:current_user_id]
|
|
39
35
|
@current_user_name = conf[:current_user_name]
|
|
36
|
+
|
|
37
|
+
@remote_host = conf[:remote_host]
|
|
38
|
+
@remote_host ||= "//chat.planga.io"
|
|
39
|
+
|
|
40
40
|
@container_id = conf[:container_id]
|
|
41
|
-
@
|
|
42
|
-
@debug = conf[:debug] || false
|
|
41
|
+
@container_id ||= "planga-chat-" + SecureRandom.hex
|
|
43
42
|
|
|
44
|
-
|
|
45
|
-
@container_id = "planga-chat-" + SecureRandom.hex
|
|
46
|
-
end
|
|
43
|
+
@debug = conf[:debug] || false
|
|
47
44
|
end
|
|
48
|
-
|
|
45
|
+
|
|
49
46
|
|
|
50
47
|
# Creates a full-fledged HTML snippet that includes Planga in your page.
|
|
51
48
|
def chat_snippet
|
|
52
|
-
|
|
53
|
-
<script type
|
|
54
|
-
<div id
|
|
55
|
-
<script type
|
|
56
|
-
new Planga(document.getElementById(
|
|
57
|
-
public_api_id:
|
|
58
|
-
encrypted_options:
|
|
59
|
-
socket_location:
|
|
60
|
-
debug: #{
|
|
49
|
+
<<-SNIPPET
|
|
50
|
+
<script type="text/javascript" src="#{@remote_host}/js/js_snippet.js"></script>
|
|
51
|
+
<div id="#{@container_id}"></div>
|
|
52
|
+
<script type="text/javascript">
|
|
53
|
+
new Planga(document.getElementById("#{@container_id}"), \{
|
|
54
|
+
public_api_id: "#{@public_api_id}",
|
|
55
|
+
encrypted_options: "#{encrypted_options()}",
|
|
56
|
+
socket_location: "#{@remote_host}/socket",
|
|
57
|
+
debug: #{@debug},
|
|
61
58
|
\});
|
|
62
59
|
</script>
|
|
63
|
-
|
|
60
|
+
SNIPPET
|
|
64
61
|
end
|
|
65
|
-
|
|
62
|
+
|
|
66
63
|
|
|
67
64
|
# Returns the encrypted configuration.
|
|
68
65
|
#
|
|
69
66
|
# This function is useful if (and only if) you do not want to use the normal chat snippet,
|
|
70
67
|
# but want to completely customize how Planga loads (so you want to create it manually).
|
|
71
68
|
def encrypted_options
|
|
72
|
-
|
|
69
|
+
encrypt(construct_encrypted_options())
|
|
70
|
+
end
|
|
73
71
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
72
|
+
private def construct_encrypted_options
|
|
73
|
+
{
|
|
74
|
+
"conversation_id": @conversation_id,
|
|
75
|
+
"current_user_id": @current_user_id,
|
|
76
|
+
"current_user_name": @current_user_name
|
|
77
|
+
}.to_json
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
private def encrypt(payload)
|
|
81
|
+
JOSE::JWE.block_encrypt(
|
|
82
|
+
unwrapped_key,
|
|
83
|
+
payload,
|
|
84
|
+
{ "alg" => "A128GCMKW", "enc" => "A128GCM" }
|
|
85
|
+
).compact
|
|
86
|
+
end
|
|
79
87
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
payload.to_json,
|
|
83
|
-
{ "alg" => "A128GCMKW", "enc" => "A128GCM" }
|
|
84
|
-
).compact
|
|
88
|
+
private def unwrapped_key()
|
|
89
|
+
JOSE::JWK.from({"k" => @private_api_key, "kty" => "oct"})
|
|
85
90
|
end
|
|
86
91
|
end
|