planga 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/planga.rb +44 -39
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e12d35f94be4c97a00dd851adef3f5ec093b6d1f
4
- data.tar.gz: 5e1e66cf22db3239d17dc53a29c895cc7fc995ac
3
+ metadata.gz: 763322693d99d01a54ad37f478207dec7c365ecd
4
+ data.tar.gz: 7ed0e2f0b23e28c375d787d520efb7400426f180
5
5
  SHA512:
6
- metadata.gz: 2ba888e4fe368156d775e7f5c7d50d8a86e259e2737c1aef48373104cc0c37964e83585be3175629e49a78b0ae606ce524b109d72f283c09ec974da17179bd3b
7
- data.tar.gz: daf392c96dc10e331802fe42a5f98dbde0a8ea5e208951b34b9eff2137adcef348fc274a7397b238e86c90bb5ce1bf5fb4fa12182a6835cc914a4fe8b837a096
6
+ metadata.gz: 326d4f47b3f0615deed9cb74ea269ec83652c28216a61a51e8b1e05ce86391978eb49d133213b8660507fdf3d67427eba7127636fe9f82ba7f0a775e6007bd01
7
+ data.tar.gz: 9308434ab433890f5bc2800da817c49e45f08af14674c5054346e6f72d917b0ae8dfff704bdba47fc80f9d968b62fa45b929e84d7272da3f74ec3a247caef053
data/README.md CHANGED
@@ -11,7 +11,7 @@ Global installation:
11
11
  `gem install planga`
12
12
  or, for installation in a single project, add
13
13
  ```
14
- gem 'planga', '~> 0.5.0'
14
+ gem 'planga', '~> 0.6.0'
15
15
  ```
16
16
  to your Gemfile.
17
17
 
@@ -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
- # that the user can connect with in this chat. Examples would be "general", "product/1234" or "private/123/543".
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
- # the user currently using your application.
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
- # next to the typed messages
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
- # It defaults to the URL of Planga's main chat server. (`//chat.planga.io`)
30
- # * container_id: If you want a custom HTML ID attribute specified to the created HTML element,
31
- # you can enter it here.
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
- @remote_host = conf[:remote_host] || "//chat.planga.io"
42
- @debug = conf[:debug] || false
41
+ @container_id ||= "planga-chat-" + SecureRandom.hex
43
42
 
44
- if not container_id
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
- return %{
53
- <script type=\"text/javascript\" src=\"#{self.remote_host}/js/js_snippet.js\"></script>
54
- <div id=\"#{self.container_id}\"></div>
55
- <script type=\"text/javascript\">
56
- new Planga(document.getElementById(\"#{self.container_id}\"), \{
57
- public_api_id: \"#{self.public_api_id}\",
58
- encrypted_options: \"#{encrypted_options()}\",
59
- socket_location: \"#{self.remote_host}/socket\",
60
- debug: #{self.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
- key = JOSE::JWK.from({"k" => self.private_api_key, "kty" => "oct"})
69
+ encrypt(construct_encrypted_options())
70
+ end
73
71
 
74
- payload = {
75
- "conversation_id": self.conversation_id,
76
- "current_user_id": self.current_user_id,
77
- "current_user_name": self.current_user_name
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
- return JOSE::JWE.block_encrypt(
81
- key,
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: planga
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wiebe Marten Wijnja