kamiflex 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kamiflex/actions.rb +22 -0
- data/lib/kamiflex/basic_elements.rb +61 -0
- data/lib/kamiflex/core.rb +78 -0
- data/lib/kamiflex/quick_reply.rb +42 -0
- data/lib/kamiflex/version.rb +1 -1
- data/lib/kamiflex.rb +10 -159
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02abb717a3c9bf92e88f986bd17fe1ef469fa5c48d498ad7548ef784d01744ac
|
4
|
+
data.tar.gz: c6cf2e666d479328551e19139c34f2362c9d53fe38cbca903c9fb57f3c7b58d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52394c972f2ca4d08f3b0f67375cdeb1012f5a11a74c435e290494adbc08e37e70661d0f1318a9e971af059df88ea33c18e7be68818c58066243e4d4b3224397
|
7
|
+
data.tar.gz: df49a613f94f1d35890cc9fe51d5cb9c6d33b057457c7807a2018ee4a3487b33b2f9d6a366f1a416ad4f6805c2ed247c12c1e32bcb6f7a4c1dafb64287440a1b
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Kamiflex
|
2
|
+
module Actions
|
3
|
+
def message_action(label, **params)
|
4
|
+
{
|
5
|
+
type: "message",
|
6
|
+
label: label,
|
7
|
+
text: label
|
8
|
+
}.merge(params)
|
9
|
+
end
|
10
|
+
|
11
|
+
def uri_action(uri, **params)
|
12
|
+
{
|
13
|
+
type: "uri",
|
14
|
+
label: uri[0...40],
|
15
|
+
uri: uri,
|
16
|
+
# altUri: {
|
17
|
+
# desktop: uri
|
18
|
+
# }
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Kamiflex
|
2
|
+
module BasicElements
|
3
|
+
def text(message, **params)
|
4
|
+
@flex_contents << {
|
5
|
+
"type": "text",
|
6
|
+
"text": message
|
7
|
+
}.merge(params)
|
8
|
+
end
|
9
|
+
|
10
|
+
def image(url, **params)
|
11
|
+
@flex_contents << {
|
12
|
+
"type": "image",
|
13
|
+
"url": url
|
14
|
+
}.merge(params)
|
15
|
+
end
|
16
|
+
|
17
|
+
def icon(url, **params)
|
18
|
+
@flex_contents << {
|
19
|
+
"type": "image",
|
20
|
+
"url": url
|
21
|
+
}.merge(params)
|
22
|
+
end
|
23
|
+
|
24
|
+
def separator(**params)
|
25
|
+
@flex_contents << {
|
26
|
+
"type": "separator",
|
27
|
+
"margin": "md",
|
28
|
+
"color": "#000000",
|
29
|
+
}.merge(params)
|
30
|
+
end
|
31
|
+
|
32
|
+
def spacer(**params)
|
33
|
+
@flex_contents << {
|
34
|
+
"type": "spacer",
|
35
|
+
"size": "md",
|
36
|
+
}.merge(params)
|
37
|
+
end
|
38
|
+
|
39
|
+
def url_button(label, url, **params)
|
40
|
+
@flex_contents << {
|
41
|
+
"type": "button",
|
42
|
+
"action": {
|
43
|
+
"type": "uri",
|
44
|
+
"label": label,
|
45
|
+
"uri": url
|
46
|
+
}
|
47
|
+
}.merge(params)
|
48
|
+
end
|
49
|
+
|
50
|
+
def message_button(label, message, **params)
|
51
|
+
@flex_contents << {
|
52
|
+
"type": "button",
|
53
|
+
"action": {
|
54
|
+
"type": "message",
|
55
|
+
"label": label,
|
56
|
+
"text": message
|
57
|
+
}
|
58
|
+
}.merge(params)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Kamiflex
|
2
|
+
module Core
|
3
|
+
def bubble
|
4
|
+
attributes, _contents = flex_scope{ yield }
|
5
|
+
{
|
6
|
+
type: "flex",
|
7
|
+
altText: "this is a flex message",
|
8
|
+
contents: {
|
9
|
+
type: "bubble"
|
10
|
+
}.merge(attributes.slice(:header, :hero, :body, :footer, :style))
|
11
|
+
}.merge(attributes.slice(:quickReply))
|
12
|
+
end
|
13
|
+
|
14
|
+
# bubble attributes
|
15
|
+
def header(**params)
|
16
|
+
_attributes, contents = flex_scope{ yield }
|
17
|
+
@flex_attributes[:header] = {
|
18
|
+
type: "box",
|
19
|
+
layout: "vertical",
|
20
|
+
contents: contents
|
21
|
+
}.merge(params)
|
22
|
+
end
|
23
|
+
|
24
|
+
def hero(image_url, **params)
|
25
|
+
_attributes, _contents = flex_scope{ yield }
|
26
|
+
@flex_attributes[:hero] = {}
|
27
|
+
end
|
28
|
+
|
29
|
+
def body(**params)
|
30
|
+
_attributes, contents = flex_scope{ yield }
|
31
|
+
@flex_attributes[:body] = {
|
32
|
+
type: "box",
|
33
|
+
layout: "vertical",
|
34
|
+
contents: contents
|
35
|
+
}.merge(params)
|
36
|
+
end
|
37
|
+
|
38
|
+
def footer(**params)
|
39
|
+
_attributes, contents = flex_scope{ yield }
|
40
|
+
@flex_attributes[:footer] = {
|
41
|
+
type: "box",
|
42
|
+
layout: "vertical",
|
43
|
+
contents: contents
|
44
|
+
}.merge(params)
|
45
|
+
end
|
46
|
+
|
47
|
+
# container
|
48
|
+
def horizontal_box(resources = [nil], **params)
|
49
|
+
resources.each do |resource|
|
50
|
+
_attributes, contents = flex_scope{ yield resource }
|
51
|
+
@flex_contents << {
|
52
|
+
type: "box",
|
53
|
+
layout: "horizontal",
|
54
|
+
contents: contents
|
55
|
+
}.merge(params)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def vertical_box(resources = [nil], **params, &block)
|
60
|
+
horizontal_box(resources, layout: "vertical", **params, &block)
|
61
|
+
end
|
62
|
+
|
63
|
+
def baseline_box(resources = [nil], **params, &block)
|
64
|
+
horizontal_box(resources, layout: "baseline", **params, &block)
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def flex_scope
|
70
|
+
parent_attributes, parent_contents = @flex_attributes, @flex_contents
|
71
|
+
@flex_attributes, @flex_contents = {}, []
|
72
|
+
yield self
|
73
|
+
[@flex_attributes, @flex_contents]
|
74
|
+
ensure
|
75
|
+
@flex_attributes, @flex_contents = parent_attributes, parent_contents
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Kamiflex
|
2
|
+
module QuickReply
|
3
|
+
|
4
|
+
def quick_reply
|
5
|
+
_attributes, contents = flex_scope{ yield }
|
6
|
+
@flex_attributes[:quickReply] = {
|
7
|
+
items: contents
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
def action_item(action)
|
12
|
+
@flex_contents << {
|
13
|
+
type: "action",
|
14
|
+
action: action
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def message_action_item(label, **params)
|
19
|
+
action_item(message_action(label, **params))
|
20
|
+
end
|
21
|
+
|
22
|
+
def postback_action_item(label, **params)
|
23
|
+
action_item(postback_action(label, **params))
|
24
|
+
end
|
25
|
+
|
26
|
+
def datetime_picker_action_item(label, **params)
|
27
|
+
action_item(message_action(label, **params))
|
28
|
+
end
|
29
|
+
|
30
|
+
def camera_action_item(label, **params)
|
31
|
+
action_item(camera_action(label, **params))
|
32
|
+
end
|
33
|
+
|
34
|
+
def camera_roll_action_item(label, **params)
|
35
|
+
action_item(camera_roll_action(label, **params))
|
36
|
+
end
|
37
|
+
|
38
|
+
def location_action_item(label, **params)
|
39
|
+
action_item(location_action(label, **params))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/kamiflex/version.rb
CHANGED
data/lib/kamiflex.rb
CHANGED
@@ -1,164 +1,15 @@
|
|
1
1
|
require "kamiflex/railtie"
|
2
|
+
require "kamiflex/core"
|
3
|
+
require "kamiflex/basic_elements"
|
4
|
+
require "kamiflex/actions"
|
5
|
+
require "kamiflex/quick_reply"
|
2
6
|
|
3
|
-
module
|
4
|
-
def bubble
|
5
|
-
attributes, _contents = flex_scope{ yield }
|
6
|
-
{
|
7
|
-
type: "flex",
|
8
|
-
altText: "this is a flex message",
|
9
|
-
contents: {
|
10
|
-
type: "bubble"
|
11
|
-
}.merge(attributes)
|
12
|
-
}
|
13
|
-
end
|
14
|
-
|
15
|
-
# bubble attributes
|
16
|
-
def header(**params)
|
17
|
-
_attributes, contents = flex_scope{ yield }
|
18
|
-
@flex_attributes[:header] = {
|
19
|
-
type: "box",
|
20
|
-
layout: "vertical",
|
21
|
-
contents: contents
|
22
|
-
}.merge(params)
|
23
|
-
end
|
24
|
-
|
25
|
-
def hero(image_url, **params)
|
26
|
-
_attributes, _contents = flex_scope{ yield }
|
27
|
-
@flex_attributes[:hero] = {}
|
28
|
-
end
|
29
|
-
|
30
|
-
def body(**params)
|
31
|
-
_attributes, contents = flex_scope{ yield }
|
32
|
-
@flex_attributes[:body] = {
|
33
|
-
type: "box",
|
34
|
-
layout: "vertical",
|
35
|
-
contents: contents
|
36
|
-
}.merge(params)
|
37
|
-
end
|
38
|
-
|
39
|
-
def footer(**params)
|
40
|
-
_attributes, contents = flex_scope{ yield }
|
41
|
-
@flex_attributes[:footer] = {
|
42
|
-
type: "box",
|
43
|
-
layout: "vertical",
|
44
|
-
contents: contents
|
45
|
-
}.merge(params)
|
46
|
-
end
|
47
|
-
|
48
|
-
# container
|
49
|
-
def horizontal_box(resources = [nil], **params)
|
50
|
-
resources.each do |resource|
|
51
|
-
_attributes, contents = flex_scope{ yield resource }
|
52
|
-
@flex_contents << {
|
53
|
-
type: "box",
|
54
|
-
layout: "horizontal",
|
55
|
-
contents: contents
|
56
|
-
}.merge(params)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def vertical_box(resources = [nil], **params, &block)
|
61
|
-
horizontal_box(resources, layout: "vertical", **params, &block)
|
62
|
-
end
|
63
|
-
|
64
|
-
def baseline_box(resources = [nil], **params, &block)
|
65
|
-
horizontal_box(resources, layout: "baseline", **params, &block)
|
66
|
-
end
|
67
|
-
|
68
|
-
# elements
|
69
|
-
def text(message, **params)
|
70
|
-
@flex_contents << {
|
71
|
-
"type": "text",
|
72
|
-
"text": message
|
73
|
-
}.merge(params)
|
74
|
-
end
|
75
|
-
|
76
|
-
def image(url, **params)
|
77
|
-
@flex_contents << {
|
78
|
-
"type": "image",
|
79
|
-
"url": url
|
80
|
-
}.merge(params)
|
81
|
-
end
|
82
|
-
|
83
|
-
def icon(url, **params)
|
84
|
-
@flex_contents << {
|
85
|
-
"type": "image",
|
86
|
-
"url": url
|
87
|
-
}.merge(params)
|
88
|
-
end
|
89
|
-
|
90
|
-
def separator(**params)
|
91
|
-
@flex_contents << {
|
92
|
-
"type": "separator",
|
93
|
-
"margin": "md",
|
94
|
-
"color": "#000000",
|
95
|
-
}.merge(params)
|
96
|
-
end
|
97
|
-
|
98
|
-
def spacer(**params)
|
99
|
-
@flex_contents << {
|
100
|
-
"type": "spacer",
|
101
|
-
"size": "md",
|
102
|
-
}.merge(params)
|
103
|
-
end
|
104
|
-
|
105
|
-
def url_button(label, url, **params)
|
106
|
-
@flex_contents << {
|
107
|
-
"type": "button",
|
108
|
-
"action": {
|
109
|
-
"type": "uri",
|
110
|
-
"label": label,
|
111
|
-
"uri": url
|
112
|
-
}
|
113
|
-
}.merge(params)
|
114
|
-
end
|
115
|
-
|
116
|
-
def message_button(label, message, **params)
|
117
|
-
@flex_contents << {
|
118
|
-
"type": "button",
|
119
|
-
"action": {
|
120
|
-
"type": "message",
|
121
|
-
"label": label,
|
122
|
-
"text": message
|
123
|
-
}
|
124
|
-
}.merge(params)
|
125
|
-
end
|
126
|
-
|
127
|
-
# actions
|
128
|
-
def message_action(label, **params)
|
129
|
-
{
|
130
|
-
type: "message",
|
131
|
-
label: label,
|
132
|
-
text: label
|
133
|
-
}.merge(params)
|
134
|
-
end
|
135
|
-
|
136
|
-
def uri_action(uri, **params)
|
137
|
-
{
|
138
|
-
type: "uri",
|
139
|
-
label: uri[0...40],
|
140
|
-
uri: uri,
|
141
|
-
# altUri: {
|
142
|
-
# desktop: uri
|
143
|
-
# }
|
144
|
-
}
|
145
|
-
end
|
146
|
-
|
147
|
-
private
|
148
|
-
|
149
|
-
def flex_scope
|
150
|
-
parent_attributes, parent_contents = @flex_attributes, @flex_contents
|
151
|
-
@flex_attributes, @flex_contents = {}, []
|
152
|
-
yield self
|
153
|
-
[@flex_attributes, @flex_contents]
|
154
|
-
ensure
|
155
|
-
@flex_attributes, @flex_contents = parent_attributes, parent_contents
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
class Kamiflex
|
7
|
+
module Kamiflex
|
160
8
|
def self.build(parent)
|
161
|
-
parent.class.include
|
162
|
-
|
9
|
+
parent.class.include Kamiflex::Core
|
10
|
+
parent.class.include Kamiflex::BasicElements
|
11
|
+
parent.class.include Kamiflex::Actions
|
12
|
+
parent.class.include Kamiflex::QuickReply
|
13
|
+
JSON.pretty_generate yield
|
163
14
|
end
|
164
15
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kamiflex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- etrex kuo
|
@@ -36,6 +36,10 @@ files:
|
|
36
36
|
- README.md
|
37
37
|
- Rakefile
|
38
38
|
- lib/kamiflex.rb
|
39
|
+
- lib/kamiflex/actions.rb
|
40
|
+
- lib/kamiflex/basic_elements.rb
|
41
|
+
- lib/kamiflex/core.rb
|
42
|
+
- lib/kamiflex/quick_reply.rb
|
39
43
|
- lib/kamiflex/railtie.rb
|
40
44
|
- lib/kamiflex/version.rb
|
41
45
|
- lib/tasks/kamiflex_tasks.rake
|