planga 0.0.1

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 +7 -0
  2. data/README.md +26 -0
  3. data/lib/planga.rb +57 -0
  4. metadata +60 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d294bcf960dca05eb0490216ad01618f22200d0c
4
+ data.tar.gz: 5f58a78e10f05b1d9622439373b4c97076526c03
5
+ SHA512:
6
+ metadata.gz: a87050f9510c8f60da001245d05295dce8e4d6d2e1a0a01291510108f8e297a67c501192310368c8ff3d6164de4848cc1b52145d4b21b060c66811b3aa9edc94
7
+ data.tar.gz: 2b82a3b06fd91348b8c3d6e5bdf5865bc58487f6e3b66fdaf16d43702e0ca27393e9b0f7878cedd05a7539fbc86d80a1b5c644d36a80e6dfcbeb38d4dd6f72c7
@@ -0,0 +1,26 @@
1
+ Planga Ruby Wrapper:
2
+ ====================
3
+
4
+ **requirements:**
5
+
6
+ * Ruby >= 2.4.1
7
+ * gem
8
+
9
+ **Build and Deploy new gem:**
10
+
11
+ * run `gem build planga.gemspec`
12
+ * run `gem push planga-n.n.n.gem`
13
+
14
+ **Installing the new gem:**
15
+
16
+ * run `gem install planga`
17
+
18
+ **Example usage**
19
+
20
+ ```ruby
21
+ require 'planga'
22
+
23
+ conf = PlangaConfiguration.new("foobar", "kl9psH9VrLZ1hfsPY0b3-W", "general", "1234", "Bob", "my_container_div")
24
+
25
+ snippet = Planga.get_planga_snippet(conf)
26
+ ```
@@ -0,0 +1,57 @@
1
+ require 'securerandom'
2
+ require 'jose'
3
+ require 'json'
4
+
5
+ class Planga
6
+ def self.get_planga_snippet(configuration)
7
+ return %{
8
+ <script type=\"text/javascript\" src=\"#{configuration.remote_host}/js/js_snippet.js\"></script>
9
+ <div id=\"#{configuration.container_id}\"></div>
10
+ <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\",
15
+ \});
16
+ </script>
17
+ }
18
+ end
19
+
20
+ private
21
+ def self.encrypt_options(configuration)
22
+ key = JOSE::JWK.from({"k" => configuration.private_api_key, "kty" => "oct"})
23
+
24
+ payload = {
25
+ "conversation_id": configuration.conversation_id,
26
+ "current_user_id": configuration.current_user_id,
27
+ "current_user_name": configuration.current_user_name
28
+ }
29
+
30
+ return JOSE::JWE.block_encrypt(
31
+ key,
32
+ payload.to_json,
33
+ { "alg" => "A128GCMKW", "enc" => "A128GCM" }
34
+ ).compact
35
+ 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(public_api_id=nil, private_api_key=nil, conversation_id=nil,
43
+ current_user_id=nil, current_user_name=nil, container_id=nil)
44
+
45
+ @public_api_id = public_api_id
46
+ @private_api_key = private_api_key
47
+ @conversation_id = conversation_id
48
+ @current_user_id = current_user_id
49
+ @current_user_name = current_user_name
50
+ @container_id = container_id
51
+ @remote_host = "//planga.def"
52
+
53
+ if not container_id
54
+ @container_id = "planga-chat-" + SecureRandom.hex
55
+ end
56
+ end
57
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: planga
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Wiebe Marten Wijnja
8
+ - Jeroen Hoekstra
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2018-09-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: jose
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ description: Wrapper for interacting with the Planga chat server.
29
+ email:
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - README.md
35
+ - lib/planga.rb
36
+ homepage: https://github.com/ResiliaDev/Planga
37
+ licenses:
38
+ - MIT
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 2.6.11
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Planga
60
+ test_files: []