kamiliff 0.9.1 → 0.10.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d54d4db13aebe2f67af89450339aeef983ea29398b09e0e7860f5ec9e9af06b2
4
- data.tar.gz: eeba26bda1ac6981c7f2414a197cf9674646bb407ca397b99eb3cb53433254b7
3
+ metadata.gz: 915f5ef08af7a80fe0bf398fc6904af20bd1724293e185ae9c8e5d32d2fc83bd
4
+ data.tar.gz: 6b2c561c64d3fc1837415e56713ec3619a68e8c060b5d8d54e7ba728ba58e933
5
5
  SHA512:
6
- metadata.gz: 28cfb4e7b0e0f3e09d115a2f07f3fe93d6bc2e4e502f8386061019fcd80270e4589b0f24af43dd489d8b60f76b2abce22d5c30a59acbd404c9308e31f4927969
7
- data.tar.gz: 8e5d40223c25b996d44e47ae382277bea2f03b4a5e28ca939a65702fe24929dda3e991ca086e944ddc062902af87c635c057f2f0cbee9607024785c8a5115198
6
+ metadata.gz: 3e5bf4fd8a2d00cfd03b90607f2f1c1515fba3d9eb9e497db9a99f7abd1d66ea9caa6d012bce2523086cb9280a0fc54e4b099bbc5301c57ddbda015d11b786e4
7
+ data.tar.gz: 37053aa17374dc5febb260edc964224cfda343e96818499b74acdd5bc0c0081c637b0ec1436f588df39f687825a14a08acc2840b12ebd86d22c2a6b01d9f25a6
data/README.md CHANGED
@@ -13,7 +13,7 @@ Kamiliff make LIFF easy to use.
13
13
  gem 'kamiliff'
14
14
  ```
15
15
 
16
- login to line developers, and create 3 LIFF for 3 different size.
16
+ Login to line developers, and create 3 LIFF for 3 different size.
17
17
 
18
18
  - for compact
19
19
  - name: Compact
@@ -30,7 +30,7 @@ login to line developers, and create 3 LIFF for 3 different size.
30
30
  - size: Full
31
31
  - Endpoint URL: https://yourwebsite/liff
32
32
 
33
- and then copy the result to enviroment parameters:
33
+ And then copy the result to enviroment parameters:
34
34
 
35
35
  ```
36
36
  LIFF_COMPACT=line://app/for_compact_liff_id
@@ -40,27 +40,11 @@ LIFF_FULL=line://app/for_full_liff_id
40
40
 
41
41
  ## Usage
42
42
 
43
- ### Implement LIFF View
44
-
45
- Kamiliff using view format `.liff`, so you can reuse exists controller and model, you can create a LIFF form by only adding a new view file.
46
-
47
- Suppose you have a resource `todos`, you want to create a liff form for `todos/new`, so you create a file `app/views/todos/new.liff.erb`, the content is as follows:
48
-
49
- ```
50
- <% content_for :title, "new todo" %>
51
-
52
- <%= render "todos/form.html", todo: @todo %>
53
-
54
- <%= link_to "test", liff_path(path: '/todos/new') %>
55
- ```
56
-
57
- You can test the form at [localhost:3000/todos/new.liff](localhost:3000/todos/new.liff)
58
-
59
43
  ### Generate LIFF Link
60
44
 
61
45
  You can change any path to liff by `liff_path` method.
62
46
 
63
- for example:
47
+ For example:
64
48
 
