kamiliff 0.14.0 → 0.19.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 +106 -1
- data/app/controllers/liff_controller.rb +15 -8
- data/app/helpers/liff_helper.rb +6 -5
- data/app/views/layouts/liff.html.erb +20 -5
- data/app/views/liff/entry.html.erb +23 -9
- data/lib/kamiliff.rb +1 -0
- data/lib/kamiliff/services/liff_service.rb +26 -0
- data/lib/kamiliff/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 498ccd4075fc6cdf241d6ec11ecc943a1d5a18799677baf5a4b665585eca0658
|
4
|
+
data.tar.gz: ce48f53be68d877bb2efacc71eb264e8d6d74a499287bd9b1ba478bc10e12ea9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecd86a4de7d7e18be3a9ba5049ab36bdee3ebfa246ce07225a632d6739d86758dd71dc4e6aaa072110d750653029adc341e1c1bec06450e4c12eef0c14f7975e
|
7
|
+
data.tar.gz: 1538d204048373fa00fc63e9f8046039b2e8312ad48525d6505d3155fa381871339ad76d61c43dfe1088e06201c121e4cd15e38ec33491aaea0f56a814b98566
|
data/README.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
# Kamiliff
|
2
|
-
|
3
2
|
Kamiliff make LIFF easy to use.
|
4
3
|
|
5
4
|
# Feature
|
@@ -8,7 +7,113 @@ Kamiliff make LIFF easy to use.
|
|
8
7
|
- liff_send_text_message: quick send message and close LIFF.
|
9
8
|
|
10
9
|
## Installation & Usage
|
10
|
+
### Create a new rails repository:
|
11
|
+
|
12
|
+
```bash
|
13
|
+
# create rails repository
|
14
|
+
rails new kamiliff_demo
|
15
|
+
# change directory
|
16
|
+
cd kamiliff_demo
|
17
|
+
# install gem
|
18
|
+
bundle add kamiliff
|
19
|
+
bundle add dotenv-rails
|
20
|
+
```
|
21
|
+
|
22
|
+
### Add LIFF Endpoint URL
|
23
|
+
Login to LINE Developers, and create 3 LIFF for 3 different size.
|
24
|
+
|
25
|
+
- For compact
|
26
|
+
- LIFF app name: Compact
|
27
|
+
- Size: Compact
|
28
|
+
- Endpoint URL: https://yourwebsite/liff_entry
|
29
|
+
|
30
|
+
- For tall
|
31
|
+
- LIFF app name: Tall
|
32
|
+
- Size: Tall
|
33
|
+
- Endpoint URL: https://yourwebsite/liff_entry
|
34
|
+
|
35
|
+
- For full
|
36
|
+
- LIFF app name: Full
|
37
|
+
- Size: Full
|
38
|
+
- Endpoint URL: https://yourwebsite/liff_entry
|
39
|
+
|
40
|
+
Since the compact size is default. You could only create the compact one.
|
41
|
+
|
42
|
+
**NOTICE:** As LINE announcement, due to a function enhancement with LIFF v2, you should add LIFF apps to LINE Login channel. The LIFF apps added to Messaging API channels are still allowed to use.
|
43
|
+
|
44
|
+
### Set environment variables
|
45
|
+
Create a file `.env` with the following content under the root directory. Kamiliff provides two setting ways, you can choose the one based on the position where LIFF apps added.
|
46
|
+
|
47
|
+
- LIFF apps added to Messaging API channel (v1)
|
48
|
+
```
|
49
|
+
LIFF_COMPACT=line://app/{FOR_COMPACT_LIFF_ID}
|
50
|
+
LIFF_TALL=line://app/{FOR_TALL_LIFF_ID}
|
51
|
+
LIFF_FULL=line://app/{FOR_FULL_LIFF_ID}
|
52
|
+
```
|
53
|
+
|
54
|
+
- LIFF apps added to LINE Login channel (v2)
|
55
|
+
```
|
56
|
+
LIFF_COMPACT=https://liff.line.me/{FOR_COMPACT_LIFF_ID}
|
57
|
+
LIFF_TALL=https://liff.line.me/{FOR_TALL_LIFF_ID}
|
58
|
+
LIFF_FULL=https://liff.line.me/{FOR_FULL_LIFF_ID}
|
59
|
+
```
|
60
|
+
|
61
|
+
You could choose another setting method.
|
62
|
+
|
63
|
+
### Generate simple todo resource
|
64
|
+
Create todo resource:
|
65
|
+
|
66
|
+
```bash
|
67
|
+
rails g scaffold todo name desc
|
68
|
+
rails db:migrate
|
69
|
+
```
|
70
|
+
|
71
|
+
### Create LIFF view
|
72
|
+
Create liff view for new action at `app/views/todos/new.liff.erb`.
|
73
|
+
|
74
|
+
```
|
75
|
+
<%= render "todos/form.html", todo: @todo %>
|
76
|
+
|
77
|
+
<script>
|
78
|
+
document.title = "new todo";
|
79
|
+
|
80
|
+
window.addEventListener("liff_submit", function(event){
|
81
|
+
var json = JSON.stringify(event.detail.data);
|
82
|
+
var url = event.detail.url;
|
83
|
+
var method = event.detail.method;
|
84
|
+
var request_text = method + " " + url + "\n" + json;
|
85
|
+
liff_send_text_message(request_text);
|
86
|
+
});
|
87
|
+
</script>
|
88
|
+
```
|
89
|
+
|
90
|
+
The javascript listen to submit button click, and build the message from form data, and send to current LINE chatroom, and then close the LIFF webview.
|
91
|
+
|
92
|
+
You could modify those javascript to change the format.
|
93
|
+
|
94
|
+
### Test LIFF view
|
95
|
+
Add following content into `app/views/todos/index.html.erb`.
|
96
|
+
|
97
|
+
```
|
98
|
+
<%= liff_path(path: new_todo_path) %>
|
99
|
+
```
|
100
|
+
|
101
|
+
Copy this url and paste to any LINE chatroom.
|
102
|
+
|
103
|
+
Click this url in LINE app.
|
104
|
+
|
105
|
+
The correct usage is put this url into Rich Manu or Flex Message or Template Message with url action.
|
106
|
+
|
107
|
+
### How to change LIFF size
|
108
|
+
You can change the size of LIFF by adding a parameter to the helper method, like this:
|
109
|
+
|
110
|
+
```
|
111
|
+
<%= liff_path(path: new_todo_path, liff_size: :compact) %>
|
112
|
+
<%= liff_path(path: new_todo_path, liff_size: :tall) %>
|
113
|
+
<%= liff_path(path: new_todo_path, liff_size: :full) %>
|
114
|
+
```
|
11
115
|
|
116
|
+
## Apps use Kamiliff
|
12
117
|
See my kamiliff demo: [https://github.com/etrex/kamiliff_demo](https://github.com/etrex/kamiliff_demo)
|
13
118
|
|
14
119
|
## Author
|
@@ -1,17 +1,18 @@
|
|
1
1
|
|
2
|
-
class LiffController <
|
2
|
+
class LiffController < ActionController::Base
|
3
3
|
layout false, only: :route
|
4
4
|
|
5
|
-
|
6
5
|
def entry
|
7
6
|
query = Rack::Utils.parse_nested_query(request.query_string)
|
8
7
|
|
9
|
-
# fix liff 2.0
|
10
|
-
|
11
|
-
|
8
|
+
# fix liff 2.0 redirect issue
|
9
|
+
@need_reload = query["liff.state"].present?
|
10
|
+
if(@need_reload)
|
11
|
+
querystring = query["liff.state"][(query["liff.state"].index('?')+1)..-1]
|
12
|
+
query = Rack::Utils.parse_nested_query(querystring)
|
12
13
|
end
|
13
14
|
|
14
|
-
@
|
15
|
+
@liff = LiffService.new(query)
|
15
16
|
end
|
16
17
|
|
17
18
|
def route
|
@@ -31,9 +32,12 @@ class LiffController < ApplicationController
|
|
31
32
|
# env = {Rack::RACK_INPUT => StringIO.new}
|
32
33
|
|
33
34
|
res = Rails.application.routes.router.serve(request)
|
35
|
+
# res[0]: http state code
|
36
|
+
# res[1]: headers
|
37
|
+
# res[2]: response
|
34
38
|
res[2].body
|
35
|
-
rescue
|
36
|
-
res
|
39
|
+
rescue NoMethodError => e
|
40
|
+
res&.to_s || e.full_message
|
37
41
|
end
|
38
42
|
|
39
43
|
def source_info
|
@@ -44,11 +48,14 @@ class LiffController < ApplicationController
|
|
44
48
|
source_group_id = context["roomId"] || context["groupId"] || context["userId"]
|
45
49
|
source_user_id = context["userId"]
|
46
50
|
|
51
|
+
profile = params["profile"]
|
52
|
+
|
47
53
|
{
|
48
54
|
platform_type: 'line',
|
49
55
|
source_type: source_type,
|
50
56
|
source_group_id: source_group_id,
|
51
57
|
source_user_id: source_user_id,
|
58
|
+
profile: profile
|
52
59
|
}
|
53
60
|
end
|
54
61
|
end
|
data/app/helpers/liff_helper.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
module LiffHelper
|
2
2
|
def liff_path(params)
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
liff = LiffService.new(params)
|
4
|
+
if ENV["LIFF_MODE"]&.downcase == "replace"
|
5
|
+
return "#{liff.url}/liff_entry?#{params.to_query}"
|
6
|
+
end
|
7
|
+
# liff mode is Concatenate
|
8
|
+
"#{liff.url}?#{params.to_query}"
|
8
9
|
end
|
9
10
|
end
|
@@ -5,14 +5,29 @@
|
|
5
5
|
<%= csrf_meta_tags %>
|
6
6
|
<%= csp_meta_tag %>
|
7
7
|
<meta name="viewport" content="width=device-width, initial-scale=1" >
|
8
|
-
<script src="https://
|
9
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
|
8
|
+
<script src="https://static.line-scdn.net/liff/edge/versions/2.5.0/sdk.js"></script>
|
10
9
|
|
11
|
-
|
12
|
-
|
10
|
+
<% asset_application_js_path = Dir.glob("#{Rails.root}/app/assets/javascripts/application.*").first %>
|
11
|
+
<% if asset_application_js_path.present? %>
|
12
|
+
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
|
13
|
+
<% end %>
|
14
|
+
|
15
|
+
<% webpacker_application_js_path = Dir.glob("#{Rails.root}/app/javascript/packs/application.*").first %>
|
16
|
+
<% if webpacker_application_js_path.present? %>
|
17
|
+
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
|
18
|
+
<% end %>
|
19
|
+
|
20
|
+
<% has_jquery = [asset_application_js_path, webpacker_application_js_path].compact.map do |path|
|
21
|
+
(File.read(path) =~ /jquery/i).present?
|
22
|
+
end.any? %>
|
13
23
|
|
24
|
+
<% unless has_jquery %>
|
25
|
+
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
|
26
|
+
<script> alert("has no jquery") </script>
|
27
|
+
<% end %>
|
28
|
+
|
29
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
|
14
30
|
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
15
|
-
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
16
31
|
<script>
|
17
32
|
function liff_send_text_message(text){
|
18
33
|
liff.sendMessages(
|
@@ -42,15 +42,29 @@
|
|
42
42
|
});
|
43
43
|
}
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
45
|
+
window.onload = function() {
|
46
|
+
liff.init({
|
47
|
+
liffId: "<%= @liff.id %>"
|
48
|
+
})
|
49
|
+
.then(() => {
|
50
|
+
if (!liff.isLoggedIn()) {
|
51
|
+
liff.login();
|
52
|
+
}else{
|
53
|
+
liff.getProfile().then(profile => {
|
54
|
+
const data = {};
|
55
|
+
data.context = liff.getContext();
|
56
|
+
data.profile = profile;
|
57
|
+
data.path = "<%= @liff.path %>";
|
58
|
+
<% if !@need_reload %>
|
59
|
+
route(data);
|
60
|
+
<% end %>
|
61
|
+
})
|
62
|
+
}
|
63
|
+
})
|
64
|
+
.catch((err) => {
|
65
|
+
console.log(err.code, err.message);
|
66
|
+
});
|
67
|
+
};
|
54
68
|
})();
|
55
69
|
</script>
|
56
70
|
<% end %>
|
data/lib/kamiliff.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
class LiffService
|
2
|
+
|
3
|
+
# rails routes path
|
4
|
+
attr_accessor :path
|
5
|
+
|
6
|
+
# size
|
7
|
+
# COMPACT TALL FULL
|
8
|
+
attr_accessor :size
|
9
|
+
|
10
|
+
# liff app url
|
11
|
+
# https://liff.line.me/app/#{liff_id}
|
12
|
+
attr_accessor :url
|
13
|
+
|
14
|
+
# liff id
|
15
|
+
attr_accessor :id
|
16
|
+
|
17
|
+
def initialize(options)
|
18
|
+
self.path = options[:path] || options['path'] || "/"
|
19
|
+
self.size = options[:liff_size] || options['liff_size'] || :compact
|
20
|
+
self.size = size.to_s.upcase
|
21
|
+
raise "liff_size should be compact, tall or full." unless size.in? %w[COMPACT TALL FULL]
|
22
|
+
self.url = ENV["LIFF_#{size}"]
|
23
|
+
raise "LIFF_#{size} should be in the env variables" if url.empty?
|
24
|
+
self.id = url[(url.rindex('/')+1)..-1]
|
25
|
+
end
|
26
|
+
end
|
data/lib/kamiliff/version.rb
CHANGED
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.
|
4
|
+
version: 0.19.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- etrex kuo
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -46,6 +46,7 @@ files:
|
|
46
46
|
- config/routes.rb
|
47
47
|
- lib/kamiliff.rb
|
48
48
|
- lib/kamiliff/engine.rb
|
49
|
+
- lib/kamiliff/services/liff_service.rb
|
49
50
|
- lib/kamiliff/version.rb
|
50
51
|
- lib/tasks/kamiliff_tasks.rake
|
51
52
|
homepage: https://github.com/etrex/kamiliff
|
@@ -53,7 +54,7 @@ licenses:
|
|
53
54
|
- MIT
|
54
55
|
metadata:
|
55
56
|
allowed_push_host: https://rubygems.org
|
56
|
-
post_install_message:
|
57
|
+
post_install_message:
|
57
58
|
rdoc_options: []
|
58
59
|
require_paths:
|
59
60
|
- lib
|
@@ -68,8 +69,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
69
|
- !ruby/object:Gem::Version
|
69
70
|
version: '0'
|
70
71
|
requirements: []
|
71
|
-
rubygems_version: 3.
|
72
|
-
signing_key:
|
72
|
+
rubygems_version: 3.1.2
|
73
|
+
signing_key:
|
73
74
|
specification_version: 4
|
74
75
|
summary: An easy way to use LINE Front-end Framework(LIFF) on rails.
|
75
76
|
test_files: []
|