vonage 7.5.0 → 7.7.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
  SHA256:
3
- metadata.gz: f62613660a4bd7e71b9a11ef299c20bd28296bc5f757ae82db513f667db0b687
4
- data.tar.gz: 0db9c1d1b20dfff9936d7dd5ec495e7074242556f69461b57c5ef69bd244314b
3
+ metadata.gz: 242b084a9fa7d5182003af91d36beecd17e87067eb857baafea3d3b3e39c249e
4
+ data.tar.gz: 71ac8feb31afc39000b60d06e41b158effa0017dcd88c5dd799f87474c45c873
5
5
  SHA512:
6
- metadata.gz: 73d49ed457a469c6caf6599b2f712fd035f3cde34daf350ae1ae4c18d510c94a01cf2e23902686c2429cfad066215ea94ef02d846c8ac001fd29a6d52c994867
7
- data.tar.gz: cb3acb8a05f3e3c4ef773a6fca17731ef58929bda0277bbd54e7bc34c8c0983fbcca73e3efd3ddf68a12d62f9c6743efc3474b40d15e13a83bbdd38025ad730b
6
+ metadata.gz: 2fcd2b8066241a751dbdc7311272e1f5232c0aa740c8b1d6353d28e71295b1393035a8b27801d64503ad34d965b1794c345e3d3753bc7d11109db51222495576
7
+ data.tar.gz: 999ad595cb6efd3e8ac88cb306ffaf4b1267c356744985e107d6b7a8c488f8988b54ee57cc763cb47622587272bdbe9c8d994286b4067c270792b2743611b0e8
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
@@ -71,6 +71,7 @@ module Vonage
71
71
 
72
72
  # set headers
73
73
  request['User-Agent'] = UserAgent.string(@config.app_name, @config.app_version)
74
+ request['Accept'] = 'application/json'
74
75
  self.class.request_headers.each do |key, value|
75
76
  request[key] = value
76
77
  end
@@ -1,5 +1,5 @@
1
1
  # typed: strong
2
2
 
3
3
  module Vonage
4
- VERSION = '7.5.0'
4
+ VERSION = '7.7.0'
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.0
4
+ version: 7.7.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-03-16 00:00:00.000000000 Z
11
+ date: 2022-06-29 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