kamiliff 0.7.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 74fdcb1aa9887f7a0768791b79eecafd7ca36f7c9b51f24a4fb8a20912d5910a
4
+ data.tar.gz: cb374760f4d192b552e84fdfb96d9af1802276400586ac1c7bcd0a93017eb6e8
5
+ SHA512:
6
+ metadata.gz: 1f1bf7aa4af19d5d40d5906f211e6666ae56e67ef52b8c23d5eb40ee9776edf0b247601c35a45a9a36ad56e4d4dda0f1f308b4878188f159257ed4a093efac65
7
+ data.tar.gz: 5f8228f4c684d8c11d884c1a312d80d3c64a3d8baa1db2c04d94e61d3f203c73dbc21eb801564c44c6eba7361cd8d00be2fa2d60c8293003ed76cd1dd4a01fc9
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2019 etrex kuo
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # Kamiliff
2
+
3
+ Kamiliff make LIFF easy to use.
4
+
5
+ # Feature
6
+ - register LIFF once and reuse to your all path.
7
+ - liff_submit event: a hook when LIFF form submit, with form data in js object format.
8
+ - liff_send_text_message: quick send message and close LIFF.
9
+
10
+ ## Installation
11
+
12
+ ```ruby
13
+ gem 'kamiliff'
14
+ ```
15
+
16
+ login to line developers, and create 3 LIFF for 3 different size.
17
+
18
+ - for compact
19
+ - name: Compact
20
+ - size: Compact
21
+ - Endpoint URL: https://yourwebsite/liff
22
+
23
+ - for tall
24
+ - name: Tall
25
+ - size: Tall
26
+ - Endpoint URL: https://yourwebsite/liff
27
+
28
+ - for full
29
+ - name: Full
30
+ - size: Full
31
+ - Endpoint URL: https://yourwebsite/liff
32
+
33
+ and then copy the result to enviroment parameters:
34
+
35
+ ```
36
+ LIFF_COMPACT=line://app/for_compact_liff_id
37
+ LIFF_TALL=line://app/for_tall_liff_id
38
+ LIFF_FULL=line://app/for_full_liff_id
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ ### Implement LIFF View
44
+
45
+ Kamiliff using view format `.liff`, so you can reuse exists controller and model, you can create a LIFF form by only adding a new view file.
46
+
47
+ Suppose you have a resource `todos`, you want to create a liff form for `todos/new`, so you create a file `app/views/todos/new.liff.erb`, the content is as follows:
48
+
49
+ ```
50
+ <% content_for :title, "new todo" %>
51
+
52
+ <%= render "todos/form.html", todo: @todo %>
53
+
54
+ <%= link_to "test", liff_path(path: '/todos/new') %>
55
+ ```
56
+
57
+ You can test the form at [localhost:3000/todos/new.liff](localhost:3000/todos/new.liff)
58
+
59
+ ### Generate LIFF Link
60
+
61
+ You can change any path to liff by `liff_path` method.
62
+
63
+ for example:
64
+
65
+ ```
66
+ liff_path(path: '/todos/new')
67
+ ```
68
+
69
+ You can choice the liff size by `liff_size` parameter. the default value of liff_size is compact.
70
+
71
+ ```
72
+ liff_path(path: '/todos/new', liff_size: :compact)
73
+ liff_path(path: '/todos/new', liff_size: :tall)
74
+ liff_path(path: '/todos/new', liff_size: :full)
75
+ ```
76
+
77
+ liff_path method add format :liff automatically.
78
+
79
+ ## Author
80
+ create by [etrex](https://etrex.tw)
81
+
82
+ ## License
83
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Kamiliff'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+ task default: :test
@@ -0,0 +1,57 @@
1
+ function liff_send_text_message(text){
2
+ liff.sendMessages(
3
+ [
4
+ {
5
+ type: 'text',
6
+ text: text
7
+ }
8
+ ]
9
+ ).then(() => {
10
+ liff.closeWindow();
11
+ })
12
+ .catch((err) => {
13
+ alert('error', err);
14
+ });
15
+ }
16
+
17
+ $(function(){
18
+ function dispatch_liff_event(data){
19
+ var event = new CustomEvent('liff_submit', { 'detail': data });
20
+ window.dispatchEvent(event);
21
+ }
22
+ $('input[type="submit"]').click(function(e){
23
+ e.preventDefault();
24
+ dispatch_liff_event(get_request_text($("form")));
25
+ })
26
+
27
+ function get_request_text(form_element){
28
+ var data = get_form_data(form_element);
29
+ var method = form_element.attr("method").toUpperCase();
30
+ var url = form_element.attr("action");
31
+ return {
32
+ data: data,
33
+ method: method,
34
+ url: url
35
+ }
36
+ }
37
+
38
+ function get_form_data(form_element){
39
+ var excpet = ["utf8","authenticity_token"];
40
+ var form = form_element.serializeArray();
41
+ form = form.filter((a)=>{ return !excpet.includes(a.name) })
42
+ var data = {}
43
+ form.forEach((a)=>{ set_object_value(data, a.name, a.value) })
44
+ return data;
45
+ }
46
+
47
+ function set_object_value(object, path, value){
48
+ var o = object;
49
+ var p = path.replace(/(\]\[)/g, "[").replace(/]$/g, "").split("[")
50
+ var last_key = p.pop();
51
+ p.forEach((key)=>{
52
+ o[key] = o[key] || {}
53
+ o = o[key]
54
+ })
55
+ o[last_key] = value;
56
+ }
57
+ });
@@ -0,0 +1,26 @@
1
+
2
+ class LiffController < ApplicationController
3
+ layout false
4
+
5
+ def entry
6
+ query = Rack::Utils.parse_nested_query(request.query_string)
7
+ @body = reserve_route(query["path"], format: :liff)
8
+ end
9
+
10
+ private
11
+
12
+ def reserve_route(path, http_method: "GET", request_params: nil, format: nil)
13
+ request.request_method = http_method
14
+ request.path_info = path
15
+ request.format = format if format.present?
16
+ request.request_parameters = request_params if request_params.present?
17
+
18
+ # req = Rack::Request.new
19
+ # env = {Rack::RACK_INPUT => StringIO.new}
20
+
21
+ res = Rails.application.routes.router.serve(request)
22
+ res[2].body
23
+ rescue
24
+ res[2].to_s
25
+ end
26
+ end
@@ -0,0 +1,9 @@
1
+ module LiffHelper
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}"
8
+ end
9
+ end
@@ -0,0 +1,24 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= yield(:title) || "Todo" %></title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+ <meta name="viewport" content="width=device-width, initial-scale=1" >
8
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
9
+ <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
10
+
11
+ <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">
12
+ <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
13
+
14
+ <script src="https://d.line-scdn.net/liff/1.0/sdk.js"></script>
15
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
16
+ <%= javascript_include_tag 'kamiliff', 'data-turbolinks-track': 'reload' %>
17
+ </head>
18
+
19
+ <body>
20
+ <div class="container-fluid">
21
+ <%= yield %>
22
+ </div>
23
+ </body>
24
+ </html>
@@ -0,0 +1 @@
1
+ <%= raw @body %>
@@ -0,0 +1 @@
1
+ Rails.application.config.assets.precompile << "kamiliff.js"
@@ -0,0 +1,6 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+
6
+ Mime::Type.register "text/html", :liff
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ Rails.application.routes.draw do
2
+ # liff
3
+ get 'liff', to: 'liff#entry'
4
+ end
@@ -0,0 +1,4 @@
1
+ module Kamiliff
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Kamiliff
2
+ VERSION = '0.7.0'
3
+ end
data/lib/kamiliff.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "kamiliff/engine"
2
+
3
+ module Kamiliff
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :kamiliff do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kamiliff
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.0
5
+ platform: ruby
6
+ authors:
7
+ - etrex kuo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.2.2
27
+ description: An easy way to use LINE Front-end Framework(LIFF) on rails.
28
+ email:
29
+ - et284vu065k3@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - app/assets/javascripts/kamiliff.js
38
+ - app/controllers/liff_controller.rb
39
+ - app/helpers/liff_helper.rb
40
+ - app/views/layouts/application.liff.erb
41
+ - app/views/liff/entry.html.erb
42
+ - config/initializers/assets.rb
43
+ - config/initializers/mime_types.rb
44
+ - config/routes.rb
45
+ - lib/kamiliff.rb
46
+ - lib/kamiliff/engine.rb
47
+ - lib/kamiliff/version.rb
48
+ - lib/tasks/kamiliff_tasks.rake
49
+ homepage: https://github.com/etrex/kamiliff
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ allowed_push_host: https://rubygems.org
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.0.3
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: An easy way to use LINE Front-end Framework(LIFF) on rails.
73
+ test_files: []