warb 0.1.0 → 0.1.2

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.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +12 -5
  3. data/README.md +8 -0
  4. data/Rakefile +3 -3
  5. data/docs/messages/interactive_call_to_action_url.md +9 -9
  6. data/docs/messages/interactive_list.md +2 -2
  7. data/docs/messages/interactive_reply_button.md +9 -9
  8. data/docs/messages/template.md +13 -13
  9. data/examples/audio.rb +10 -10
  10. data/examples/document.rb +34 -34
  11. data/examples/image.rb +22 -22
  12. data/examples/interactive_call_to_action_url.rb +46 -46
  13. data/examples/interactive_list.rb +61 -61
  14. data/examples/interactive_reply_button.rb +43 -43
  15. data/examples/location.rb +32 -32
  16. data/examples/location_request.rb +11 -11
  17. data/examples/message.rb +8 -8
  18. data/examples/sticker.rb +10 -10
  19. data/examples/video.rb +22 -22
  20. data/examples/webhook.rb +44 -42
  21. data/lib/warb/client.rb +7 -5
  22. data/lib/warb/components/action.rb +12 -8
  23. data/lib/warb/components/button.rb +2 -2
  24. data/lib/warb/components/component.rb +1 -1
  25. data/lib/warb/components/copy_code_button.rb +4 -4
  26. data/lib/warb/components/quick_reply_button.rb +1 -1
  27. data/lib/warb/components/url_button.rb +4 -4
  28. data/lib/warb/components/voice_call_button.rb +1 -1
  29. data/lib/warb/configuration.rb +4 -1
  30. data/lib/warb/connection.rb +15 -9
  31. data/lib/warb/dispatcher.rb +3 -2
  32. data/lib/warb/dispatcher_concern.rb +2 -0
  33. data/lib/warb/errors.rb +27 -0
  34. data/lib/warb/indicator_dispatcher.rb +4 -4
  35. data/lib/warb/language.rb +2 -2
  36. data/lib/warb/media_dispatcher.rb +10 -10
  37. data/lib/warb/resources/audio.rb +1 -1
  38. data/lib/warb/resources/contact.rb +22 -20
  39. data/lib/warb/resources/currency.rb +6 -4
  40. data/lib/warb/resources/date_time.rb +1 -1
  41. data/lib/warb/resources/document.rb +1 -1
  42. data/lib/warb/resources/flow.rb +10 -8
  43. data/lib/warb/resources/image.rb +1 -1
  44. data/lib/warb/resources/interactive_call_to_action_url.rb +10 -8
  45. data/lib/warb/resources/interactive_list.rb +7 -5
  46. data/lib/warb/resources/interactive_reply_button.rb +10 -8
  47. data/lib/warb/resources/location.rb +1 -1
  48. data/lib/warb/resources/location_request.rb +5 -3
  49. data/lib/warb/resources/reaction.rb +1 -1
  50. data/lib/warb/resources/resource.rb +4 -4
  51. data/lib/warb/resources/sticker.rb +1 -1
  52. data/lib/warb/resources/template.rb +30 -29
  53. data/lib/warb/resources/text.rb +4 -4
  54. data/lib/warb/resources/video.rb +1 -1
  55. data/lib/warb/response.rb +33 -0
  56. data/lib/warb/response_error_handler.rb +42 -0
  57. data/lib/warb/template_dispatcher.rb +4 -2
  58. data/lib/warb/utils.rb +3 -1
  59. data/lib/warb/version.rb +1 -1
  60. data/lib/warb.rb +50 -42
  61. metadata +10 -3
data/examples/location.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../lib/warb"
3
+ require_relative '../lib/warb'
4
4
 
5
5
  # Configure your variables here
6
6
 
7
- access_token = ""
8
- business_id = ""
9
- sender_id = ""
10
- recipient_number = ""
7
+ access_token = ''
8
+ business_id = ''
9
+ sender_id = ''
10
+ recipient_number = ''
11
11
 
12
12
  # We recommend testing one section at a time, as it can be overwhelming to see all the messages at once.
13
13
  # So you can comment out the sections you don't want to test.
