kamiliff 0.19.0 → 0.24.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: 498ccd4075fc6cdf241d6ec11ecc943a1d5a18799677baf5a4b665585eca0658
4
- data.tar.gz: ce48f53be68d877bb2efacc71eb264e8d6d74a499287bd9b1ba478bc10e12ea9
3
+ metadata.gz: 3189c0303b55fd1e7d8ed2cc55f613544f8bdd9db48f34cf526baec151044afe
4
+ data.tar.gz: 5204d91c73e59aec7386a07f1f25d7ef4f1a5b6d9f5eb81d032faf91ac0e94cb
5
5
  SHA512:
6
- metadata.gz: ecd86a4de7d7e18be3a9ba5049ab36bdee3ebfa246ce07225a632d6739d86758dd71dc4e6aaa072110d750653029adc341e1c1bec06450e4c12eef0c14f7975e
7
- data.tar.gz: 1538d204048373fa00fc63e9f8046039b2e8312ad48525d6505d3155fa381871339ad76d61c43dfe1088e06201c121e4cd15e38ec33491aaea0f56a814b98566
6
+ metadata.gz: ba41019d9be741d925eacf2451a16e3d4486a7404f2a2ed696eaed173b4f99f32bf235d4360331213113ba4a84a8de4ebccd7e98847d7f0673b302313c67bd2a
7
+ data.tar.gz: 226c181fd2fb67213dd105c984a1d251ccf58a3eb33645f2b0bdda5092c280810d91c9e09cd8e51dcb310f547d9cd48c2dc957a5471e152673334857abe81a6d
data/README.md CHANGED
@@ -41,6 +41,8 @@ Since the compact size is default. You could only create the compact one.
41
41
 
42
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
43
 
