warb 0.1.2 → 1.0.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.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -12
  3. data/README.md +9 -32
  4. data/Rakefile +3 -3
  5. data/docs/README.md +1 -4
  6. data/docs/components/README.md +1 -4
  7. data/docs/messages/README.md +1 -2
  8. data/docs/messages/interactive_call_to_action_url.md +9 -9
  9. data/docs/messages/interactive_list.md +2 -2
  10. data/docs/messages/interactive_reply_button.md +9 -9
  11. data/examples/audio.rb +10 -10
  12. data/examples/document.rb +34 -34
  13. data/examples/image.rb +22 -22
  14. data/examples/interactive_call_to_action_url.rb +46 -46
  15. data/examples/interactive_list.rb +61 -61
  16. data/examples/interactive_reply_button.rb +43 -43
  17. data/examples/location.rb +32 -32
  18. data/examples/location_request.rb +11 -11
  19. data/examples/message.rb +8 -8
  20. data/examples/sticker.rb +10 -10
  21. data/examples/video.rb +22 -22
  22. data/examples/webhook.rb +42 -44
  23. data/lib/warb/client.rb +5 -7
  24. data/lib/warb/components/action.rb +8 -12
  25. data/lib/warb/configuration.rb +1 -4
  26. data/lib/warb/connection.rb +9 -15
  27. data/lib/warb/dispatcher.rb +3 -4
  28. data/lib/warb/dispatcher_concern.rb +0 -6
  29. data/lib/warb/indicator_dispatcher.rb +4 -4
  30. data/lib/warb/media_dispatcher.rb +10 -10
  31. data/lib/warb/resources/audio.rb +1 -1
  32. data/lib/warb/resources/contact.rb +20 -22
  33. data/lib/warb/resources/document.rb +1 -1
  34. data/lib/warb/resources/flow.rb +8 -10
  35. data/lib/warb/resources/image.rb +1 -1
  36. data/lib/warb/resources/interactive_call_to_action_url.rb +8 -10
  37. data/lib/warb/resources/interactive_list.rb +5 -7
  38. data/lib/warb/resources/interactive_reply_button.rb +8 -10
  39. data/lib/warb/resources/location.rb +1 -11
  40. data/lib/warb/resources/location_request.rb +3 -5
  41. data/lib/warb/resources/reaction.rb +1 -1
  42. data/lib/warb/resources/resource.rb +4 -12
  43. data/lib/warb/resources/sticker.rb +1 -1
  44. data/lib/warb/resources/text.rb +3 -21
  45. data/lib/warb/resources/video.rb +1 -1
  46. data/lib/warb/utils.rb +1 -3
  47. data/lib/warb/version.rb +1 -1
  48. data/lib/warb.rb +31 -50
  49. metadata +3 -29
  50. data/docs/components/button.md +0 -61
  51. data/docs/components/copy_code_button.md +0 -57
  52. data/docs/components/url_button.md +0 -57
  53. data/docs/messages/template.md +0 -327
  54. data/docs/resources/currency.md +0 -22
  55. data/docs/resources/date_time.md +0 -11
  56. data/docs/resources/index.md +0 -14
  57. data/docs/resources/text.md +0 -9
  58. data/lib/warb/components/button.rb +0 -29
  59. data/lib/warb/components/component.rb +0 -19
  60. data/lib/warb/components/copy_code_button.rb +0 -30
  61. data/lib/warb/components/quick_reply_button.rb +0 -15
  62. data/lib/warb/components/url_button.rb +0 -30
  63. data/lib/warb/components/voice_call_button.rb +0 -15
  64. data/lib/warb/errors.rb +0 -27
  65. data/lib/warb/language.rb +0 -8
  66. data/lib/warb/resources/currency.rb +0 -47
  67. data/lib/warb/resources/date_time.rb +0 -34
  68. data/lib/warb/resources/template.rb +0 -167
  69. data/lib/warb/response.rb +0 -33
  70. data/lib/warb/response_error_handler.rb +0 -42
  71. data/lib/warb/template_dispatcher.rb +0 -12
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,37 +1,35 @@
1
- # frozen_string_literal: true
2
-
3
- require 'sinatra/base'
4
- require 'faraday'
1
+ require "sinatra/base"
2
+ require "faraday"
5
3
 
