messenger_client 0.1.9 → 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/messenger_client/client.rb +7 -2
- data/lib/messenger_client/generic_template.rb +3 -39
- data/lib/messenger_client/list_template.rb +22 -0
- data/lib/messenger_client/template.rb +30 -0
- data/lib/messenger_client/template_item.rb +40 -0
- data/lib/messenger_client/version.rb +1 -1
- data/lib/messenger_client.rb +3 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f470ceb2bf9c2cfa56c2d4c4b003ffd883ceb5cc
|
4
|
+
data.tar.gz: 803cffcf8fcc220102f9fa146f9993255ebf2325
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e80175a4e0bcba16e38853971d8627c0ee568a8a6f548f74777bdd7dd0907517776b6d04d3a1ceea2d9a55076143b90d0363049d27db641336e838210e3c2d87
|
7
|
+
data.tar.gz: e0eeae58462d084f5cb5229279596b9c8b7700f9b5a26282c932521a6658087a5cfe5f04b59fd60d67a55801a5e8d0ae19a9062b26de2a45f89192fbee919d24
|
@@ -44,8 +44,13 @@ module MessengerClient
|
|
44
44
|
send(recipient_id, template.to_json)
|
45
45
|
end
|
46
46
|
|
47
|
-
def
|
48
|
-
template =
|
47
|
+
def list_template(recipient_id:, template_items:, buttons: [])
|
48
|
+
template = ListTemplate.new(template_items, buttons)
|
49
|
+
send(recipient_id, template.to_json)
|
50
|
+
end
|
51
|
+
|
52
|
+
def generic_template(recipient_id:, template_items:)
|
53
|
+
template = GenericTemplate.new(template_items)
|
49
54
|
send(recipient_id, template.to_json)
|
50
55
|
end
|
51
56
|
|
@@ -1,43 +1,7 @@
|
|
1
1
|
module MessengerClient
|
2
|
-
class GenericTemplate
|
3
|
-
def
|
4
|
-
|
5
|
-
@subtitle = subtitle
|
6
|
-
@image_url = image_url
|
7
|
-
@default_url = default_url
|
8
|
-
@buttons = buttons
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_json
|
12
|
-
payload = {
|
13
|
-
template_type: "generic",
|
14
|
-
title: @title,
|
15
|
-
}
|
16
|
-
|
17
|
-
payload.merge!(subtitle: @subtitle) unless @subtitle.nil?
|
18
|
-
payload.merge!(image_url: @image_url) unless @image_url.nil?
|
19
|
-
payload.merge!(default_action: parse_default_action(@default_url)) unless @default_url.nil?
|
20
|
-
payload.merge!(buttons: parse_buttons(@buttons)) unless @buttons.empty?
|
21
|
-
|
22
|
-
{
|
23
|
-
attachment: {
|
24
|
-
type: "template",
|
25
|
-
payload: payload
|
26
|
-
}
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def parse_default_action(url)
|
33
|
-
{
|
34
|
-
type: "web_url",
|
35
|
-
url: url,
|
36
|
-
}
|
37
|
-
end
|
38
|
-
|
39
|
-
def parse_buttons(buttons)
|
40
|
-
buttons.map(&:to_json)
|
2
|
+
class GenericTemplate < Template
|
3
|
+
def type
|
4
|
+
"generic"
|
41
5
|
end
|
42
6
|
end
|
43
7
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module MessengerClient
|
2
|
+
class ListTemplate < Template
|
3
|
+
def initialize(template_items, buttons = [])
|
4
|
+
@template_items = template_items
|
5
|
+
@buttons = buttons
|
6
|
+
end
|
7
|
+
|
8
|
+
def type
|
9
|
+
"list"
|
10
|
+
end
|
11
|
+
|
12
|
+
def payload
|
13
|
+
data = {
|
14
|
+
template_type: type,
|
15
|
+
elements: @template_items.map(&:to_json),
|
16
|
+
}
|
17
|
+
|
18
|
+
data.merge!(buttons: @buttons.map(&:to_json)) if @buttons.any?
|
19
|
+
data
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module MessengerClient
|
2
|
+
class Template
|
3
|
+
def initialize(template_items)
|
4
|
+
@template_items = template_items
|
5
|
+
end
|
6
|
+
|
7
|
+
def type
|
8
|
+
raise NotImplementedError
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_json
|
12
|
+
{
|
13
|
+
attachment: {
|
14
|
+
type: "template",
|
15
|
+
payload: payload
|
16
|
+
}
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def payload
|
23
|
+
{
|
24
|
+
template_type: type,
|
25
|
+
elements: @template_items.map(&:to_json),
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module MessengerClient
|
2
|
+
class TemplateItem
|
3
|
+
def initialize(title, subtitle = nil, image_url = nil, default_url = nil, buttons = [])
|
4
|
+
@title = title
|
5
|
+
@subtitle = subtitle
|
6
|
+
@image_url = image_url
|
7
|
+
@default_url = default_url
|
8
|
+
@buttons = buttons
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_json
|
12
|
+
payload
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def payload
|
18
|
+
data = {
|
19
|
+
title: @title
|
20
|
+
}
|
21
|
+
|
22
|
+
data.merge!(subtitle: @subtitle) unless @subtitle.nil?
|
23
|
+
data.merge!(image_url: @image_url) unless @image_url.nil?
|
24
|
+
data.merge!(default_action: parse_default_action(@default_url)) unless @default_url.nil?
|
25
|
+
data.merge!(buttons: parse_buttons(@buttons)) unless @buttons.empty?
|
26
|
+
data
|
27
|
+
end
|
28
|
+
|
29
|
+
def parse_default_action(url)
|
30
|
+
{
|
31
|
+
type: "web_url",
|
32
|
+
url: url,
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def parse_buttons(buttons)
|
37
|
+
buttons.map(&:to_json)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/messenger_client.rb
CHANGED
@@ -46,8 +46,11 @@ require "messenger_client/menu"
|
|
46
46
|
require "messenger_client/get_started"
|
47
47
|
|
48
48
|
# Templates
|
49
|
+
require "messenger_client/template_item"
|
50
|
+
require "messenger_client/template"
|
49
51
|
require "messenger_client/button_template"
|
50
52
|
require "messenger_client/generic_template"
|
53
|
+
require "messenger_client/list_template"
|
51
54
|
|
52
55
|
# Client
|
53
56
|
require "messenger_client/client"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: messenger_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Cruz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- lib/messenger_client/config.rb
|
92
92
|
- lib/messenger_client/generic_template.rb
|
93
93
|
- lib/messenger_client/get_started.rb
|
94
|
+
- lib/messenger_client/list_template.rb
|
94
95
|
- lib/messenger_client/location_template.rb
|
95
96
|
- lib/messenger_client/login_button.rb
|
96
97
|
- lib/messenger_client/logout_button.rb
|
@@ -115,6 +116,8 @@ files:
|
|
115
116
|
- lib/messenger_client/quick_replies.rb
|
116
117
|
- lib/messenger_client/quick_reply.rb
|
117
118
|
- lib/messenger_client/share_button.rb
|
119
|
+
- lib/messenger_client/template.rb
|
120
|
+
- lib/messenger_client/template_item.rb
|
118
121
|
- lib/messenger_client/url_audio.rb
|
119
122
|
- lib/messenger_client/url_button.rb
|
120
123
|
- lib/messenger_client/url_file.rb
|