kamiliff 0.23.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: d8d9f1e36c1dc706651145146649792d8f128784824c476d688e1b7c42b0e6ba
4
- data.tar.gz: 2bc4437b67d94a0bb39456d470a615d63363aadf43bb1fbf6301659fc80e982e
3
+ metadata.gz: 3189c0303b55fd1e7d8ed2cc55f613544f8bdd9db48f34cf526baec151044afe
4
+ data.tar.gz: 5204d91c73e59aec7386a07f1f25d7ef4f1a5b6d9f5eb81d032faf91ac0e94cb
5
5
  SHA512:
6
- metadata.gz: 7debaefba5c60a6327e74db069680dbcd4462a42c1ad31a10ea28456651302032e7c6c4c8a9a625509ee095731a8292f6e6424a63b629065483e769215607d71
7
- data.tar.gz: ce34f047195fe836f37f3da058902aef6218448efacc0c0bf5e1d11235e9b0e6d57a3d16d02ba95f462e51af1c83d782a9240411cae49eea95863a881ada2172
6
+ metadata.gz: ba41019d9be741d925eacf2451a16e3d4486a7404f2a2ed696eaed173b4f99f32bf235d4360331213113ba4a84a8de4ebccd7e98847d7f0673b302313c67bd2a
7
+ data.tar.gz: 226c181fd2fb67213dd105c984a1d251ccf58a3eb33645f2b0bdda5092c280810d91c9e09cd8e51dcb310f547d9cd48c2dc957a5471e152673334857abe81a6d
@@ -8,11 +8,18 @@ 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
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Kamiliff
2
- VERSION = '0.23.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.23.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-12-28 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