@@ -22,20 +22,20 @@ warb_from_setup = Warb.setup do |config|
22
22
  config.sender_id = sender_id
23
23
  end
24
24
 
25
- warb_from_setup.location.dispatch(recipient_number, latitude: "37.44216251868683", longitude: "-122.16153582049394")
25
+ warb_from_setup.location.dispatch(recipient_number, latitude: '37.44216251868683', longitude: '-122.16153582049394')
26
26
  warb_from_setup.location.dispatch(
27
27
  recipient_number,
28
- latitude: "37.44216251868683",
29
- longitude: "-122.16153582049394",
30
- name: "OPTIONAL - Location Name",
31
- address: "OPTIONAL - Location Address"
28
+ latitude: '37.44216251868683',
29
+ longitude: '-122.16153582049394',
30
+ name: 'OPTIONAL - Location Name',
31
+ address: 'OPTIONAL - Location Address'
32
32
  )
33
33
 
34
34
  warb_from_setup.location.dispatch(recipient_number) do |builder|
35
- builder.latitude = "37.44216251868683"
36
- builder.longitude = "-122.16153582049394"
37
- builder.name = "OPTIONAL - Location Name"
38
- builder.address = "OPTIONAL - Location Address"
35
+ builder.latitude = '37.44216251868683'
36
+ builder.longitude = '-122.16153582049394'
37
+ builder.name = 'OPTIONAL - Location Name'
38
+ builder.address = 'OPTIONAL - Location Address'
39
39
  end
40
40
 
41
41
  # ############################################ #
@@ -48,38 +48,38 @@ warb_from_new = Warb.new(
48
48
  sender_id: sender_id
49
49
  )
50
50
 
51
- warb_from_new.location.dispatch(recipient_number, latitude: "37.44216251868683", longitude: "-122.16153582049394")
51
+ warb_from_new.location.dispatch(recipient_number, latitude: '37.44216251868683', longitude: '-122.16153582049394')
52
52
  warb_from_new.location.dispatch(
53
53
  recipient_number,
54
- latitude: "37.44216251868683",
55
- longitude: "-122.16153582049394",
56
- name: "OPTIONAL - Location Name",
57
- address: "OPTIONAL - Location Address"
54
+ latitude: '37.44216251868683',
55
+ longitude: '-122.16153582049394',
56
+ name: 'OPTIONAL - Location Name',
57
+ address: 'OPTIONAL - Location Address'
58
58
  )
59
59
 
60
60
  warb_from_new.location.dispatch(recipient_number) do |builder|
61
- builder.latitude = "37.44216251868683"
62
- builder.longitude = "-122.16153582049394"
63
- builder.name = "OPTIONAL - Location Name"
64
- builder.address = "OPTIONAL - Location Address"
61
+ builder.latitude = '37.44216251868683'
62
+ builder.longitude = '-122.16153582049394'
63
+ builder.name = 'OPTIONAL - Location Name'
64
+ builder.address = 'OPTIONAL - Location Address'
65
65
  end
66
66
 
67
67
  # ################################################# #
68
68
  # ============== Using Warb directly ============== #
69
69
  # ################################################# #
70
70
 
71
- Warb.location.dispatch(recipient_number, latitude: "37.44216251868683", longitude: "-122.16153582049394")
71
+ Warb.location.dispatch(recipient_number, latitude: '37.44216251868683', longitude: '-122.16153582049394')
72
72
  Warb.location.dispatch(
73
73
  recipient_number,
74
- latitude: "37.44216251868683",
75
- longitude: "-122.16153582049394",
76
- name: "OPTIONAL - Location Name",
77
- address: "OPTIONAL - Location Address"
74
+ latitude: '37.44216251868683',
75
+ longitude: '-122.16153582049394',
76
+ name: 'OPTIONAL - Location Name',
77
+ address: 'OPTIONAL - Location Address'
78
78
  )
79
79
 
80
80
  Warb.location.dispatch(recipient_number) do |builder|
