vonage 7.5.1 → 7.7.1

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
  SHA256:
3
- metadata.gz: '0058dda59784aa7cfa75fe455daaea8f77996a3a6bb13d0c4e9e9e3f3189d158'
4
- data.tar.gz: f4f638d8a372169e7753e4be0c9a5569034ae94a003fd3abc4e4810d94d4d8e9
3
+ metadata.gz: a5abd23c1c0bb97e8cb78fc79732f72ea35887914247c9680ad3c2eaa6d0cdc2
4
+ data.tar.gz: 9376d57883a348e58082fca9fe7f0fdc22e0f8cc2b459286013a9a44657e7527
5
5
  SHA512:
6
- metadata.gz: 55798156fde3c5cc807a1f1fd9e9e361a76254853fafe314f1c19f687596ebf100f69d9c9791ad31e1e2f22d2c00ddad76ee5e736a39dacfccf0c4d00564f95d
7
- data.tar.gz: 58a1bbc1bccf731746a5cea98b973db35fc7aa201a263e7ea1f054c47b4fd8163c04a40677086278a07392a6c439d410cd1c85ec3dd4ac3594f1aa913cba01b2
6
+ metadata.gz: c2a2dc7f2a936dc09a1548df697d66bc894dba2ec6835bd01a01927de19fe06fc0d8f41a5acd5f241591ae2d6e6fd91c01d14c1bab2f12d11626578bb9a7a365
7
+ data.tar.gz: da5dbce2fa961f5f5fa50812900f3ff563b7a34f1b407a5f64f94f43446c5dd23e8a265962499b9a1f7d055e46100cdcf5af76772fce513a1fe3accc1c2a5122
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)) }
data/lib/vonage/json.rb CHANGED
@@ -6,7 +6,7 @@ module Vonage
6
6
  module JSON
7
7
  extend T::Sig
8
8
 
9
- sig { params(http_request: T.any(Net::HTTP::Put, Net::HTTP::Post, Net::HTTP::Get), params: T::Hash[Symbol, T.untyped]).void }
9
+ sig { params(http_request: T.any(Net::HTTP::Patch, Net::HTTP::Put, Net::HTTP::Post, Net::HTTP::Get), params: T::Hash[Symbol, T.untyped]).void }
10
10
  def self.update(http_request, params)
11
11
  http_request['Content-Type'] = 'application/json'
12
12
  http_request.body = ::JSON.generate(params)
@@ -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.7.1'
5
5
  end
data/lib/vonage/voice.rb CHANGED
@@ -19,8 +19,14 @@ module Vonage
19
19
  # @option params [required, Array<Hash>] :to
20
20
  # Connect to a Phone (PSTN) number, SIP Endpoint, Websocket, or VBC extension.
21
21
  #
22
- # @option params [required, Hash] :from
23
- # Connect to a Phone (PSTN) number.
22
+ # @option params [Hash] :from
23
+ # Connect to a Phone (PSTN) number. Should not be set if **:random_from_number** is **true**
24
+ # If not set, then **:random_from_number** will automatically be set to **true**
25
+ #
26
+ # @option params [Boolean] :random_from_number
27
+ # Set to **true** to use random phone number as **from**. The number will be selected from the list
28
+ # of the numbers assigned to the current application.
29
+ # **random_from_number: true** cannot be used together with **:from**.
24
30
  #
25
31
  # @option params [Array<String>] :ncco
26
32
  # The Vonage Call Control Object to use for this call.
@@ -55,6 +61,14 @@ module Vonage
55
61
  # @see https://developer.nexmo.com/api/voice#createCall
56
62
  #
57
63
  def create(params)
64
+ if params.key?(:from) && params[:random_from_number] == true
65
+ raise ClientError.new("`from` should not be set if `random_from_number` is `true`")
66
+ end
67
+
68
+ if params && !params.key?(:from)
69
+ params.merge!(random_from_number: true)
70
+ end
71
+
58
72
  request('/v1/calls', params: params, type: Post)
59
73
  end
60
74
 
@@ -101,7 +115,7 @@ module Vonage
101
115
  if params && !params.key?(:auto_advance)
102
116
  params.merge!(auto_advance: true)
103
117
  end
104
-
118
+
105
119
  request('/v1/calls', params: params, response_class: ListResponse)
106
120
  end
107
121
 
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.7.1
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-07-02 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