Class: LiffBase64Service
- Inherits:
-
Object
- Object
- LiffBase64Service
- Defined in:
- lib/kamiliff/services/liff_base64_service.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
liff id.
-
#path ⇒ Object
rails routes path.
-
#size ⇒ Object
size COMPACT TALL FULL.
-
#url ⇒ Object
liff app url liff.line.me/app/#liff_id.
Class Method Summary collapse
Instance Method Summary collapse
- #full_url ⇒ Object
-
#initialize(options) ⇒ LiffBase64Service
constructor
A new instance of LiffBase64Service.
- #to_base64 ⇒ Object
Constructor Details
#initialize(options) ⇒ LiffBase64Service
Returns a new instance of LiffBase64Service.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/kamiliff/services/liff_base64_service.rb', line 35 def initialize() = .with_indifferent_access self.path = [:path] || "/" self.size = [:liff_size] || :compact self.size = size.to_s.upcase raise "liff_size should be compact, tall or full." unless size.in? %w[COMPACT TALL FULL] self.url = ENV["LIFF_#{size}"] raise "LIFF_#{size} should be in the env variables" if url.blank? self.id = url[(url.rindex('/')+1)..-1] end |
Instance Attribute Details
#id ⇒ Object
liff id
17 18 19 |
# File 'lib/kamiliff/services/liff_base64_service.rb', line 17 def id @id end |
#path ⇒ Object
rails routes path
6 7 8 |
# File 'lib/kamiliff/services/liff_base64_service.rb', line 6 def path @path end |
#size ⇒ Object
size COMPACT TALL FULL
10 11 12 |
# File 'lib/kamiliff/services/liff_base64_service.rb', line 10 def size @size end |
#url ⇒ Object
liff app url liff.line.me/app/#liff_id
14 15 16 |
# File 'lib/kamiliff/services/liff_base64_service.rb', line 14 def url @url end |
Class Method Details
.from_base64(base64_string) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/kamiliff/services/liff_base64_service.rb', line 19 def self.from_base64(base64_string) base64_string = base64_string.tr('-','+').tr('_','/') json = Base64.decode64(base64_string) = JSON.parse(json) LiffBase64Service.new() end |
Instance Method Details
#full_url ⇒ Object
46 47 48 49 50 51 |
# File 'lib/kamiliff/services/liff_base64_service.rb', line 46 def full_url if ENV["LIFF_MODE"]&.downcase == "replace" end # liff mode is Concatenate "#{url}/#{to_base64}" end |
#to_base64 ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/kamiliff/services/liff_base64_service.rb', line 26 def to_base64 json = { path: path, size: size }.to_json base64_string = Base64.encode64(json) base64_string.tr('+','-').tr('/','_')[0..-4] end |