44
+ For the [Behaviors from accessing the LIFF URL to opening the LIFF app](https://developers.line.biz/en/docs/liff/opening-liff-app/#redirect-flow) setting, please use the Concatenate mode. That's the default value in the Kamiliff. If you want to use the Replace mode([will be removed on March 1, 2021](https://developers.line.biz/en/news/2020/11/20/discontinue-replace-mode-announcement/)), you can add an enviroment variable `LIFF_MODE` and set the value to `replace`.
45
+
44
46
  ### Set environment variables
45
47
  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
48
 
@@ -8,16 +8,24 @@ class LiffController < ActionController::Base
8
8
  # fix liff 2.0 redirect issue
9
9
  @need_reload = query["liff.state"].present?
10
10
  if(@need_reload)
11
- querystring = query["liff.state"][(query["liff.state"].index('?')+1)..-1]
12
- query = Rack::Utils.parse_nested_query(querystring)
11
+ if query["liff.state"].index('?').present?
12
+ querystring = query["liff.state"][(query["liff.state"].index('?')+1)..-1]
13
+ query = Rack::Utils.parse_nested_query(querystring)
14
+ end
13
15
  end
14
16
 
15
- @liff = LiffService.new(query)
17
+ # try base64 decode
18
+ if params[:base64].present?
19
+ @liff = LiffBase64Service.from_base64(params[:base64])
20
+ else
21
+ @liff = LiffService.new(query)
22
+ end
16
23
  end
17
24
 
18
25
  def route
19
- path = params["path"]
20
- @body = reserve_route(path, request_params: source_info, format: :liff)
26
+ path, query = params["path"].split("?")
27
+ query = Rack::Utils.parse_nested_query(query)
28
+ @body = reserve_route(path, request_params: source_info.merge(query), format: :liff)
21
29
  end
22
30
 
23
31
  private
@@ -1,5 +1,5 @@
1
1
  module LiffHelper
2
- def liff_path(params)
2
+ def old_liff_path(params)
3
3
  liff = LiffService.new(params)
4
4
  if ENV["LIFF_MODE"]&.downcase == "replace"
5
5
  return "#{liff.url}/liff_entry?#{params.to_query}"
@@ -7,4 +7,9 @@ module LiffHelper
7
7
  # liff mode is Concatenate
8
8
  "#{liff.url}?#{params.to_query}"
9
9
  end
10
+
11
+ def liff_path(params)
12
+ liff = LiffBase64Service.new(params)
13
+ liff.full_url
14
+ end
10
15
  end
@@ -23,7 +23,6 @@
23
23
 
24
24
  <% unless has_jquery %>
25
25
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
26
- <script> alert("has no jquery") </script>
27
26
  <% end %>
28
27
 
29
28
  <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
@@ -1,5 +1,6 @@
1
1
  Rails.application.routes.draw do
2
2
  # liff
3
+ get 'liff_entry/:base64', to: 'liff#entry'
3
4
  get 'liff_entry', to: 'liff#entry'
4
5
  post 'liff_route', to: 'liff#route'
5
6
  end
@@ -1,5 +1,6 @@
1
1
  require "kamiliff/engine"
2
2
  require "kamiliff/services/liff_service"
3
+ require "kamiliff/services/liff_base64_service"
3
4
 
4
5
  module Kamiliff
5
6
  # Your code goes here...
@@ -0,0 +1,52 @@
1
+ require "base64"
2
+
3
+ class LiffBase64Service
4
+
5
+ # rails routes path
6
+ attr_accessor :path
7
+
8
+ # size
9
+ # COMPACT TALL FULL
10
+ attr_accessor :size
11
+
12
+ # liff app url
13
+ # https://liff.line.me/app/#{liff_id}
14
+ attr_accessor :url
15
+
16
+ # liff id
17
+ attr_accessor :id
18
+
19
+ def self.from_base64(base64_string)
20
+ base64_string = base64_string.tr('-','+').tr('_','/')
21
+ json = Base64.decode64(base64_string)
22
+ options = JSON.parse(json)
23
+ LiffBase64Service.new(options)
24
+ end
25
+
26
+ def to_base64
27
+ json = {
28
+ path: path,
29
+ size: size
30
+ }.to_json
31
+ base64_string = Base64.encode64(json)
32
+ base64_string.tr('+','-').tr('/','_')[0..-4]
33
+ end
34
+
35
+ def initialize(options)
36
+ options = options.with_indifferent_access
37
+ self.path = options[:path] || "/"
38
+ self.size = options[:liff_size] || :compact
39
+ self.size = size.to_s.upcase
40
+ raise "liff_size should be compact, tall or full." unless size.in? %w[COMPACT TALL FULL]
41
+ self.url = ENV["LIFF_#{size}"]
42
+ raise "LIFF_#{size} should be in the env variables" if url.blank?
43
+ self.id = url[(url.rindex('/')+1)..-1]
44
+ end
45
+
46
+ def full_url
47
+ if ENV["LIFF_MODE"]&.downcase == "replace"
48
+ end
49
+ # liff mode is Concatenate
50
+ "#{url}/#{to_base64}"
51
+ end
52
+ end
@@ -20,7 +20,7 @@ class LiffService
20
20
  self.size = size.to_s.upcase
21
21
  raise "liff_size should be compact, tall or full." unless size.in? %w[COMPACT TALL FULL]
22
22
  self.url = ENV["LIFF_#{size}"]
23
- raise "LIFF_#{size} should be in the env variables" if url.empty?
23
+ raise "LIFF_#{size} should be in the env variables" if url.blank?
24
24
  self.id = url[(url.rindex('/')+1)..-1]
25
25
  end
26
26
  end
@@ -1,3 +1,3 @@
1
1
  module Kamiliff
2
- VERSION = '0.19.0'
2
+ VERSION = '0.24.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.19.0
4
+ version: 0.24.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: 2020-11-22 00:00:00.000000000 Z
11
+ date: 2021-01-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_base64_service.rb
49
50
  - lib/kamiliff/services/liff_service.rb
50
51
  - lib/kamiliff/version.rb
51
52
  - lib/tasks/kamiliff_tasks.rake