Skip to content

Commit

Permalink
Merge pull request #264 from Vonage/dev
Browse files Browse the repository at this point in the history
Release 7.9.0
  • Loading branch information
superchilled authored Apr 19, 2023
2 parents 13a6810 + e03a29b commit 8d2f2b4
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 43 deletions.
7 changes: 6 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# 7.9.0

* Updates the Messages API implementation to ass support for `video` and `file` messages types to the Viber channel, and `sticker` messages in the WhatsApp channel. [#260](https://github.com/Vonage/vonage-ruby-sdk/pull/260)
* Updates the Numbers API implementation to use Basic authentication. [#262](https://github.com/Vonage/vonage-ruby-sdk/pull/262)

# 7.8.2

* Updates the GSM::CHARACTERS constant to remove `ç` and instead add `Ç`. Fixes [#256](https://github.com/Vonage/vonage-ruby-sdk/issues/255)
* Updates code comments for `SMS#send` method to remove properties for unsupported message types `vCal`, `vCard`, and `wappush`
* Updates namespacing for referencing `SecurityUtils#secure_compare` method due to change in `ruby-jwt ` gem dependency.
* Updates namespacing for referencing `SecurityUtils#secure_compare` method due to change in `ruby-jwt ` gem dependency.

# 7.8.1

Expand Down
9 changes: 8 additions & 1 deletion lib/vonage/messaging/channels/viber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Vonage
class Messaging::Channels::Viber < Messaging::Message
MESSAGE_TYPES = ['text', 'image']
MESSAGE_TYPES = ['text', 'image', 'video', 'file']

attr_reader :data

Expand Down Expand Up @@ -33,6 +33,13 @@ def verify_message
when 'image'
raise Vonage::ClientError.new(":message must be a Hash") unless message.is_a? Hash
raise Vonage::ClientError.new(":url is required in :message") unless message[:url]
when 'video'
raise Vonage::ClientError.new(":message must be a Hash") unless message.is_a? Hash
raise Vonage::ClientError.new(":url is required in :message") unless message[:url]
raise Vonage::ClientError.new(":thumb_url is required in :message") unless message[:thumb_url]
when 'file'
raise Vonage::ClientError.new(":message must be a Hash") unless message.is_a? Hash
raise Vonage::ClientError.new(":url is required in :message") unless message[:url]
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/vonage/messaging/channels/whats_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Vonage
class Messaging::Channels::WhatsApp < Messaging::Message
MESSAGE_TYPES = ['text', 'image', 'audio', 'video', 'file', 'template', 'custom']
MESSAGE_TYPES = ['text', 'image', 'audio', 'video', 'file', 'template', 'sticker', 'custom']

attr_reader :data

Expand Down Expand Up @@ -35,6 +35,8 @@ def verify_message
raise Vonage::ClientError.new(":name is required in :template") unless message[:name]
raise Vonage::ClientError.new(":whatsapp is required in :opts") unless opts[:whatsapp]
raise Vonage::ClientError.new(":locale is required in :whatsapp") unless opts[:whatsapp][:locale]
when 'sticker'
raise Vonage::ClientError.new(":message must contain either :id or :url") unless message.has_key?(:id) ^ message.has_key?(:url)
when 'custom'
raise Vonage::ClientError.new(":message must be a Hash") unless message.is_a? Hash
else
Expand Down
35 changes: 29 additions & 6 deletions lib/vonage/numbers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module Vonage
class Numbers < Namespace
include Keys

self.authentication = Basic

self.host = :rest_host

# Retrieve all the inbound numbers associated with your Vonage account.
Expand Down Expand Up @@ -52,7 +54,7 @@ class Numbers < Namespace
# @see https://developer.nexmo.com/api/developer/numbers#getOwnedNumbers
#
def list(params = nil)
request('/account/numbers', params: params, response_class: ListResponse)
request("/account/numbers", params: params, response_class: ListResponse)
end

# Retrieve inbound numbers that are available for the specified country.
Expand Down Expand Up @@ -100,7 +102,7 @@ def list(params = nil)
# @see https://developer.nexmo.com/api/developer/numbers#getAvailableNumbers
#
def search(params)
request('/number/search', params: params, response_class: ListResponse)
request("/number/search", params: params, response_class: ListResponse)
end

# Request to purchase a specific inbound number.
Expand All @@ -125,7 +127,12 @@ def search(params)
# @see https://developer.nexmo.com/api/developer/numbers#buyANumber
#
def buy(params)
request('/number/buy', params: params, type: Post, response_class: Response)
request(
"/number/buy",
params: params,
type: Post,
response_class: Response
)
end

# Cancel your subscription for a specific inbound number.
Expand All @@ -150,7 +157,12 @@ def buy(params)
# @see https://developer.nexmo.com/api/developer/numbers#cancelANumber
#
def cancel(params)
request('/number/cancel', params: params, type: Post, response_class: Response)
request(
"/number/cancel",
params: params,
type: Post,
response_class: Response
)
end

# Change the behaviour of a number that you own.
Expand Down Expand Up @@ -198,14 +210,25 @@ def cancel(params)
# @see https://developer.nexmo.com/api/developer/numbers#updateANumber
#
def update(params)
request('/number/update', params: camelcase(params), type: Post, response_class: Response)
request(
"/number/update",
params: camelcase(params),
type: Post,
response_class: Response
)
end

private

# A specific implementation of iterable_request for Numbers, because the Numbers API
# handles pagination differently to other Vonage APIs
def iterable_request(path, response: nil, response_class: nil, params: {}, &block)
def iterable_request(
path,
response: nil,
response_class: nil,
params: {},
&block
)
response = parse(response, response_class)
params[:index] = 1 unless params.has_key?(:index)
size = params.fetch(:size, 10)
Expand Down
2 changes: 1 addition & 1 deletion lib/vonage/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# typed: strong

module Vonage
VERSION = '7.8.2'
VERSION = "7.9.0"
end
41 changes: 41 additions & 0 deletions test/vonage/messaging/channels/viber_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ def test_with_valid_type_image_specified
assert_includes viber.data, :image
end

def test_with_valid_type_video_specified
viber = Vonage::Messaging::Channels::Viber.new(type: 'video', message: { url: 'https://example.com/video.mp4', thumb_url: 'https://example.com/file1.jpg' })

assert_equal 'video', viber.data[:message_type]
assert_includes viber.data, :video
end

def test_with_valid_type_file_specified
viber = Vonage::Messaging::Channels::Viber.new(type: 'file', message: { url: 'https://example.com/file.pdf' })

assert_equal 'file', viber.data[:message_type]
assert_includes viber.data, :file
end

def test_with_invalid_type_specified
exception = assert_raises {
viber = Vonage::Messaging::Channels::Viber.new(type: 'audio', message: { url: 'https://example.com/audio.mp3' })
Expand Down Expand Up @@ -56,6 +70,33 @@ def test_image_without_url
assert_match ":url is required in :message", exception.message
end

def test_video_without_url
exception = assert_raises {
viber = Vonage::Messaging::Channels::Viber.new(type: 'video', message: { thumb_url: 'https://example.com/file1.jpg' })
}

assert_instance_of Vonage::ClientError, exception
assert_match ":url is required in :message", exception.message
end

def test_video_without_thumb_url
exception = assert_raises {
viber = Vonage::Messaging::Channels::Viber.new(type: 'video', message: { url: 'https://example.com/video.mp4' })
}

assert_instance_of Vonage::ClientError, exception
assert_match ":thumb_url is required in :message", exception.message
end

def test_file_without_url
exception = assert_raises {
viber = Vonage::Messaging::Channels::Viber.new(type: 'file', message: {})
}

assert_instance_of Vonage::ClientError, exception
assert_match ":url is required in :message", exception.message
end

def test_with_opts_client_ref
viber = Vonage::Messaging::Channels::Viber.new(type: 'text', message: 'Hello world!', opts: { client_ref: 'abc123' })

Expand Down
34 changes: 34 additions & 0 deletions test/vonage/messaging/channels/whats_app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ def test_with_valid_type_file_specified
assert_includes whatsapp.data, :file
end

def test_with_valid_type_sticker_specified_with_url
whatsapp = Vonage::Messaging::Channels::WhatsApp.new(type: 'sticker', message: { url: 'https://example.com/file.webp' })

assert_equal 'sticker', whatsapp.data[:message_type]
assert_includes whatsapp.data, :sticker
assert_includes whatsapp.data[:sticker], :url
end

def test_with_valid_type_sticker_specified_with_id
whatsapp = Vonage::Messaging::Channels::WhatsApp.new(type: 'sticker', message: { id: '16aec2a6-bf69-11ed-afa1-0242ac120002' })

assert_equal 'sticker', whatsapp.data[:message_type]
assert_includes whatsapp.data, :sticker
assert_includes whatsapp.data[:sticker], :id
end

def test_with_invalid_type_specified
exception = assert_raises {
whatsapp = Vonage::Messaging::Channels::WhatsApp.new(type: 'vcard', message: { url: 'https://example.com/contact.vcf' })
Expand Down Expand Up @@ -113,6 +129,24 @@ def test_custom_message_with_invalid_message_type
assert_match ":message must be a Hash", exception.message
end

def test_sticker_without_id_or_url
exception = assert_raises {
whatsapp = Vonage::Messaging::Channels::WhatsApp.new(type: 'sticker', message: {})
}

assert_instance_of Vonage::ClientError, exception
assert_match ":message must contain either :id or :url", exception.message
end

def test_sticker_with_both_id_and_url
exception = assert_raises {
whatsapp = Vonage::Messaging::Channels::WhatsApp.new(type: 'sticker', message: { url: 'https://example.com/file.webp', id: '16aec2a6-bf69-11ed-afa1-0242ac120002' })
}

assert_instance_of Vonage::ClientError, exception
assert_match ":message must contain either :id or :url", exception.message
end

def test_with_opts_client_ref
whatsapp = Vonage::Messaging::Channels::WhatsApp.new(type: 'text', message: 'Hello world!', opts: { client_ref: 'abc123' })

Expand Down
Loading

0 comments on commit 8d2f2b4

Please sign in to comment.