81
- builder.latitude = "37.44216251868683"
82
- builder.longitude = "-122.16153582049394"
83
- builder.name = "OPTIONAL - Location Name"
84
- builder.address = "OPTIONAL - Location Address"
81
+ builder.latitude = '37.44216251868683'
82
+ builder.longitude = '-122.16153582049394'
83
+ builder.name = 'OPTIONAL - Location Name'
84
+ builder.address = 'OPTIONAL - Location Address'
85
85
  end
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../lib/warb"
3
+ require_relative '../lib/warb'
4
4
 
5
5
  # Configure your variables here
6
6
 
7
- access_token = ""
8
- business_id = ""
9
- sender_id = ""
10
- recipient_number = ""
7
+ access_token = ''
8
+ business_id = ''
9
+ sender_id = ''
10
+ recipient_number = ''
11
11
 
12
12
  # We recommend testing one section at a time, as it can be overwhelming to see all the messages at once.
13
13
  # So you can comment out the sections you don't want to test.
@@ -22,10 +22,10 @@ warb_from_setup = Warb.setup do |config|
22
22
  config.sender_id = sender_id
23
23
  end
24
24
 
25
- warb_from_setup.location_request.dispatch(recipient_number, body_text: "Location request body text")
25
+ warb_from_setup.location_request.dispatch(recipient_number, body_text: 'Location request body text')
26
26
 
27
27
  warb_from_setup.location_request.dispatch(recipient_number) do |builder|
28
- builder.body_text = "Location request body text"
28
+ builder.body_text = 'Location request body text'
29
29
  end
30
30
 
31
31
  # ############################################ #
@@ -38,18 +38,18 @@ warb_from_new = Warb.new(
38
38
  sender_id: sender_id
39
39
  )
40
40
 
41
- warb_from_new.location_request.dispatch(recipient_number, body_text: "Location request body text")
41
+ warb_from_new.location_request.dispatch(recipient_number, body_text: 'Location request body text')
42
42
 
43
43
  warb_from_new.location_request.dispatch(recipient_number) do |builder|
44
- builder.body_text = "Location request body text"
44
+ builder.body_text = 'Location request body text'
45
45
  end
46
46
 
47
47
  # ################################################# #
48
48
  # ============== Using Warb directly ============== #
49
49
  # ################################################# #
50
50
 
51
- Warb.location_request.dispatch(recipient_number, body_text: "Location request body text")
51
+ Warb.location_request.dispatch(recipient_number, body_text: 'Location request body text')
52
52
 
53
53
  Warb.location_request.dispatch(recipient_number) do |builder|
54
- builder.body_text = "Location request body text"
54
+ builder.body_text = 'Location request body text'
55
55
  end
data/examples/message.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../lib/warb"
3
+ require_relative '../lib/warb'
4
4
 
5
5
  # Configure your variables here
6
6
 
7
- access_token = ""
8
- business_id = ""
9
- sender_id = ""
10
- recipient_number = ""
7
+ access_token = ''
8
+ business_id = ''
9
+ sender_id = ''
10
+ recipient_number = ''
11
11
 
12
12
  # We recommend testing one section at a time, as it can be overwhelming to see all the messages at once.
13
13
  # So you can comment out the sections you don't want to test.
