vonage 7.5.1 → 7.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0058dda59784aa7cfa75fe455daaea8f77996a3a6bb13d0c4e9e9e3f3189d158'
4
- data.tar.gz: f4f638d8a372169e7753e4be0c9a5569034ae94a003fd3abc4e4810d94d4d8e9
3
+ metadata.gz: 0c49e3250bfdfaea4ece849f64f65e3e7820dafb185fc9816ccb5ae7c2a37a7c
4
+ data.tar.gz: 402ae1133d19b7a6871642c480b2b2db162e0f560a1179513c088c5209f7e6f1
5
5
  SHA512:
6
- metadata.gz: 55798156fde3c5cc807a1f1fd9e9e361a76254853fafe314f1c19f687596ebf100f69d9c9791ad31e1e2f22d2c00ddad76ee5e736a39dacfccf0c4d00564f95d
7
- data.tar.gz: 58a1bbc1bccf731746a5cea98b973db35fc7aa201a263e7ea1f054c47b4fd8163c04a40677086278a07392a6c439d410cd1c85ec3dd4ac3594f1aa913cba01b2
6
+ metadata.gz: 1fdb9e9324d0a7c3d41b7670d20bfe16922a41ac97eb15a404a2a69394ee3d6b06fb7d37fbb90cf21dda1b15a35cbe64cfefc2236c2b3e1f0a36438b74e67b75
7
+ data.tar.gz: 8d80c1b1aef68c354170a5e906427883ae8c48b931cf845f101a72addee80e397517a5c64046a333585963e4a0fde20e2cc48353f7a64908744bd1b72e887195
data/README.md CHANGED
@@ -98,7 +98,7 @@ By default the hosts are set to `api.nexmo.com` and `rest.nexmo.com`, respective
98
98
 
99
99
  ## JWT authentication
100
100
 
101
- To call newer endpoints that support JWT authentication such as the Voice API you'll
101
+ To call newer endpoints that support JWT authentication such as the Voice API and Messages API you'll
102
102
  also need to specify the `application_id` and `private_key` options. For example:
103
103
 
104
104
  ```ruby
@@ -194,6 +194,32 @@ response = client.voice.create({
194
194
  })
195
195
  ```
196
196
 