6
4
  class Webhook < Sinatra::Base
7
5
  configure do
8
- set :bind, '0.0.0.0'
6
+ set :bind, "0.0.0.0"
9
7
  set :port, 3000
10
8
  set :host_authorization, { permitted_hosts: [] }
11
9
  end
12
10
 
13
- post '/webhook' do
11
+ post "/webhook" do
14
12
  request_body = JSON.parse(request.body.read)
15
13
 
16
14
  puts "\n🪝 Incoming webhook message: #{request_body}"
17
15
 
18
- message = request_body.dig('entry', 0, 'changes', 0, 'value', 'messages', 0)
16
+ message = request_body.dig("entry", 0, "changes", 0, "value", "messages", 0)
19
17
 
20
- if message && message['type'] == 'text'
21
- message_id = message['id']
18
+ if message && message["type"] == "text"
19
+ message_id = message["id"]
22
20
 
23
21
  Warb.indicator.mark_as_read(message_id)
24
22
 
25
- Warb.message.dispatch(message['from'], reply_to: message_id, message: "Echo #{message['text']['body']}")
23
+ Warb.message.dispatch(message["from"], reply_to: message_id, message: "Echo #{message["text"]["body"]}")
26
24
 
27
25
  reaction = {
28
26
  message_id:,
29
- emoji: ''
27
+ emoji: ""
30
28
  }
31
29
 
32
- Warb.reaction.dispatch(message['from'], **reaction)
33
- elsif message && message['type'] == 'location'
34
- message_id = message['id']
30
+ Warb.reaction.dispatch(message["from"], **reaction)
31
+ elsif message && message["type"] == "location"
32
+ message_id = message["id"]
35
33
 
36
34
  Warb.indicator.mark_as_read(message_id)
37
35
 
@@ -42,15 +40,15 @@ class Webhook < Sinatra::Base
42
40
  sleep 2
43
41
 
44
42
  location = {
45
- latitude: message['location']['latitude'],
46
- longitude: message['location']['longitude'],
47
- name: message['location']['name'],
48
- address: message['location']['address']
43
+ latitude: message["location"]["latitude"],
44
+ longitude: message["location"]["longitude"],
45
+ name: message["location"]["name"],
46
+ address: message["location"]["address"]
49
47
  }
50
48
 
51
- Warb.location.dispatch(message['from'], reply_to: message_id, **location)
52
- elsif message && message['type'] == 'image'
53
- message_id = message['id']
49
+ Warb.location.dispatch(message["from"], reply_to: message_id, **location)
50
+ elsif message && message["type"] == "image"
51
+ message_id = message["id"]
54
52
 
55
53
  Warb.indicator.mark_as_read(message_id)
56
54
 
@@ -69,39 +67,39 @@ class Webhook < Sinatra::Base
69
67
  # below, we resend the received image, using its id.
70
68
 
71
69
  image = {
72
- media_id: message['image']['id'],
73
- link: message['image']['link'],
74
- caption: message['image']['caption']
70
+ media_id: message["image"]["id"],
71
+ link: message["image"]["link"],
72
+ caption: message["image"]["caption"]
75
73
  }
76
74
 
77
- Warb.image.dispatch(message['from'], reply_to: message_id, **image)
75
+ Warb.image.dispatch(message["from"], reply_to: message_id, **image)
78
76
 
79
77
  # and here, we download the received image
80
78
  Warb.image.download(media_id: image[:media_id], file_path: "#{Time.now}.jpg")