@@ -27,7 +27,7 @@ warb_from_setup.message.dispatch(recipient_number, message: 'Hello from warb! Me
27
27
  warb_from_setup.message.dispatch(recipient_number, text: 'Hello from warb! Message sent with "text" key')
28
28
 
29
29
  warb_from_setup.message.dispatch(recipient_number) do |builder|
30
- builder.content = "Hello from warb! Message sent with block builder"
30
+ builder.content = 'Hello from warb! Message sent with block builder'
31
31
  end
32
32
 
33
33
  # ############################################ #
@@ -45,7 +45,7 @@ warb_from_new.message.dispatch(recipient_number, message: 'Hello from warb! Mess
45
45
  warb_from_new.message.dispatch(recipient_number, text: 'Hello from warb! Message sent with "text" key')
46
46
 
47
47
  warb_from_new.message.dispatch(recipient_number) do |builder|
48
- builder.content = "Hello from warb! Message sent with block builder"
48
+ builder.content = 'Hello from warb! Message sent with block builder'
49
49
  end
50
50
 
51
51
  # ################################################# #
@@ -57,5 +57,5 @@ Warb.message.dispatch(recipient_number, message: 'Hello from warb! Message sent
57
57
  Warb.message.dispatch(recipient_number, text: 'Hello from warb! Message sent with "text" key')
58
58
 
59
59
  Warb.message.dispatch(recipient_number) do |builder|
60
- builder.content = "Hello from warb! Message sent with block builder"
60
+ builder.content = 'Hello from warb! Message sent with block builder'
61
61
  end
data/examples/sticker.rb CHANGED
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../lib/warb"
3
+ require_relative '../lib/warb'
4
4
 
5
5
  # Configure your variables here
6
6
 
7
- access_token = ""
8
- business_id = ""
9
- sender_id = ""
10
- recipient_number = ""
7
+ access_token = ''
8
+ business_id = ''
9
+ sender_id = ''
10
+ recipient_number = ''
11
11
 
12
- image_link = ""
12
+ image_link = ''
13
13
 
14
14
  # We recommend testing one section at a time, as it can be overwhelming to see all the messages at once.
15
15
  # So you can comment out the sections you don't want to test.
@@ -25,8 +25,8 @@ warb_from_setup = Warb.setup do |config|
25
25
  end
26
26
 
27
27
  # To send sticker using its ID, you may need to retrieve it first, which can be retrieved this way
28
- file_path = "" # fill this in with the file path pointing to wherever the sticker is located
29
- file_type = "image/webp" # fill this in with the mimetype of the sticker to be uploaded
28
+ file_path = '' # fill this in with the file path pointing to wherever the sticker is located
29
+ file_type = 'image/webp' # fill this in with the mimetype of the sticker to be uploaded
30
30
  # only image/webp is allowed for sticker file type
31
31
  image_id = warb_from_setup.sticker.upload(file_path: file_path, file_type: file_type)
32
32
  # if you already have an sticker id, you can simply replace the above line with such id
@@ -53,8 +53,8 @@ warb_from_new = Warb.new(
53
53
  )
54
54
 
55
55
  # Same as stated above, if you need a sticker id, you can upload it this way
56
- file_path = "" # fill this in with the file path pointing to wherever the sticker is located
57
- file_type = "" # fill this in with the mimetype of the sticker to be uploaded
56
+ file_path = '' # fill this in with the file path pointing to wherever the sticker is located
57
+ file_type = '' # fill this in with the mimetype of the sticker to be uploaded
58
58
  # allow values for file_type: sticker/aac, sticker/amr, sticker/mpeg, sticker/mp4 or sticker/ogg
59
59
  image_id = warb_from_setup.sticker.upload(file_path: file_path, file_type: file_type)
60
60
  # if you already have a sticker id, you can simply replace the above line with such id
data/examples/video.rb CHANGED
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../lib/warb"
3
+ require_relative '../lib/warb'
4
4
 
5
5
  # Configure your variables here
6
6
 
7
- access_token = ""
8
- business_id = ""
9
- sender_id = ""
10
- recipient_number = ""
7
+ access_token = ''
8
+ business_id = ''
9
+ sender_id = ''
10
+ recipient_number = ''
11
11
 
12
- video_link = ""
12
+ video_link = ''
13
13
 
14
14
  # We recommend testing one section at a time, as it can be overwhelming to see all the messages at once.
15
15
  # So you can comment out the sections you don't want to test.
@@ -25,24 +25,24 @@ warb_from_setup = Warb.setup do |config|
25
25
  end
26
26
 
27
27
  # To send video using its ID, you may need to retrieve it first, which can be retrieved this way
28
- file_path = "" # fill this in with the file path pointing to wherever the video is located
29
- file_type = "" # fill this in with the mimetype of the video to be uploaded. allowed values: "video/3gpp" or "video/mp4"
28
+ file_path = '' # fill this in with the file path pointing to wherever the video is located
29
+ file_type = '' # fill this in with the mimetype of the video to be uploaded. allowed values: "video/3gpp" or "video/mp4"
30
30
  video_id = warb_from_setup.video.upload(file_path: file_path, file_type: file_type)
31
31
  # if you already have a video id, you can simply replace the above line with such id
32
32
 
33
33
  warb_from_setup.video.dispatch(recipient_number, media_id: video_id)
34
- warb_from_setup.video.dispatch(recipient_number, media_id: video_id, caption: "OPTIONAL - Image caption")
34
+ warb_from_setup.video.dispatch(recipient_number, media_id: video_id, caption: 'OPTIONAL - Image caption')
35
35
  warb_from_setup.video.dispatch(recipient_number, link: video_link)
36
- warb_from_setup.video.dispatch(recipient_number, link: video_link, caption: "OPTIONAL - Image caption")
36
+ warb_from_setup.video.dispatch(recipient_number, link: video_link, caption: 'OPTIONAL - Image caption')
37
37
 
38
38
  warb_from_setup.video.dispatch(recipient_number) do |builder|
39
39
  builder.media_id = video_id
40
- builder.caption = "OPTIONAL - Image caption"
40
+ builder.caption = 'OPTIONAL - Image caption'
41
41
  end
42
42
 
43
43
  warb_from_setup.video.dispatch(recipient_number) do |builder|
44
44
  builder.link = video_link
45
- builder.caption = "OPTIONAL - Image caption"
45
+ builder.caption = 'OPTIONAL - Image caption'
46
46
  end
47
47
 
48
48
  # ############################################ #
@@ -56,24 +56,24 @@ warb_from_new = Warb.new(
56
56
  )
57
57
 
58
58
  # Same as stated above, if you need a video id, you can upload it this way
59
- file_path = "" # fill this in with the file path pointing to wherever the video is located
60
- file_type = "" # fill this in with the mimetype of the video to be uploaded. allowed values: "video/3gpp" or "video/mp4"
59
+ file_path = '' # fill this in with the file path pointing to wherever the video is located
60
+ file_type = '' # fill this in with the mimetype of the video to be uploaded. allowed values: "video/3gpp" or "video/mp4"
61
61
  video_id = warb_from_setup.video.upload(file_path: file_path, file_type: file_type)
62
62
  # if you already have a video id, you can simply replace the above line with such id
63
63
 
64
64
  warb_from_new.video.dispatch(recipient_number, media_id: video_id)
65
- warb_from_new.video.dispatch(recipient_number, media_id: video_id, caption: "OPTIONAL - Image caption")
65
+ warb_from_new.video.dispatch(recipient_number, media_id: video_id, caption: 'OPTIONAL - Image caption')
66
66
  warb_from_new.video.dispatch(recipient_number, link: video_link)
67
- warb_from_new.video.dispatch(recipient_number, link: video_link, caption: "OPTIONAL - Image caption")
67
+ warb_from_new.video.dispatch(recipient_number, link: video_link, caption: 'OPTIONAL - Image caption')
68
68
 
69
69
  warb_from_new.video.dispatch(recipient_number) do |builder|
70
70
  builder.media_id = video_id
71
- builder.caption = "OPTIONAL - Image caption"
71
+ builder.caption = 'OPTIONAL - Image caption'
72
72
  end
73
73
 
74
74
  warb_from_new.video.dispatch(recipient_number) do |builder|
75
75
  builder.link = video_link
76
- builder.caption = "OPTIONAL - Image caption"
76
+ builder.caption = 'OPTIONAL - Image caption'
77
77
  end
78
78
 
79
79
  # ################################################# #
@@ -81,16 +81,16 @@ end
81
81
  # ################################################# #
82
82
 
83
83
  Warb.video.dispatch(recipient_number, media_id: video_id)
84
- Warb.video.dispatch(recipient_number, media_id: video_id, caption: "OPTIONAL - Image caption")
84
+ Warb.video.dispatch(recipient_number, media_id: video_id, caption: 'OPTIONAL - Image caption')
85
85
  Warb.video.dispatch(recipient_number, link: video_link)
86
- Warb.video.dispatch(recipient_number, link: video_link, caption: "OPTIONAL - Image caption")
86
+ Warb.video.dispatch(recipient_number, link: video_link, caption: 'OPTIONAL - Image caption')
87
87
 
88
88
  Warb.video.dispatch(recipient_number) do |builder|
89
89
  builder.media_id = video_id
90
- builder.caption = "OPTIONAL - Image caption"
90
+ builder.caption = 'OPTIONAL - Image caption'
91
91
  end
92
92
 
93
93
  Warb.video.dispatch(recipient_number) do |builder|
94
94
  builder.link = video_link
95
- builder.caption = "OPTIONAL - Image caption"
95
+ builder.caption = 'OPTIONAL - Image caption'
96
96
  end
data/examples/webhook.rb CHANGED
@@ -1,35 +1,37 @@
1
- require "sinatra/base"
2
- require "faraday"
1
+ # frozen_string_literal: true
2
+
3
+ require 'sinatra/base'
4
+ require 'faraday'
3
5
 
4
6
  class Webhook < Sinatra::Base
5
7
  configure do
6
- set :bind, "0.0.0.0"
8
+ set :bind, '0.0.0.0'
7
9
  set :port, 3000
8
10
  set :host_authorization, { permitted_hosts: [] }
9
11
  end
10
12
 
11
- post "/webhook" do
13
+ post '/webhook' do
12
14
  request_body = JSON.parse(request.body.read)
13
15
 
14
16
  puts "\n🪝 Incoming webhook message: #{request_body}"
15
17
 
16
- message = request_body.dig("entry", 0, "changes", 0, "value", "messages", 0)
18
+ message = request_body.dig('entry', 0, 'changes', 0, 'value', 'messages', 0)
17
19
 
18
- if message && message["type"] == "text"
19
- message_id = message["id"]
20
+ if message && message['type'] == 'text'
21
+ message_id = message['id']
20
22
 
21
23
  Warb.indicator.mark_as_read(message_id)
22
24
 
23
- Warb.message.dispatch(message["from"], reply_to: message_id, message: "Echo #{message["text"]["body"]}")
25
+ Warb.message.dispatch(message['from'], reply_to: message_id, message: "Echo #{message['text']['body']}")
24
26
 
25
27
  reaction = {
26
28
  message_id:,
27
- emoji: ""
29
+ emoji: ''
28
30
  }
29
31
 
30
- Warb.reaction.dispatch(message["from"], **reaction)
31
- elsif message && message["type"] == "location"
32
- message_id = message["id"]
32
+ Warb.reaction.dispatch(message['from'], **reaction)
33
+ elsif message && message['type'] == 'location'
34
+ message_id = message['id']
33
35
 
34
36
  Warb.indicator.mark_as_read(message_id)
35
37
 
@@ -40,15 +42,15 @@ class Webhook < Sinatra::Base
40
42
  sleep 2
41
43
 
42
44
  location = {
43
- latitude: message["location"]["latitude"],
44
- longitude: message["location"]["longitude"],
45
- name: message["location"]["name"],
46
- address: message["location"]["address"]
45
+ latitude: message['location']['latitude'],
46
+ longitude: message['location']['longitude'],
47
+ name: message['location']['name'],
48
+ address: message['location']['address']
47
49
  }
48
50
 
49
- Warb.location.dispatch(message["from"], reply_to: message_id, **location)
50
- elsif message && message["type"] == "image"
51
- message_id = message["id"]
51
+ Warb.location.dispatch(message['from'], reply_to: message_id, **location)
52
+ elsif message && message['type'] == 'image'
53
+ message_id = message['id']
52
54
 
53
55
  Warb.indicator.mark_as_read(message_id)
54
56
 
@@ -67,39 +69,39 @@ class Webhook < Sinatra::Base
67
69
  # below, we resend the received image, using its id.
68
70
 
69
71
  image = {
70
- media_id: message["image"]["id"],
71
- link: message["image"]["link"],
72
- caption: message["image"]["caption"]
72
+ media_id: message['image']['id'],
73
+ link: message['image']['link'],
74
+ caption: message['image']['caption']
73
75
  }
74
76
 
75
- Warb.image.dispatch(message["from"], reply_to: message_id, **image)
77
+ Warb.image.dispatch(message['from'], reply_to: message_id, **image)
76
78
 
77
79
  # and here, we download the received image
78
80
  Warb.image.download(media_id: image[:media_id], file_path: "#{Time.now}.jpg")
79
- elsif message && message["type"] == "document"
80
- message_id = message["id"]
81
+ elsif message && message['type'] == 'document'
82
+ message_id = message['id']
81
83
 
82
84
  Warb.indicator.mark_as_read(message_id)
83
85
 
84
86
  document = {
85
- id: message["document"]["id"],
86
- link: message["document"]["link"],
87
- caption: message["document"]["caption"],
88
- filename: message["document"]["filename"]
87
+ id: message['document']['id'],
88
+ link: message['document']['link'],
89
+ caption: message['document']['caption'],
90
+ filename: message['document']['filename']
89
91
  }
90
92
 
91
- Warb.document.dispatch(message["from"], reply_to: message_id, **document)
92
- elsif message && message["type"] == "sticker"
93
- message_id = message["id"]
93
+ Warb.document.dispatch(message['from'], reply_to: message_id, **document)
94
+ elsif message && message['type'] == 'sticker'
95
+ message_id = message['id']
94
96
 
95
97
  Warb.indicator.mark_as_read(message_id)
96
98
 
97
99
  sticker = {
98
- media_id: message["sticker"]["id"],
99
- link: message["sticker"]["link"]
100
+ media_id: message['sticker']['id'],
101
+ link: message['sticker']['link']
100
102
  }
101
103
 
102
- Warb.sticker.dispatch(message["from"], reply_to: message_id, **sticker)
104
+ Warb.sticker.dispatch(message['from'], reply_to: message_id, **sticker)
103
105
  # you could keep adding verifications for different types of messages...
104
106
  # elsif message && message["type"] == "image"
105
107
  # elsif message && message["type"] == "video"
@@ -115,12 +117,12 @@ class Webhook < Sinatra::Base
115
117
  # this is the endpoint which gets called to verify the server within the Meta's API
116
118
  # you can do whatever you want here to verify your server
117
119
  # returning the challenge value which was received as query param is enough
118
- get "/webhook" do
119
- mode = params["hub.mode"]
120
- token = params["hub.verify_token"]
121
- challenge = params["hub.challenge"]
120
+ get '/webhook' do
121
+ mode = params['hub.mode']
122
+ token = params['hub.verify_token']
123
+ challenge = params['hub.challenge']
122
124
 
123
- if mode == "subscribe" && token == Warb.configuration.webhook_verify_token
125
+ if mode == 'subscribe' && token == Warb.configuration.webhook_verify_token
124
126
  status 200
125
127
  body challenge
126
128
 
@@ -135,8 +137,8 @@ class Webhook < Sinatra::Base
135
137
  private
136
138
 
137
139
  def conn
138
- @conn ||= Faraday.new("https://graph.facebook.com/v22.0") do |conn|
139
- conn.headers["Authorization"] = "Bearer #{Warb.configuration.access_token}" if Warb.configuration.access_token
140
+ @conn ||= Faraday.new('https://graph.facebook.com/v22.0') do |conn|
141
+ conn.headers['Authorization'] = "Bearer #{Warb.configuration.access_token}" if Warb.configuration.access_token
140
142
  conn.request(:json)
141
143
  conn.response(:json)
142
144
  end
data/lib/warb/client.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "connection"
3
+ require_relative 'connection'
4
4
  module Warb
5
5
  class Client
6
6
  include DispatcherConcern
@@ -10,6 +10,7 @@ module Warb
10
10
 
11
11
  def_delegators :@configuration, :access_token, :sender_id, :business_id, :adapter, :logger
12
12
 
13
+ # rubocop:disable Metrics/ParameterLists
13
14
  def initialize(configuration = nil, access_token: nil, sender_id: nil, business_id: nil,
14
15
  adapter: nil, logger: nil)
15
16
  @configuration = (configuration || Warb.configuration).dup
@@ -20,21 +21,22 @@ module Warb
20
21
  @configuration.adapter = adapter || @configuration.adapter
21
22
  @configuration.logger = logger || @configuration.logger
22
23
  end
24
+ # rubocop:enable Metrics/ParameterLists
23
25
 
24
26
  def get(endpoint, data = {}, **args)
25
- conn.send_request(http_method: "get", endpoint: endpoint, data: data, **args)
27
+ conn.send_request(http_method: 'get', endpoint: endpoint, data: data, **args)
26
28
  end
27
29
 
28
30
  def post(endpoint, data = {}, **args)
29
- conn.send_request(http_method: "post", endpoint: endpoint, data: data, **args)
31
+ conn.send_request(http_method: 'post', endpoint: endpoint, data: data, **args)
30
32
  end
31
33
 
32
34
  def put(endpoint, data = {}, **args)
33
- conn.send_request(http_method: "put", endpoint: endpoint, data: data, **args)
35
+ conn.send_request(http_method: 'put', endpoint: endpoint, data: data, **args)
34
36
  end
35
37
 
36
38
  def delete(endpoint, data = {}, **args)
37
- conn.send_request(http_method: "delete", endpoint: endpoint, data: data, **args)
39
+ conn.send_request(http_method: 'delete', endpoint: endpoint, data: data, **args)
38
40
  end
39
41
 
40
42
  private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Warb
2
4
  module Components
3
5
  class Row
@@ -24,12 +26,12 @@ module Warb
24
26
  @rows = rows
25
27
  end
26
28
 
27
- def add_row(**args, &block)
29
+ def add_row(**args, &)
28
30
  row = Row.new(**args)
29
31
 
30
32
  @rows << row
31
33
 
32
- block_given? ? row.tap(&block) : row
34
+ block_given? ? row.tap(&) : row
33
35
  end
34
36
 
35
37
  def to_h
@@ -37,7 +39,7 @@ module Warb
37
39
  title: @title,
38
40
  rows: @rows.map.with_index do |row, index|
39
41
  row_title = row.title.slice(0, 10)
40
- title = row_title.normalize.gsub(/\s/, "").downcase
42
+ title = row_title.normalize.gsub(/\s/, '').downcase
41
43
  id = "#{title}_#{index}"
42
44
 
43
45
  row.to_h.merge(id: id)
@@ -54,12 +56,12 @@ module Warb
54
56
  @sections = sections
55
57
  end
56
58
 
57
- def add_section(**args, &block)
59
+ def add_section(**args, &)
58
60
  section = Section.new(**args)
59
61
 
60
62
  @sections << section
61
63
 
62
- block_given? ? section.tap(&block) : section
64
+ block_given? ? section.tap(&) : section
63
65
  end
64
66
 
65
67
  def to_h
@@ -77,14 +79,15 @@ module Warb
77
79
  @buttons_texts = buttons_texts
78
80
  end
79
81
 
82
+ # rubocop:disable Metrics/MethodLength
80
83
  def to_h
81
84
  {
82
85
  buttons: @buttons_texts.map.with_index do |button_text, index|
83
- text = button_text.normalize.gsub(/\s/, "").downcase
86
+ text = button_text.normalize.gsub(/\s/, '').downcase
84
87
  id = "#{text}_#{index}"
85
88
 
86
89
  {
87
- type: "reply",
90
+ type: 'reply',
88
91
  reply: {
89
92
  id: id,
90
93
  title: button_text
@@ -93,6 +96,7 @@ module Warb
93
96
  end
94
97
  }
95
98
  end
99
+ # rubocop:enable Metrics/MethodLength
96
100
 
97
101
  def add_button_text(button_text)
98
102
  @buttons_texts << button_text
@@ -109,7 +113,7 @@ module Warb
109
113
 
110
114
  def to_h
111
115
  {
112
- name: "cta_url",
116
+ name: 'cta_url',
113
117
  parameters: {
114
118
  display_text: @button_text,
115
119
  url: @url
@@ -8,12 +8,12 @@ module Warb
8
8
  def initialize(**params)
9
9
  params[:sub_type] = button_type unless params[:sub_type]
10
10
 
11
- super(**params)
11
+ super
12
12
  end
13
13
 
14
14
  def to_h
15
15
  {
16
- type: "button",
16
+ type: 'button',
17
17
  sub_type: sub_type || @params[:sub_type],
18
18
  index: index || @params[:index]
19
19
  }
@@ -16,4 +16,4 @@ module Warb
16
16
  attr_reader :params
17
17
  end
18
18
  end
19
- end
19
+ end