planga 0.0.3 → 0.0.4

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 +2 -2
  3. data/lib/planga.rb +32 -31
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a609e6f707bf33cdbff461bd1762ee3f4378d7c1
4
- data.tar.gz: 77a8e01e75dd4b704fd9472779f6ca743c45df76
3
+ metadata.gz: c6ffe01fdbb613efb04c25f71e7e0b973412d111
4
+ data.tar.gz: 6a8aecf7e8bb6f3e7445dbf946ddda833f2d0494
5
5
  SHA512:
6
- metadata.gz: 186a579a23157e19bb5a68b5c03594f0cf4fb27068405fda4140cea4b677b3ff36cbcd27ddc8439f7b9ca5ceb2ccac63e02d291e45a16c08ef22e47c0e483cb3
7
- data.tar.gz: b937d960bb425f386492138f1602d8f17a3081491dcca6bb3270ea21acef51ac4a7de73bdd58d0953cbc7c97839d779440eb68acdfa48ee218920f3f3debfd99
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
- conf = PlangaConfiguration.new(
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 = Planga.get_planga_snippet(conf)
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
- def self.get_planga_snippet(configuration)
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=\"#{configuration.remote_host}/js/js_snippet.js\"></script>
9
- <div id=\"#{configuration.container_id}\"></div>
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(\"#{configuration.container_id}\"), \{
12
- public_api_id: \"#{configuration.public_api_id}\",
13
- encrypted_options: \"#{Planga.encrypt_options(configuration)}\",
14
- socket_location: \"#{configuration.remote_host}/socket\",
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 self.encrypt_options(configuration)
22
- key = JOSE::JWK.from({"k" => configuration.private_api_key, "kty" => "oct"})
41
+ def encrypt_options
42
+ key = JOSE::JWK.from({"k" => self.private_api_key, "kty" => "oct"})
23
43
 
24
44
  payload = {
25
- "conversation_id": configuration.conversation_id,
26
- "current_user_id": configuration.current_user_id,
27
- "current_user_name": configuration.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
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.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wiebe Marten Wijnja