197
+ ## Messages API
198
+
199
+ The [Vonage Messages API](https://developer.vonage.com/messages/overview) allows you to send messages over a number of different channels, and various message types within each channel. See the Vonage Developer Documentation for a [complete API reference](https://developer.vonage.com/api/messages-olympus) listing all the channel and message type combinations.
200
+
201
+ The Ruby SDK allows you to construct message data for specific messaging channels. Other than SMS (which has only one type -- text), you need to pass the message `:type` as well as the `:message` itself as arguments to the appropriate messages method, along with any optional properties if needed.
202
+
203
+ ```ruby
204
+ # creating an SMS message
205
+ message = Vonage::Messaging::Message.sms(message: 'Hello world!')
206
+
207
+ # creating a WhatsApp Text message
208
+ message = Vonage::Messaging::Message.whatsapp(type: 'text', message: 'Hello world!')
209
+
210
+ # creating a WhatsApp Image message
211
+ message = Vonage::Messaging::Message.whatsapp(type: 'image', message: { url: 'https://example.com/image.jpg' })
212
+
213
+ # creating an MMS audio message with optional properties
214
+ message = Vonage::Messaging::Message.mms(type: 'audio', message: { url: 'https://example.com/audio.mp3' }, opts: {client_ref: "abc123"})
215
+ ```
216
+
217
+ Once the message data is created, you can then send the message.
218
+
219
+ ```ruby
220
+ response = client.messaging.send(to: "447700900000", from: "447700900001", **message)
221
+ ```
222
+
197
223
  ## Documentation
198
224
 
199
225
  Vonage Ruby documentation: https://www.rubydoc.info/github/Vonage/vonage-ruby-sdk
@@ -218,7 +244,7 @@ The following is a list of Vonage APIs and whether the Ruby SDK provides support
218
244
  | Dispatch API | Beta |❌|
219
245
  | External Accounts API | Beta |❌|
220
246
  | Media API | Beta | ❌|
221
- | Messages API | Beta |❌|
247
+ | Messages API | General Availability |✅|
222
248
  | Number Insight API | General Availability |✅|
223
249
  | Number Management API | General Availability |✅|
224
250
  | Pricing API | General Availability |✅|
data/lib/vonage/client.rb CHANGED
@@ -68,6 +68,13 @@ module Vonage
68
68
  @messages ||= T.let(Messages.new(config), T.nilable(Vonage::Messages))
69
69
  end
70
70
 
71
+ # @return [Messaging]
72
+ #
73
+ sig { returns(T.nilable(Vonage::Messaging)) }
74
+ def messaging
75
+ @messaging ||= T.let(Messaging.new(config), T.nilable(Vonage::Messaging))
76
+ end
77
+
71
78
  # @return [NumberInsight]
72
79
  #
73
80
  sig { returns(T.nilable(Vonage::NumberInsight)) }
@@ -0,0 +1,39 @@
1
+ # typed: true
2
+
3
+ module Vonage
4
+ class Messaging::Channels::Messenger < Messaging::Message
5
+ MESSAGE_TYPES = ['text', 'image', 'audio', 'video', 'file']
6
+
7
+ attr_reader :data
8
+
9
+ def initialize(attributes = {})
10
+ @type = attributes.fetch(:type, nil)
11
+ @message = attributes.fetch(:message, nil)
12
+ @opts = attributes.fetch(:opts, {})
13
+ @data = {}
14
+
15
+ after_initialize!
16
+ end
17
+
18
+ private
19
+
20
+ def build
21
+ data[:channel] = 'messenger'
22
+ super
23
+ end
24
+
25
+ def verify_type
26
+ raise Vonage::ClientError.new("Invalid message type") unless MESSAGE_TYPES.include?(type)
27
+ end
28
+
29
+ def verify_message
30
+ case type
31
+ when 'text'
32
+ raise Vonage::ClientError.new(":message must be a String") unless message.is_a? String
33
+ else
34
+ raise Vonage::ClientError.new(":message must be a Hash") unless message.is_a? Hash
35
+ raise Vonage::ClientError.new(":url is required in :message") unless message[:url]
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,34 @@
1
+ # typed: true
2
+
3
+ module Vonage
4
+ class Messaging::Channels::MMS < Messaging::Message
5
+ MESSAGE_TYPES = ['image', 'vcard', 'audio', 'video']
6
+
7
+ attr_reader :data
8
+
9
+ def initialize(attributes = {})
10
+ @type = attributes.fetch(:type, nil)
11
+ @message = attributes.fetch(:message, nil)
12
+ @opts = attributes.fetch(:opts, {})
13
+ @data = {}
14
+
15
+ after_initialize!
16
+ end
17
+
18
+ private
19
+
20
+ def build
21
+ data[:channel] = 'mms'
22
+ super
23
+ end
24
+
25
+ def verify_type
26
+ raise Vonage::ClientError.new("Invalid message type") unless MESSAGE_TYPES.include?(type)
27
+ end
28
+
29
+ def verify_message
30
+ raise Vonage::ClientError.new(":message must be a Hash") unless message.is_a? Hash
31
+ raise Vonage::ClientError.new(":url is required in :message") unless message[:url]
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,31 @@
1
+ # typed: true
2
+
3
+ module Vonage
4
+ class Messaging::Channels::SMS < Messaging::Message
5
+ attr_reader :data
6
+
7
+ def initialize(attributes = {})
8
+ @type = attributes.fetch(:type, 'text')
9
+ @message = attributes.fetch(:message, nil)
10
+ @opts = attributes.fetch(:opts, {})
11
+ @data = {}
12
+
13
+ after_initialize!
14
+ end
15
+
16
+ private
17
+
18
+ def build
19
+ data[:channel] = 'sms'
20
+ super
21
+ end
22
+
23
+ def verify_type
24
+ raise Vonage::ClientError.new("Invalid message type") unless type == 'text'
25
+ end
26
+
27
+ def verify_message
28
+ raise Vonage::ClientError.new(":message must be a String") unless message.is_a? String
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,39 @@
1
+ # typed: true
2
+
3
+ module Vonage
4
+ class Messaging::Channels::Viber < Messaging::Message
5
+ MESSAGE_TYPES = ['text', 'image']
6
+
7
+ attr_reader :data
8
+
9
+ def initialize(attributes = {})
10
+ @type = attributes.fetch(:type, nil)
11
+ @message = attributes.fetch(:message, nil)
12
+ @opts = attributes.fetch(:opts, {})
13
+ @data = {}
14
+
15
+ after_initialize!
16
+ end
17
+
18
+ private
19
+
20
+ def build
21
+ data[:channel] = ' viber_service'
22
+ super
23
+ end
24
+
25
+ def verify_type
26
+ raise Vonage::ClientError.new("Invalid message type") unless MESSAGE_TYPES.include?(type)
27
+ end
28
+
29
+ def verify_message
30
+ case type
31
+ when 'text'
32
+ raise Vonage::ClientError.new(":message must be a String") unless message.is_a? String
33
+ when 'image'
34
+ raise Vonage::ClientError.new(":message must be a Hash") unless message.is_a? Hash
35
+ raise Vonage::ClientError.new(":url is required in :message") unless message[:url]
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,47 @@
1
+ # typed: true
2
+
3
+ module Vonage
4
+ class Messaging::Channels::WhatsApp < Messaging::Message
5
+ MESSAGE_TYPES = ['text', 'image', 'audio', 'video', 'file', 'template', 'custom']
6
+
7
+ attr_reader :data
8
+
9
+ def initialize(attributes = {})
10
+ @type = attributes.fetch(:type, nil)
11
+ @message = attributes.fetch(:message, nil)
12
+ @opts = attributes.fetch(:opts, {})
13
+ @data = {}
14
+
15
+ after_initialize!
16
+ end
17
+
18
+ private
19
+
20
+ def build
21
+ data[:channel] = 'whatsapp'
22
+ super
23
+ end
24
+
25
+ def verify_type
26
+ raise ClientError.new("Invalid message type") unless MESSAGE_TYPES.include?(type)
27
+ end
28
+
29
+ def verify_message
30
+ case type
31
+ when 'text'
32
+ raise Vonage::ClientError.new(":message must be a String") unless message.is_a? String
33
+ when 'template'
34
+ raise Vonage::ClientError.new(":message must be a Hash") unless message.is_a? Hash
35
+ raise Vonage::ClientError.new(":name is required in :template") unless message[:name]
36
+ raise Vonage::ClientError.new(":whatsapp is required in :opts") unless opts[:whatsapp]
37
+ raise Vonage::ClientError.new(":policy is required in :whatsapp") unless opts[:whatsapp][:policy]
38
+ raise Vonage::ClientError.new(":locale is required in :whatsapp") unless opts[:whatsapp][:locale]
39
+ when 'custom'
40
+ raise Vonage::ClientError.new(":message must be a Hash") unless message.is_a? Hash
41
+ else
42
+ raise Vonage::ClientError.new(":message must be a Hash") unless message.is_a? Hash
43
+ raise Vonage::ClientError.new(":url is required in :message") unless message[:url]
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,42 @@
1
+ # typed: true
2
+
3
+ module Vonage
4
+ class Messaging::Message
5
+ CHANNELS = {
6
+ sms: Vonage::Messaging::Channels::SMS,
7
+ mms: Vonage::Messaging::Channels::MMS,
8
+ whatsapp: Vonage::Messaging::Channels::WhatsApp,
9
+ messenger: Vonage::Messaging::Channels::Messenger,
10
+ viber: Vonage::Messaging::Channels::Viber
11
+ }
12
+
13
+ class << self
14
+ CHANNELS.keys.each do |method|
15
+ define_method method do |attributes|
16
+ CHANNELS[method].new(**attributes).data
17
+ end
18
+ end
19
+ end
20
+
21
+ def self.method_missing(method)
22
+ raise ClientError.new("Messaging channel must be one of the valid options.")
23
+ end
24
+
25
+ private
26
+
27
+ attr_accessor :type, :message, :opts
28
+ attr_writer :data
29
+
30
+ def after_initialize!
31
+ verify_type
32
+ verify_message
33
+ build
34
+ end
35
+
36
+ def build
37
+ data[:message_type] = type
38
+ data[type.to_sym] = message
39
+ data.merge!(opts)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,29 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Vonage
5
+ class Messaging < Namespace
6
+ self.authentication = BearerToken
7
+
8
+ self.request_body = JSON
9
+
10
+ # Send a Message.
11
+ #
12
+ # @example
13
+ # message = Vonage::Messaging::Message.sms(message: "Hello world!")
14
+ # response = client.messaging.send(to: "447700900000", from: "447700900001", **message)
15
+ #
16
+ # @option params [required, String] :to
17
+ #
18
+ # @option params [required, String] :from
19
+ #
20
+ # @option params [required, Hash] **message
21
+ # The Vonage Message object to use for this message.
22
+ #
23
+ # @see https://developer.vonage.com/api/messages-olympus#SendMessage
24
+ #
25
+ def send(params)
26
+ request('/v1/messages', params: params, type: Post)
27
+ end
28
+ end
29
+ end
@@ -1,5 +1,5 @@
1
1
  # typed: strong
2
2
 
3
3
  module Vonage
4
- VERSION = '7.5.1'
4
+ VERSION = '7.6.0'
5
5
  end
data/lib/vonage.rb CHANGED
@@ -13,6 +13,7 @@ module Vonage
13
13
  'json' => 'JSON',
14
14
  'jwt' => 'JWT',
15
15
  'sms' => 'SMS',
16
+ 'mms' => 'MMS',
16
17
  'tfa' => 'TFA',
17
18
  'version' => 'VERSION',
18
19
  })
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vonage
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.5.1
4
+ version: 7.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vonage
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-04 00:00:00.000000000 Z
11
+ date: 2022-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nexmo-jwt
@@ -126,6 +126,13 @@ files:
126
126
  - lib/vonage/keys.rb
127
127
  - lib/vonage/logger.rb
128
128
  - lib/vonage/messages.rb
129
+ - lib/vonage/messaging.rb
130
+ - lib/vonage/messaging/channels/messenger.rb
131
+ - lib/vonage/messaging/channels/mms.rb
132
+ - lib/vonage/messaging/channels/sms.rb
133
+ - lib/vonage/messaging/channels/viber.rb
134
+ - lib/vonage/messaging/channels/whats_app.rb
135
+ - lib/vonage/messaging/message.rb
129
136
  - lib/vonage/namespace.rb
130
137
  - lib/vonage/number_insight.rb
131
138
  - lib/vonage/numbers.rb
@@ -184,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
191
  - !ruby/object:Gem::Version
185
192
  version: '0'
186
193
  requirements: []
187
- rubygems_version: 3.3.6
194
+ rubygems_version: 3.2.3
188
195
  signing_key:
189
196
  specification_version: 4
190
197
  summary: This is the Ruby Server SDK for Vonage APIs. To use it you'll need a Vonage