kamigo 0.6.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21366e85d6e20718c8c7ebc6eac94740928de80dc1e0a5dd5acbd6b722a57087
4
- data.tar.gz: 3cac9c2fec9298a9bf6cf697d319c62b7054c2303e3a0bf11c420aa0e2130b6c
3
+ metadata.gz: da82bc8564ff3625ed8387a352a0dc7a4920453874b66c21ab5d8b901f0bbba9
4
+ data.tar.gz: 0440adead99e55dbc0bbe23372273f232cef39ddc42f1b43f15a5b38034272a9
5
5
  SHA512:
6
- metadata.gz: 36dd211fd0a0ae7c33f614cd3b80142961e0b486578336efc895b5351465de133276335f0fc95eaee9490403ae492347e6af17ad26815d9ad95bb8350ba1cf72
7
- data.tar.gz: af2d392ab4ba07e7562964b83d4fed92e5c4b08994125ab487e930d99637ee16358689e027598e915fc17d50e26aca0f68ac84c652ef5024d51b5a070d3c6783
6
+ metadata.gz: d9fca66790101ba9b43e428bbcf5456bf270cdfd0d387b3e305a563444b8d42c168c2cf274151a0d026a7e7a7d0f1579c0e885d510b43827698da6731ccaff86
7
+ data.tar.gz: 7cba36eb5754912417c7265063eebcdd11483c7d87455c942933dcc1788d4611535fea3b9962705b14a6acde1f3b4142b6efb96847255e86e40c6ca6e4ab9e72
@@ -0,0 +1,30 @@
1
+ require 'uri'
2
+
3
+ class KamigoController < ApplicationController
4
+ def kamiform(http_method, path, resource)
5
+ error_message = "please generate model Kamiform by the following command:\n\nrails g model kamiform platform_type source_group_id http_method path params:jsonb field\nrails db:migrate\n\n"
6
+ begin
7
+ Kamiform
8
+ rescue StandardError
9
+ raise error_message
10
+ end
11
+
12
+ return nil if resource.errors.empty?
13
+
14
+ error = resource.errors.first
15
+
16
+ Kamiform.create(
17
+ platform_type: params[:platform_type],
18
+ source_group_id: params[:source_group_id],
19
+ http_method: http_method,
20
+ path: path,
21
+ params: params,
22
+ field: "#{resource.class.to_s.downcase}.#{error[0]}"
23
+ )
24
+
25
+ {
26
+ type: 'text',
27
+ text: error[1]
28
+ }
29
+ end
30
+ end
@@ -16,7 +16,8 @@ class LineController < ApplicationController
16
16
  private
17
17
 
18
18
  def process_event(event)
19
- http_method, path, request_params = language_understanding(event.message)
19
+ http_method, path, request_params = slot_filling(event)
20
+ http_method, path, request_params = language_understanding(event.message) if http_method.nil?
20
21
  encoded_path = URI.encode(path)
21
22
  request_params = event.platform_params.merge(request_params)
22
23
  output = reserve_route(encoded_path, http_method: http_method, request_params: request_params, format: :line)
@@ -32,6 +33,33 @@ class LineController < ApplicationController
32
33
  })
33
34
  end
34
35
 
36
+ def slot_filling(event)
37
+ begin
38
+ Kamiform
39
+ rescue StandardError
40
+ return [nil, nil, nil]
41
+ end
42
+ form = Kamiform.find_by(
43
+ platform_type: event.platform_type,
44
+ source_group_id: event.source_group_id
45
+ )
46
+ return [nil, nil, nil] if form.nil?
47
+
48
+ http_method = form.http_method
49
+ path = form.path
50
+ request_params = form.params
51
+
52
+ # fill
53
+ if form.field['.'].nil?
54
+ request_params[form.field] = event.message
55
+ else
56
+ *head, tail = form.field.split('.')
57
+ request_params.dig(*head)[tail] = event.message
58
+ end
59
+ form.destroy
60
+ [http_method.upcase, path, request_params]
61
+ end
62
+
35
63
  def language_understanding(text)
36
64
  http_method = %w[GET POST PUT PATCH DELETE].find do |http_method|
37
65
  text.start_with? http_method
@@ -0,0 +1,56 @@
1
+ require 'rails/generators/named_base'
2
+ require 'rails/generators/resource_helpers'
3
+
4
+ module Rails
5
+ module Generators
6
+ class CreateStateGenerator < NamedBase
7
+ include Rails::Generators::ResourceHelpers
8
+ namespace "devise"
9
+ argument :attributes, type: :string, default: 'kamigo_state'
10
+
11
+ class_option :timestamps, type: :boolean, default: true
12
+
13
+ def create_root_folder
14
+ path = File.join('app/views', controller_file_path)
15
+ empty_directory path unless File.directory?(path)
16
+ end
17
+
18
+ def copy_view_files
19
+ filenames.each do |filename|
20
+ template filename, File.join('app/views', controller_file_path, filename)
21
+ end
22
+ end
23
+
24
+ protected
25
+
26
+ def attributes_names
27
+ [:id] + super
28
+ end
29
+
30
+ def filenames
31
+ [
32
+ "index.line.erb",
33
+ "show.line.erb",
34
+ "edit.liff.erb",
35
+ "new.liff.erb",
36
+ ]
37
+ end
38
+
39
+ def full_attributes_list
40
+ if options[:timestamps]
41
+ attributes_list(attributes_names + %w(created_at updated_at))
42
+ else
43
+ attributes_list(attributes_names)
44
+ end
45
+ end
46
+
47
+ def attributes_list(attributes = attributes_names)
48
+ if self.attributes.any? {|attr| attr.name == 'password' && attr.type == :digest}
49
+ attributes = attributes.reject {|name| %w(password password_confirmation).include? name}
50
+ end
51
+
52
+ attributes.map { |a| ":#{a}"} * ', '
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,3 +1,3 @@
1
1
  module Kamigo
2
- VERSION = '0.6.0'
2
+ VERSION = '0.7.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kamigo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - etrex
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-27 00:00:00.000000000 Z
11
+ date: 2020-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.12.0
33
+ version: 0.13.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.12.0
40
+ version: 0.13.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: kamiflex
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -92,10 +92,12 @@ files:
92
92
  - Rakefile
93
93
  - app/assets/config/kamigo_manifest.js
94
94
  - app/controllers/concerns/reverse_route.rb
95
+ - app/controllers/kamigo_controller.rb
95
96
  - app/controllers/line_controller.rb
96
97
  - config/routes.rb
97
98
  - lib/generators/rails/kamigo/USAGE
98
99
  - lib/generators/rails/kamigo/kamigo_generator.rb
100
+ - lib/generators/rails/kamigo/state_generator.rb
99
101
  - lib/generators/rails/kamigo/templates/edit.liff.erb
100
102
  - lib/generators/rails/kamigo/templates/index.line.erb
101
103
  - lib/generators/rails/kamigo/templates/new.liff.erb