81
- elsif message && message['type'] == 'document'
82
- message_id = message['id']
79
+ elsif message && message["type"] == "document"
80
+ message_id = message["id"]
83
81
 
84
82
  Warb.indicator.mark_as_read(message_id)
85
83
 
86
84
  document = {
87
- id: message['document']['id'],
88
- link: message['document']['link'],
89
- caption: message['document']['caption'],
90
- filename: message['document']['filename']
85
+ id: message["document"]["id"],
86
+ link: message["document"]["link"],
87
+ caption: message["document"]["caption"],
88
+ filename: message["document"]["filename"]
91
89
  }
92
90
 
93
- Warb.document.dispatch(message['from'], reply_to: message_id, **document)
94
- elsif message && message['type'] == 'sticker'
95
- message_id = message['id']
91
+ Warb.document.dispatch(message["from"], reply_to: message_id, **document)
92
+ elsif message && message["type"] == "sticker"
93
+ message_id = message["id"]
96
94
 
97
95
  Warb.indicator.mark_as_read(message_id)
98
96
 
99
97
  sticker = {
100
- media_id: message['sticker']['id'],
101
- link: message['sticker']['link']
98
+ media_id: message["sticker"]["id"],
99
+ link: message["sticker"]["link"]
102
100
  }
103
101
 
104
- Warb.sticker.dispatch(message['from'], reply_to: message_id, **sticker)
102
+ Warb.sticker.dispatch(message["from"], reply_to: message_id, **sticker)
105
103
  # you could keep adding verifications for different types of messages...
106
104
  # elsif message && message["type"] == "image"
107
105
  # elsif message && message["type"] == "video"
@@ -117,12 +115,12 @@ class Webhook < Sinatra::Base
117
115
  # this is the endpoint which gets called to verify the server within the Meta's API
118
116
  # you can do whatever you want here to verify your server
119
117
  # returning the challenge value which was received as query param is enough
120
- get '/webhook' do
121
- mode = params['hub.mode']
122
- token = params['hub.verify_token']
123
- challenge = params['hub.challenge']
118
+ get "/webhook" do
119
+ mode = params["hub.mode"]
120
+ token = params["hub.verify_token"]
121
+ challenge = params["hub.challenge"]
124
122
 
125
- if mode == 'subscribe' && token == Warb.configuration.webhook_verify_token
123
+ if mode == "subscribe" && token == Warb.configuration.webhook_verify_token
126
124
  status 200
127
125
  body challenge
128
126
 
@@ -137,8 +135,8 @@ class Webhook < Sinatra::Base
137
135
  private
138
136
 
139
137
  def conn
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
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
142
140
  conn.request(:json)
143
141
  conn.response(:json)
144
142
  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,7 +10,6 @@ module Warb
10
10
 
11
11
  def_delegators :@configuration, :access_token, :sender_id, :business_id, :adapter, :logger
12
12
 
13
- # rubocop:disable Metrics/ParameterLists
14
13
  def initialize(configuration = nil, access_token: nil, sender_id: nil, business_id: nil,
15
14
  adapter: nil, logger: nil)
16
15
  @configuration = (configuration || Warb.configuration).dup
@@ -21,22 +20,21 @@ module Warb
21
20
  @configuration.adapter = adapter || @configuration.adapter
22
21
  @configuration.logger = logger || @configuration.logger
23
22
  end
24
- # rubocop:enable Metrics/ParameterLists
25
23
 
26
24
  def get(endpoint, data = {}, **args)
27
- conn.send_request(http_method: 'get', endpoint: endpoint, data: data, **args)
25
+ conn.send_request(http_method: "get", endpoint: endpoint, data: data, **args)
28
26
  end
29
27
 
30
28
  def post(endpoint, data = {}, **args)
31
- conn.send_request(http_method: 'post', endpoint: endpoint, data: data, **args)
29
+ conn.send_request(http_method: "post", endpoint: endpoint, data: data, **args)
32
30
  end
33
31
 
