kamiliff 0.14.0 → 0.15.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: 3933c1a48a8b3bb9e4183e265af686ad270789d6012f927d19c54fa4be23f834
4
- data.tar.gz: 53418c89721917f2cdc97eb43436edf6be8cf4128298c97b55397d78c1df69ce
3
+ metadata.gz: 8e1a6426cb9312e84ac551da647721c6a63c4def94bbda616618e219a1bf5b61
4
+ data.tar.gz: 1290e1aa4a8fba4c814836992b1271cc722fbc4017298584971d7eb72f7ab565
5
5
  SHA512:
6
- metadata.gz: 3939f22ba9d727197e37c8e579791bc515f519dca6b206579965264d463108682768b4336da6c9ec2ec46b5c7f6b97899c28fe96dce5a00cb49768275973ce76
7
- data.tar.gz: af3c5a49dc6445f6278394ae8db02cb9dc0abe5541383ed91f538af9a284875809fac6a0e05d68510ae3869715ae00f088693b0a79bc8d6337028160994f5a26
6
+ metadata.gz: c1dae23952d71fc92ce40301baf1d8a4b1b40681c3545333d2f024aec282466730c0b762181dbb9bb57c28034ecf0682e19791f5a00bb37705daa98a2e1f0a0a
7
+ data.tar.gz: 570d689c3734d11b6adc4ddc67323f0e190fc710be3c2cba95029351e776da307c7bcd1a1dc14eeb6802db75ef8e8e35b56ef997491b8c8f017d1fa6358c8e62
@@ -2,16 +2,17 @@
2
2
  class LiffController < ApplicationController
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 path issue
10
- if query["liff.state"].present?
11
- query = Rack::Utils.parse_nested_query(query["liff.state"][1..-1])
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
- @path = query["path"]
15
+ @liff = LiffService.new(query)
15
16
  end
16
17
 
17
18
  def route
@@ -32,7 +33,7 @@ class LiffController < ApplicationController
32
33
 
33
34
  res = Rails.application.routes.router.serve(request)
34
35
  res[2].body
35
- rescue
36
+ rescue Exception => e
36
37
  res[2].to_s
37
38
  end
38
39
 
@@ -1,9 +1,6 @@
1
1
  module LiffHelper
2
2
  def liff_path(params)
3
- liff_size = params[:liff_size] || :compact
4
- liff_size = liff_size.to_s.upcase
5
- raise "liff_size should be compact, tall or full." unless liff_size.in? %w[COMPACT TALL FULL]
6
- liff_url = ENV["LIFF_#{liff_size}"]
7
- "#{liff_url}?#{params.to_query}"
3
+ liff = LiffService.new(params)
4
+ "#{liff.url}/liff_entry?#{params.to_query}"
8
5
  end
9
6
  end
@@ -5,7 +5,7 @@
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://d.line-scdn.net/liff/1.0/sdk.js"></script>
8
+ <script src="https://static.line-scdn.net/liff/edge/2.1/sdk.js"></script>
9
9
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
10
10
 
11
11
  <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
@@ -42,15 +42,24 @@
42
42
  });
43
43
  }
44
44
 
45
- liff.init(
46
- data => {
47
- data.path = '<%= @path %>';
48
- route(data);
49
- },
50
- err => {
51
- alert("Please open this url in Line.");
45
+ liff.init({
46
+ liffId: "<%= @liff.id %>"
47
+ })
48
+ .then(() => {
49
+ if (!liff.isLoggedIn()) {
50
+ liff.login();
51
+ }else{
52
+ const data = {};
53
+ data.context = liff.getContext();
54
+ data.path = "<%= @liff.path %>";
55
+ <% if !@need_reload %>
56
+ route(data);
57
+ <% end %>
52
58
  }
53
- );
59
+ })
60
+ .catch((err) => {
61
+ console.log(err.code, err.message);
62
+ });
54
63
  })();
55
64
  </script>
56
65
  <% end %>
@@ -1,4 +1,5 @@
1
1
  require "kamiliff/engine"
2
+ require "kamiliff/services/liff_service"
2
3
 
3
4
  module Kamiliff
4
5
  # Your code goes here...
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Kamiliff
2
- VERSION = '0.14.0'
2
+ VERSION = '0.15.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.14.0
4
+ version: 0.15.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-04-02 00:00:00.000000000 Z
11
+ date: 2020-04-03 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