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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f5ef9c12dbe6709e46d6f0932553857f20a6e03
4
- data.tar.gz: dee5f67cf8a8128c83859c3901ed1cef55959a14
3
+ metadata.gz: f470ceb2bf9c2cfa56c2d4c4b003ffd883ceb5cc
4
+ data.tar.gz: 803cffcf8fcc220102f9fa146f9993255ebf2325
5
5
  SHA512:
6
- metadata.gz: 7547a12ad611c4aa5615733907691ae1bd3e83126e16ec66337d02d25faecdb856448d00fcb8b68d485b1f2ceab9e239d90bb1fbec65c2ed1ef499103bcfc6df
7
- data.tar.gz: '035496b29a94129f3156ed97ad59a9774b32c063716d13816e7d4fe1f0e2130bd0146effc80e76d2bef1c9df6429226d71a0c0a41cf44963509841ac47653107'
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 generic_template(recipient_id:, title:, subtitle: nil, image_url: nil, default_url: nil, buttons: [])
48
- template = GenericTemplate.new(title, subtitle, image_url, default_url, buttons)
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 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
- 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
@@ -1,3 +1,3 @@
1
1
  module MessengerClient
2
- VERSION = "0.1.9"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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.1.9
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-05-10 00:00:00.000000000 Z
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