65
49
  ```
66
50
  liff_path(path: '/todos/new')
@@ -76,8 +60,36 @@ liff_path(path: '/todos/new', liff_size: :full)
76
60
 
77
61
  liff_path method add format :liff automatically.
78
62
 
63
+ ### Implement LIFF View
64
+
65
+ Kamiliff using view format `.liff`, so you can reuse exists controller and model, you can create a LIFF form by only adding a new view file.
66
+
67
+ Suppose you have a resource `todos`, you want to create a liff form for `todos/new`, so you create a file `app/views/todos/new.liff.erb`, the content is as follows:
68
+
69
+ ```
70
+ <% content_for :title, "new todo" %>
71
+
72
+ <%= render "todos/form.html", todo: @todo %>
73
+ ```
74
+
75
+ You can test the form at [localhost:3000/todos/new.liff](localhost:3000/todos/new.liff)
76
+
77
+ ### Receive LIFF Submit Event And Send Message
78
+
79
+ You need to add those js to handle the `liff_submit` event when user submit a form in LIFF.
80
+
81
+ ``` js
82
+ window.addEventListener("liff_submit", function(event){
83
+ var json = JSON.stringify(event.detail.data);
84
+ var url = event.detail.url;
85
+ var method = event.detail.method;
86
+ var request_text = method + " " + url + "\n" + json;
87
+ liff_send_text_message(request_text);
88
+ });
89
+ ```
90
+
79
91
  ## Author
80
- create by [etrex](https://etrex.tw)
92
+ Create by [etrex](https://etrex.tw)
81
93
 
82
94
  ## License
83
95
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -14,7 +14,7 @@ function liff_send_text_message(text){
14
14
  });
15
15
  }
16
16
 
17
- $(function(){
17
+ function register_kamiliff_submit(){
18
18
  function dispatch_liff_event(data){
19
19
  var event = new CustomEvent('liff_submit', { 'detail': data });
20
20
  window.dispatchEvent(event);
@@ -54,4 +54,4 @@ $(function(){
54
54
  })
55
55
  o[last_key] = value;
56
56
  }
57
- });
57
+ }
@@ -1,10 +1,17 @@
1
1
 
2
2
  class LiffController < ApplicationController
3
- layout false
3
+ # layout :liff
4
+ layout false, only: :route
5
+
4
6
 
5
7
  def entry
6
8
  query = Rack::Utils.parse_nested_query(request.query_string)
7
- @body = reserve_route(query["path"], format: :liff)
9
+ @path = query["path"]
10
+ end
11
+
12
+ def route
13
+ path = params["path"]
14
+ @body = reserve_route(path, format: :liff)
8
15
  end
9
16
 
10
17
  private
@@ -1,7 +1,7 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
- <title><%= yield(:title) || "Todo" %></title>
4
+ <title>Loading...</title>
5
5
  <%= csrf_meta_tags %>
6
6
  <%= csp_meta_tag %>
7
7
  <meta name="viewport" content="width=device-width, initial-scale=1" >
@@ -14,11 +14,9 @@
14
14
  <script src="https://d.line-scdn.net/liff/1.0/sdk.js"></script>
15
15
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
16
16
  <%= javascript_include_tag 'kamiliff', 'data-turbolinks-track': 'reload' %>
17
+ <%= yield(:js) %>
17
18
  </head>
18
19
 
19
- <body>
20
- <div class="container-fluid">
21
- <%= yield %>
22
- </div>
20
+ <body id="liff_body">
23
21
  </body>
24
22
  </html>
@@ -1 +1,51 @@
1
- <%= raw @body %>
1
+ <% content_for :js do %>
2
+ <script>
3
+ (function(){
4
+ function append_csrf(data){
5
+ var csrf_param = undefined;
6
+ var csrf_token = undefined;
7
+ var metas = document.getElementsByTagName("META");
8
+ for(var i = 0 ; i < metas.length ; i++){
9
+ var meta = metas[i];
10
+ if(meta.getAttribute('name') == 'csrf-param'){
11
+ csrf_param = meta.content;
12
+ }
13
+ if(meta.getAttribute('name') == 'csrf-token'){
14
+ csrf_token = meta.content;
15
+ }
16
+ }
17
+ if(csrf_param != undefined && csrf_token != undefined){
18
+ data[csrf_param] = csrf_token;
19
+ }
20
+ return data;
21
+ }
22
+
23
+ function render_body(body){
24
+ $("#liff_body").html(body);
25
+ }
26
+
27
+ function route(data){
28
+ $.ajax({
29
+ type: "POST",
30
+ url: '/liff_route',
31
+ data: append_csrf(data)
32
+ }).done(function(html){
33
+ render_body(html);
34
+ register_kamiliff_submit();
35
+ }).fail(function(e){
36
+ alert("on error: " + JSON.stringify(e));
37
+ });
38
+ }
39
+
40
+ liff.init(
41
+ data => {
42
+ data.path = '<%= @path %>';
43
+ route(data);
44
+ },
45
+ err => {
46
+ alert("Please open this url in Line.");
47
+ }
48
+ );
49
+ })();
50
+ </script>
51
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= raw @body %>
data/config/routes.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  Rails.application.routes.draw do
2
2
  # liff
3
- get 'liff', to: 'liff#entry'
3
+ get 'liff_entry', to: 'liff#entry'
4
+ post 'liff_route', to: 'liff#route'
4
5
  end
@@ -1,3 +1,3 @@
1
1
  module Kamiliff
2
- VERSION = '0.9.1'
2
+ VERSION = '0.10.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kamiliff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - etrex kuo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-12 00:00:00.000000000 Z
11
+ date: 2019-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -37,8 +37,9 @@ files:
37
37
  - app/assets/javascripts/kamiliff.js
38
38
  - app/controllers/liff_controller.rb
39
39
  - app/helpers/liff_helper.rb
40
- - app/views/layouts/application.liff.erb
40
+ - app/views/layouts/liff.html.erb
41
41
  - app/views/liff/entry.html.erb
42
+ - app/views/liff/route.html.erb
42
43
  - config/initializers/assets.rb
43
44
  - config/initializers/mime_types.rb
44
45
  - config/routes.rb