34
32
  def put(endpoint, data = {}, **args)
35
- conn.send_request(http_method: 'put', endpoint: endpoint, data: data, **args)
33
+ conn.send_request(http_method: "put", endpoint: endpoint, data: data, **args)
36
34
  end
37
35
 
38
36
  def delete(endpoint, data = {}, **args)
39
- conn.send_request(http_method: 'delete', endpoint: endpoint, data: data, **args)
37
+ conn.send_request(http_method: "delete", endpoint: endpoint, data: data, **args)
40
38
  end
41
39
 
42
40
  private
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Warb
4
2
  module Components
5
3
  class Row
@@ -26,12 +24,12 @@ module Warb
26
24
  @rows = rows
27
25
  end
28
26
 
29
- def add_row(**args, &)
27
+ def add_row(**args, &block)
30
28
  row = Row.new(**args)
31
29
 
32
30
  @rows << row
33
31
 
34
- block_given? ? row.tap(&) : row
32
+ block_given? ? row.tap(&block) : row
35
33
  end
36
34
 
37
35
  def to_h
@@ -39,7 +37,7 @@ module Warb
39
37
  title: @title,
40
38
  rows: @rows.map.with_index do |row, index|
41
39
  row_title = row.title.slice(0, 10)
42
- title = row_title.normalize.gsub(/\s/, '').downcase
40
+ title = row_title.normalize.gsub(/\s/, "").downcase
43
41
  id = "#{title}_#{index}"
44
42
 
45
43
  row.to_h.merge(id: id)
@@ -56,12 +54,12 @@ module Warb
56
54
  @sections = sections
57
55
  end
58
56
 
59
- def add_section(**args, &)
57
+ def add_section(**args, &block)
60
58
  section = Section.new(**args)
61
59
 
62
60
  @sections << section
63
61
 
64
- block_given? ? section.tap(&) : section
62
+ block_given? ? section.tap(&block) : section
65
63
  end
66
64
 
67
65
  def to_h
@@ -79,15 +77,14 @@ module Warb
79
77
  @buttons_texts = buttons_texts
80
78
  end
81
79
 
82
- # rubocop:disable Metrics/MethodLength
83
80
  def to_h
84
81
  {
85
82
  buttons: @buttons_texts.map.with_index do |button_text, index|
86
- text = button_text.normalize.gsub(/\s/, '').downcase
83
+ text = button_text.normalize.gsub(/\s/, "").downcase
87
84
  id = "#{text}_#{index}"
88
85
 
89
86
  {
90
- type: 'reply',
87
+ type: "reply",
91
88
  reply: {
92
89
  id: id,
93
90
  title: button_text
@@ -96,7 +93,6 @@ module Warb
96
93
  end
97
94
  }
98
95
  end
99
- # rubocop:enable Metrics/MethodLength
100
96
 
101
97
  def add_button_text(button_text)
102
98
  @buttons_texts << button_text
@@ -113,7 +109,7 @@ module Warb
113
109
 
114
110
  def to_h
115
111
  {
116
- name: 'cta_url',
112
+ name: "cta_url",
117
113
  parameters: {
118
114
  display_text: @button_text,
119
115
  url: @url
@@ -1,8 +1,6 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Warb
4
2
  class Configuration
5
- attr_accessor :access_token, :sender_id, :business_id, :adapter, :logger, :custom_errors
3
+ attr_accessor :access_token, :sender_id, :business_id, :adapter, :logger
6
4
 
7
5
  def initialize(access_token: nil, sender_id: nil, business_id: nil, adapter: nil, logger: nil)
8
6
  @access_token = access_token
@@ -10,7 +8,6 @@ module Warb
10
8
  @business_id = business_id
11
9
  @adapter = adapter || Faraday.default_adapter
12
10
  @logger = logger || Logger.new($stdout)
13
- @custom_errors = CustomErrors.new.build
14
11
  end
15
12
  end
16
13
  end