diff --git a/CHANGES.md b/CHANGES.md index 15b18a71..282a090b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,7 @@ +# 7.22.0 + +* Adds support for v1 the Conversation API. [#305](https://github.com/Vonage/vonage-ruby-sdk/pull/305) + # 7.21.0 * Changes the HTTP adapter from `Net::HTTP` to `Net::HTTP::Persistent` and fixes an issue with a dependency (`ruby-jwt`) diff --git a/README.md b/README.md index 2e29ccdf..27a21c6d 100644 --- a/README.md +++ b/README.md @@ -525,6 +525,7 @@ The following is a list of Vonage APIs for which the Ruby SDK currently provides * [Account API](https://developer.vonage.com/en/account/overview) * [Application API](https://developer.vonage.com/en/application/overview) +* [Conversation API](https://developer.vonage.com/en/conversation/overview) * [Meetings API](https://developer.vonage.com/en/meetings/overview) * [Messages API](https://developer.vonage.com/en/messages/overview) * [Number Insight API](https://developer.vonage.com/en/number-insight/overview) diff --git a/lib/vonage/client.rb b/lib/vonage/client.rb index 329860f9..ee7f1fa4 100644 --- a/lib/vonage/client.rb +++ b/lib/vonage/client.rb @@ -40,8 +40,17 @@ def applications @applications ||= T.let(Applications.new(config), T.nilable(Vonage::Applications)) end + # @return [Conversation] + # + sig { returns(T.nilable(Vonage::Conversation)) } + def conversation + @conversation ||= T.let(Conversation.new(config), T.nilable(Vonage::Conversation)) + end + # @return [Conversations] # + # @deprecated Please use {#conversation} instead + # sig { returns(T.nilable(Vonage::Conversations)) } def conversations @conversations ||= T.let(Conversations.new(config), T.nilable(Vonage::Conversations)) diff --git a/lib/vonage/conversation.rb b/lib/vonage/conversation.rb new file mode 100644 index 00000000..ac8e0015 --- /dev/null +++ b/lib/vonage/conversation.rb @@ -0,0 +1,164 @@ +# typed: strict +# frozen_string_literal: true + +module Vonage + class Conversation < Namespace + extend T::Sig + + self.authentication = BearerToken + + self.request_body = JSON + + # List conversations associated with a Vonage application. + # + # @example + # response = client.conversation.list + # + # @param [String] :date_start + # Return the records that occurred after this point in time. + # + # @param [String] :date_end + # Return the records that occurred before this point in time. + # + # @param [Integer] :page_size + # Return this amount of records in the response. + # + # @param ['asc', 'desc'] :order + # Return the records in ascending or descending order. + # + # @param [String] :cursor + # The cursor to start returning results from. + # + # @return [Conversation::ListResponse] + # + # @see https://developer.vonage.com/en/api/conversation#listConversations + # + def list(**params) + request('/v1/conversations', params: params, response_class: ListResponse) + end + + # Create a conversation. + # + # @example + # response = client.conversation.create(name: 'Example Conversation', display_name: 'Example Display Name') + # + # @param [String] :name + # Your internal conversation name. Must be unique. + # + # @param [String] :display_name + # The public facing name of the conversation. + # + # @param [String] :image_url + # An image URL that you associate with the conversation + # + # @param [Hash] :properties + # - :ttl (Integer) After how many seconds an empty conversation is deleted + # - :type (String) + # - :custom_sort_key (String) + # - :custom_data (Hash) Custom key/value pairs to be included with conversation data + # + # @option params [Array] :numbers An array of Hashes containing number information for different channels. + # + # @option params [Hash] :callback + # - @option callback :url (String) + # - @option callback :event_mask (String) + # - @option callback :params (Hash) + # - @option params :applicationId (String) + # - @option params :ncco_url (String) + # - @option callback :method (String) Must be one of ['POST', 'GET'] + # + # @return [Response] + # + # @see https://developer.vonage.com/en/api/conversation#createConversation + # + def create(**params) + request('/v1/conversations', params: params, type: Post) + end + + # Retrieve a conversation. + # + # @example + # response = client.conversation.find(conversation_id: 'CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a') + # + # @param [String] :conversation_id + # + # @return [Response] + # + # @see https://developer.vonage.com/en/api/conversation#retrieveConversation + # + def find(conversation_id:) + request("/v1/conversations/#{conversation_id}") + end + + # Update a conversation. + # + # @example + # response = client.conversation.update(conversation_id: 'CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a', display_name: 'Updated conversation') + # + # @param [String] :name + # Your internal conversation name. Must be unique. + # + # @param [String] :display_name + # The public facing name of the conversation. + # + # @param [String] :image_url + # An image URL that you associate with the conversation + # + # @param [Hash] :properties + # - @option properties :ttl (Integer) After how many seconds an empty conversation is deleted + # - @option properties :type (String) + # - @option properties :custom_sort_key (String) + # - @option properties :custom_data (Hash) Custom key/value pairs to be included with conversation data + # + # @param [Array] :numbers An array of Hashes containing number information for different channels. + # + # @option params [Hash] :callback + # - @option callback :url (String) + # - @option callback :event_mask (String) + # - @option callback :params (Hash) + # - @option params :applicationId (String) + # - @option params :ncco_url (String) + # - @option callback :method (String) Must be one of ['POST', 'GET'] + # + # @return [Response] + # + # @see https://developer.vonage.com/en/api/conversation#replaceConversation + # + def update(conversation_id:, **params) + request("/v1/conversations/#{conversation_id}", params: params, type: Put) + end + + # Delete a conversation. + # + # @example + # response = client.conversation.delete(conversation_id: 'CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a') + # + # @param [String] :conversation_id + # + # @return [Response] + # + # @see https://developer.vonage.com/en/api/conversation#deleteConversation + # + def delete(conversation_id:) + request("/v1/conversations/#{conversation_id}", type: Delete) + end + + # @return [Conversation::User] + sig { returns(T.nilable(Vonage::Conversation::User)) } + def user + @user ||= User.new(@config) + end + + # @return [Conversation::Member] + sig { returns(T.nilable(Vonage::Conversation::Member)) } + def member + @member ||= Member.new(@config) + end + + # @return [Conversation::Event] + sig { returns(T.nilable(Vonage::Conversation::Event)) } + def event + @event ||= Event.new(@config) + end + end +end diff --git a/lib/vonage/conversation/event.rb b/lib/vonage/conversation/event.rb new file mode 100644 index 00000000..34aa0c3e --- /dev/null +++ b/lib/vonage/conversation/event.rb @@ -0,0 +1,108 @@ +# typed: true +# frozen_string_literal: true + +module Vonage + class Conversation::Event < Namespace + self.authentication = BearerToken + + self.request_body = JSON + + # List conversation events + # + # @example + # response = client.conversation.event.list(conversation_id: 'CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a') + # + # @param [required, String] :conversation_id The conversation_id of the conversation to list events for + # + # @param [String] :start_id + # The ID to start returning events at + # + # @param [String] :end_id + # The ID to end returning events at + # + # @param [String] :event_type + # The type of event to search for. Does not currently support custom events + # + # @param [Integer] :page_size + # Return this amount of records in the response. + # + # @param ['asc', 'desc'] :order + # Return the records in ascending or descending order. + # + # @param [String] :cursor + # The cursor to start returning results from. + # + # @return [Conversation::Member::ListResponse] + # + # @see https://developer.vonage.com/en/api/conversation#getEvents + # + def list(conversation_id:, **params) + request("/v1/conversations/#{conversation_id}/events", params: params, response_class: ListResponse) + end + + # Create an event + # @example + # response = client.conversation.event.create( + # conversation_id: 'CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a', + # type: 'message', + # body: { + # message_type: 'text', + # text: 'Hello World' + # } + # ) + # + # @param [required, String] :conversation_id The conversation_id of the conversation to create the event for + # + # @param [required, String] :type + # Event type. + # + # @param [String] :from + # + # @option params [required, String] :from + # + # @param [Hash] :body + # The body of the event. There are many possible properties depending on the event type and message_type + # + # @return [Response] + # + # @see https://developer.vonage.com/en/api/conversation#createEvent + # + def create(conversation_id:, **params) + request("/v1/conversations/#{conversation_id}/events", params: params, type: Post) + end + + # Get details of a specific event + # + # @example + # response = client.conversation.event.find(conversation_id: 'CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a', event_id: 1) + # + # @param [required, String] :conversation_id + # + # @param [required, String] :event_id + # + # @return [Response] + # + # @see https://developer.vonage.com/en/api/conversation#getEvent + # + def find(conversation_id:, event_id:) + request("/v1/conversations/#{conversation_id}/events/#{event_id}") + end + + # Delete an event. + # + # @example + # response = client.conversation.event.delete(conversation_id: 'CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a', event_id: 1) + # + # @param [String] :conversation_id + # + # @param [String] :event_id + # + # @return [Response] + # + # @see https://developer.vonage.com/en/api/conversation#deleteEvent + # + def delete(conversation_id:, event_id:) + request("/v1/conversations/#{conversation_id}/events/#{event_id}", type: Delete) + end + end +end diff --git a/lib/vonage/conversation/event/list_response.rb b/lib/vonage/conversation/event/list_response.rb new file mode 100644 index 00000000..520c5256 --- /dev/null +++ b/lib/vonage/conversation/event/list_response.rb @@ -0,0 +1,11 @@ +# typed: true + +class Vonage::Conversation::Event::ListResponse < Vonage::Response + include Enumerable + + def each + return enum_for(:each) unless block_given? + + @entity._embedded.each { |item| yield item } + end +end diff --git a/lib/vonage/conversation/list_response.rb b/lib/vonage/conversation/list_response.rb new file mode 100644 index 00000000..cb3e8f3c --- /dev/null +++ b/lib/vonage/conversation/list_response.rb @@ -0,0 +1,11 @@ +# typed: true + +class Vonage::Conversation::ListResponse < Vonage::Response + include Enumerable + + def each + return enum_for(:each) unless block_given? + + @entity._embedded.conversations.each { |item| yield item } + end +end diff --git a/lib/vonage/conversation/member.rb b/lib/vonage/conversation/member.rb new file mode 100644 index 00000000..e0b717dc --- /dev/null +++ b/lib/vonage/conversation/member.rb @@ -0,0 +1,134 @@ +# typed: true +# frozen_string_literal: true + +module Vonage + class Conversation::Member < Namespace + self.authentication = BearerToken + + self.request_body = JSON + + # List members of a conversation + # + # @example + # response = client.conversation.member.list(conversation_id: 'CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a') + # + # @param [required, String] :conversation_id The conversation_id of the conversation to list members for + # + # @param [Integer] :page_size + # Return this amount of records in the response. + # + # @param ['asc', 'desc'] :order + # Return the records in ascending or descending order. + # + # @param [String] :cursor + # The cursor to start returning results from. + # + # @return [Conversation::Member::ListResponse] + # + # @see https://developer.vonage.com/en/api/conversation#getMembers + # + def list(conversation_id:, **params) + request("/v1/conversations/#{conversation_id}/members", params: params, response_class: ListResponse) + end + + # Create a member. + # + # @example + # response = client.conversation.member.create( + # conversation_id: 'CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a', + # user: { + # id: 'USR-82e028d9-5201-4f1e-8188-604b2d3471ec' + # } + # ) + # + # @param [required, String] :conversation_id The conversation_id of the conversation for which to create the member + # + # @param [String] :state Must be one of ['invited', 'joined'] + # + # @param [Hash] :user (Either :id or :name is required) + # - @option user [String] :id The user_id of the user to add to the conversation + # - @option user [String] :name The name of the user to add to the conversation + # + # @param [Hash] :channel + # - @option channel [required, String] :type The type of channel + # - @option channel [Hash] :from + # - @option from [String] :type + # - @option from [String] :number + # - @option from [String] :id + # - @option channel [Hash] :to + # - @option from [String] :type + # - @option from [String] :user + # - @option from [String] :number + # - @option from [String] :id + # + # @param [Hash] :media + # - @option media [Boolean] :audio + # - @option media [Hash] :audio_settings + # - @option audio_settings [Boolean] :enabled + # - @option audio_settings [Boolean] :earmuffed + # - @option audio_settings [Boolean] :muted + # + # @param [String] :knocking_id + # + # @param [String] :member_id_inviting + # + # @param [String] :from + # + # @return [Response] + # + # @see https://developer.vonage.com/en/api/conversation#createMember + # + def create(conversation_id:, **params) + request("/v1/conversations/#{conversation_id}/members", params: params, type: Post) + end + + # Retrieve a member + # + # @example + # response = client.conversation.member.find( + # conversation_id: 'CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a', + # member_id: 'MEM-63f61863-4a51-4f6b-86e1-46edebio0391' + # ) + # + # @param [required, String] :conversation_id + # + # @param [required, String] :member_id + # + # @return [Response] + # + # @see https://developer.vonage.com/en/api/conversation#getMember + # + def find(conversation_id:, member_id:) + request("/v1/conversations/#{conversation_id}/members/#{member_id}", response_class: Vonage::Response) + end + + # Update a member + # + # @example + # response = client.conversation.member.update( + # conversation_id: 'CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a', + # member_id: 'MEM-63f61863-4a51-4f6b-86e1-46edebio0391', + # state: 'left' + # ) + # + # @param [required, String] :conversation_id + # + # @param [required, String] :member_id + # + # @param [String] :state Must be one of ['joined', 'left'] + # + # @param [String] :from + # + # @param [Hash] :reason + # - @option reason [String] :code + # - @option reason [String] :text + # + # @return [Response] + # + # @see https://developer.vonage.com/en/api/conversation#updateMember + # + def update(conversation_id:, member_id:, **params) + request("/v1/conversations/#{conversation_id}/members/#{member_id}", params: params, type: Patch) + end + end +end diff --git a/lib/vonage/conversation/member/list_response.rb b/lib/vonage/conversation/member/list_response.rb new file mode 100644 index 00000000..1b6922ce --- /dev/null +++ b/lib/vonage/conversation/member/list_response.rb @@ -0,0 +1,11 @@ +# typed: true + +class Vonage::Conversation::Member::ListResponse < Vonage::Response + include Enumerable + + def each + return enum_for(:each) unless block_given? + + @entity._embedded.members.each { |item| yield item } + end +end diff --git a/lib/vonage/conversation/user.rb b/lib/vonage/conversation/user.rb new file mode 100644 index 00000000..70d770df --- /dev/null +++ b/lib/vonage/conversation/user.rb @@ -0,0 +1,67 @@ +# typed: true +# frozen_string_literal: true + +module Vonage + class Conversation::User < Namespace + self.authentication = BearerToken + + # List conversations associated with a user. + # + # @example + # response = client.conversation.user.list_conversations(user_id: 'USR-82e028d9-5201-4f1e-8188-604b2d3471ec') + # + # @param [required, String] :user_id The user_id of the user to list conversations for + # + # @param [String] :state Must be one of ['INVITED', 'JOINED', 'LEFT'] + # + # @param [String] :order_by Must be one of ['created', 'custom_sort_key'] + # + # @param [Boolean] :include_custom_data + # @param [String] :date_start + # Return the records that occurred after this point in time. + # + # @param [String] :date_start + # Return the records that occurred after this point in time. + # + # @param [Integer] :page_size + # Return this amount of records in the response. + # + # @param ['asc', 'desc'] :order + # Return the records in ascending or descending order. + # + # @param [String] :cursor + # The cursor to start returning results from. + # + # @return [Conversation::User::ConversationsListResponse] + # + # @see https://developer.vonage.com/en/api/conversation#getuserConversations + # + def list_conversations(user_id:, **params) + request("/v1/users/#{user_id}/conversations", params: params, response_class: ConversationsListResponse) + end + + # List conversations associated with a user. + # + # @example + # response = client.conversation.user.list_sessions(user_id: 'USR-82e028d9-5201-4f1e-8188-604b2d3471ec') + # + # @param [required, String] :user_id The user_id of the user to list sessions for + # + # @param [Integer] :page_size + # Return this amount of records in the response. + # + # @param ['asc', 'desc'] :order + # Return the records in ascending or descending order. + # + # @param [String] :cursor + # The cursor to start returning results from. + # + # @return [Conversation::User::SessionsListResponse] + # + # @see https://developer.vonage.com/en/api/conversation#getuserSessions + # + def list_sessions(user_id:, **params) + request("/v1/users/#{user_id}/sessions", params: params, response_class: SessionsListResponse) + end + end +end diff --git a/lib/vonage/conversation/user/conversations_list_response.rb b/lib/vonage/conversation/user/conversations_list_response.rb new file mode 100644 index 00000000..7b498c66 --- /dev/null +++ b/lib/vonage/conversation/user/conversations_list_response.rb @@ -0,0 +1,11 @@ +# typed: true + +class Vonage::Conversation::User::ConversationsListResponse < Vonage::Response + include Enumerable + + def each + return enum_for(:each) unless block_given? + + @entity._embedded.conversations.each { |item| yield item } + end +end diff --git a/lib/vonage/conversation/user/sessions_list_response.rb b/lib/vonage/conversation/user/sessions_list_response.rb new file mode 100644 index 00000000..4ff3b4bc --- /dev/null +++ b/lib/vonage/conversation/user/sessions_list_response.rb @@ -0,0 +1,11 @@ +# typed: true + +class Vonage::Conversation::User::SessionsListResponse < Vonage::Response + include Enumerable + + def each + return enum_for(:each) unless block_given? + + @entity._embedded.sessions.each { |item| yield item } + end +end diff --git a/lib/vonage/conversations.rb b/lib/vonage/conversations.rb index 264a0d5a..78db2858 100644 --- a/lib/vonage/conversations.rb +++ b/lib/vonage/conversations.rb @@ -11,6 +11,8 @@ class Conversations < Namespace # Create a conversation. # + # @deprecated Please use {Vonage::Conversation#create} instead + # # @example # response = client.conversations.create(name: 'Example Conversation', display_name: 'Example Display Name') # @@ -37,11 +39,14 @@ class Conversations < Namespace # sig { params(params: T::Hash[Symbol, T.untyped]).returns(Vonage::Response) } def create(params) + logger.info('This method is deprecated and will be removed in a future release. Please use `Vonage::Conversation#create` instead.') request('/beta/conversations', params: params, type: Post) end # List all conversations associated with your application. # + # @deprecated Please use {Vonage::Conversation#list} instead + # # @example # response = client.conversations.list # @@ -71,6 +76,7 @@ def create(params) # sig { params(params: T.nilable(T::Hash[Symbol, T.untyped]), auto_advance: T::Boolean).returns(Vonage::Response) } def list(params = nil, auto_advance = true) + logger.info('This method is deprecated and will be removed in a future release. Please use `Vonage::Conversation#list` instead.') if params && !params.key?(:auto_advance) params.merge!(auto_advance: true) end @@ -80,6 +86,8 @@ def list(params = nil, auto_advance = true) # Retrieve a conversation. # + # @deprecated Please use {Vonage::Conversation#find} instead + # # @example # response = client.conversations.get(id) # @@ -91,11 +99,14 @@ def list(params = nil, auto_advance = true) # sig { params(id: String).returns(Vonage::Response) } def get(id) + logger.info('This method is deprecated and will be removed in a future release. Please use `Vonage::Conversation#find` instead.') request('/beta/conversations/' + id) end # Update a conversation. # + # @deprecated Please use {Vonage::Conversation#update} instead + # # @example # response = client.conversations.update(id, display_name: 'Updated conversation') # @@ -127,11 +138,14 @@ def get(id) params: T::Hash[Symbol, T.untyped] ).returns(Vonage::Response) } def update(id, params) + logger.info('This method is deprecated and will be removed in a future release. Please use `Vonage::Conversation#update` instead.') request('/beta/conversations/' + id, params: params, type: Put) end # Delete a conversation. # + # @deprecated Please use {Vonage::Conversation#delete} instead + # # @example # response = client.conversations.delete(id) # @@ -143,11 +157,14 @@ def update(id, params) # sig { params(id: String).returns(Vonage::Response) } def delete(id) + logger.info('This method is deprecated and will be removed in a future release. Please use `Vonage::Conversation#delete` instead.') request('/beta/conversations/' + id, type: Delete) end # Record a conversation. # + # @deprecated + # # @example # response = client.conversations.record(id, action: 'start') # @@ -178,13 +195,17 @@ def delete(id) params: T::Hash[Symbol, T.untyped] ).returns(Vonage::Response) } def record(id, params) + logger.info('This method is deprecated and will be removed in a future release.') request('/v1/conversations/' + id + '/record', params: params, type: Put) end # @return [Events] # + # @deprecated Please use {Vonage::Conversation#event} instead + # sig { returns(T.nilable(Vonage::Conversations::Events)) } def events + logger.info('This method is deprecated and will be removed in a future release. Please use `Vonage::Conversation#event` instead.') @events = T.let(@events, T.nilable(Vonage::Conversations::Events)) @config = T.let(@config, T.nilable(Vonage::Config)) @events ||= Events.new(@config) @@ -192,24 +213,33 @@ def events # @return [Legs] # + # @deprecated + # sig { returns(T.nilable(Vonage::Conversations::Legs)) } def legs + logger.info('This method is deprecated and will be removed in a future release.') @legs = T.let(@legs, T.nilable(Vonage::Conversations::Legs)) @legs ||= Legs.new(@config) end # @return [Members] # + # @deprecated Please use {Vonage::Conversation#member} instead + # sig { returns(T.nilable(Vonage::Conversations::Members)) } def members + logger.info('This method is deprecated and will be removed in a future release. Please use `Vonage::Conversation#member` instead.') @members = T.let(@members, T.nilable(Vonage::Conversations::Members)) @members ||= Members.new(@config) end # @return [Users] # + # @deprecated Please use {Vonage::Conversation#user} instead + # sig { returns(T.nilable(Vonage::Conversations::Users)) } def users + logger.info('This method is deprecated and will be removed in a future release. Please use `Vonage::Conversation#user` instead.') @users = T.let(@users, T.nilable(Vonage::Conversations::Users)) @users ||= Users.new(@config) end diff --git a/lib/vonage/conversations/events.rb b/lib/vonage/conversations/events.rb index eb57c400..fcdd1598 100644 --- a/lib/vonage/conversations/events.rb +++ b/lib/vonage/conversations/events.rb @@ -9,6 +9,8 @@ class Conversations::Events < Namespace # Create an event. # + # @deprecated Please use {Vonage::Conversation::Event#create} instead + # # @option params [required, String] :type # Event type. # @@ -29,11 +31,14 @@ class Conversations::Events < Namespace # @see https://developer.nexmo.com/api/conversation#createEvent # def create(conversation_id, params) + logger.info('This method is deprecated and will be removed in a future release. Please use `Vonage::Conversation::Event#create` instead.') request('/beta/conversations/' + conversation_id + '/events', params: params, type: Post) end # List events. # + # @deprecated Please use {Vonage::Conversation::Event#list} instead + # # @param [String] conversation_id # # @option params [Boolean] :auto_advance @@ -45,11 +50,14 @@ def create(conversation_id, params) # @see https://developer.nexmo.com/api/conversation#getEvents # def list(conversation_id, params = nil, auto_advance = true) + logger.info('This method is deprecated and will be removed in a future release. Please use `Vonage::Conversation::Event#list` instead.') request('/beta/conversations/' + conversation_id + '/events', params: params) end # Retrieve an event. # + # @deprecated Please use {Vonage::Conversation::Event#find} instead + # # @param [String] conversation_id # @param [String] event_id # @@ -58,11 +66,14 @@ def list(conversation_id, params = nil, auto_advance = true) # @see https://developer.nexmo.com/api/conversation#getEvent # def get(conversation_id, event_id) + logger.info('This method is deprecated and will be removed in a future release. Please use `Vonage::Conversation::Event#find` instead.') request('/beta/conversations/' + conversation_id + '/events/' + event_id.to_s) end # Delete an event. # + # @deprecated Please use {Vonage::Conversation::Event#delete} instead + # # @param [String] conversation_id # @param [String] event_id # @@ -71,6 +82,7 @@ def get(conversation_id, event_id) # @see https://developer.nexmo.com/api/conversation#deleteEvent # def delete(conversation_id, event_id) + logger.info('This method is deprecated and will be removed in a future release. Please use `Vonage::Conversation::Event#delete` instead.') request('/beta/conversations/' + conversation_id + '/events/' + event_id.to_s, type: Delete) end end diff --git a/lib/vonage/conversations/legs.rb b/lib/vonage/conversations/legs.rb index bf431c8f..ac880f7f 100644 --- a/lib/vonage/conversations/legs.rb +++ b/lib/vonage/conversations/legs.rb @@ -7,6 +7,8 @@ class Conversations::Legs < Namespace # List legs. # + # @deprecated + # # @option params [Boolean] :auto_advance # Set this to `false` to not auto-advance through all the pages in the record # and collect all the data. The default is `true`. @@ -16,11 +18,14 @@ class Conversations::Legs < Namespace # @see https://developer.nexmo.com/api/conversation#listLegs # def list(params = nil, auto_advance = true) + logger.info('This method is deprecated and will be removed in a future release.') request('/beta/legs', params: params) end # Delete a leg. # + # @deprecated + # # @param [String] leg_id # # @return [Response] @@ -28,6 +33,7 @@ def list(params = nil, auto_advance = true) # @see https://developer.nexmo.com/api/conversation#deleteLeg # def delete(leg_id) + logger.info('This method is deprecated and will be removed in a future release.') request('/beta/legs/' + leg_id, type: Delete) end end diff --git a/lib/vonage/conversations/members.rb b/lib/vonage/conversations/members.rb index f9a9ede6..8a4c9177 100644 --- a/lib/vonage/conversations/members.rb +++ b/lib/vonage/conversations/members.rb @@ -9,6 +9,8 @@ class Conversations::Members < Namespace # Create a member. # + # @deprecated Please use {Vonage::Conversation::Member#create} instead + # # @option params [String] :action # Invite or join a member to a conversation. # Must be one of: `invite` or `join`. @@ -40,11 +42,14 @@ class Conversations::Members < Namespace # @see https://developer.nexmo.com/api/conversation#createMember # def create(conversation_id, params) + logger.info('This method is deprecated and will be removed in a future release. Please use `Vonage::Conversation::Member#create` instead.') request('/beta/conversations/' + conversation_id + '/members', params: params, type: Post) end # List members. # + # @deprecated Please use {Vonage::Conversation::Member#list} instead + # # @param [String] conversation_id # # @option params [Boolean] :auto_advance @@ -56,11 +61,14 @@ def create(conversation_id, params) # @see https://developer.nexmo.com/api/conversation#getMembers # def list(conversation_id, params = nil, auto_advance = true) + logger.info('This method is deprecated and will be removed in a future release. Please use `Vonage::Conversation::Member#list` instead.') request('/beta/conversations/' + conversation_id + '/members', params: params) end # Retrieve a member. # + # @deprecated Please use {Vonage::Conversation::Member#find} instead + # # @param [String] conversation_id # @param [String] member_id # @@ -69,11 +77,14 @@ def list(conversation_id, params = nil, auto_advance = true) # @see https://developer.nexmo.com/api/conversation#getMember # def get(conversation_id, member_id) + logger.info('This method is deprecated and will be removed in a future release. Please use `Vonage::Conversation::Member#find` instead.') request('/beta/conversations/' + conversation_id + '/members/' + member_id) end # Update a member. # + # @deprecated Please use {Vonage::Conversation::Member#update} instead + # # @option params [String] :action # Invite or join a member to a conversation. # @@ -89,11 +100,14 @@ def get(conversation_id, member_id) # @see https://developer.nexmo.com/api/conversation#updateMember # def update(conversation_id, member_id, params) + logger.info('This method is deprecated and will be removed in a future release. Please use `Vonage::Conversation::Member#update` instead.') request('/beta/conversations/' + conversation_id + '/members/' + member_id, params: params, type: Put) end # Delete a member. # + # @deprecated + # # @param [String] conversation_id # @param [String] member_id # @@ -102,6 +116,7 @@ def update(conversation_id, member_id, params) # @see https://developer.nexmo.com/api/conversation#deleteMember # def delete(conversation_id, member_id) + logger.info('This method is deprecated and will be removed in a future release.') request('/beta/conversations/' + conversation_id + '/members/' + member_id, type: Delete) end end diff --git a/lib/vonage/conversations/users.rb b/lib/vonage/conversations/users.rb index bd9ff35a..665ee9e7 100644 --- a/lib/vonage/conversations/users.rb +++ b/lib/vonage/conversations/users.rb @@ -9,6 +9,8 @@ class Conversations::Users < Namespace # Create a user. # + # @deprecated Please use {Vonage::Users#create} instead + # # @option params [String] :name # Unique name for a user. # @@ -26,11 +28,14 @@ class Conversations::Users < Namespace # @see https://developer.nexmo.com/api/conversation#createUser # def create(params) + logger.info('This method is deprecated and will be removed in a future release. Please use `Vonage::Users#create` instead.') request('/beta/users', params: params, type: Post) end # List users. # + # @deprecated Please use {Vonage::Users#list} instead + # # @option params [Boolean] :auto_advance # Set this to `false` to not auto-advance through all the pages in the record # and collect all the data. The default is `true`. @@ -40,11 +45,14 @@ def create(params) # @see https://developer.nexmo.com/api/conversation#getUsers # def list(params = nil, auto_advance = true) + logger.info('This method is deprecated and will be removed in a future release. Please use `Vonage::Users#list` instead.') request('/beta/users', params: params) end # Retrieve a user. # + # @deprecated Please use {Vonage::Users#find} instead + # # @param [String] id # # @return [Response] @@ -52,11 +60,14 @@ def list(params = nil, auto_advance = true) # @see https://developer.nexmo.com/api/conversation#getUser # def get(id) + logger.info('This method is deprecated and will be removed in a future release. Please use `Vonage::Users#find` instead.') request('/beta/users/' + id) end # Update a user. # + # @deprecated Please use {Vonage::Users#update} instead + # # @option params [String] :name # Unique name for a user. # @@ -79,11 +90,14 @@ def get(id) # @see https://developer.nexmo.com/api/conversation#updateUser # def update(id, params) + logger.info('This method is deprecated and will be removed in a future release. Please use `Vonage::Users#update` instead.') request('/beta/users/' + id, params: params, type: Put) end # Delete a user. # + # @deprecated Please use {Vonage::Users#delete} instead + # # @param [String] id # # @return [Response] @@ -91,6 +105,7 @@ def update(id, params) # @see https://developer.nexmo.com/api/conversation#deleteUser # def delete(id) + logger.info('This method is deprecated and will be removed in a future release. Please use `Vonage::Users#delete` instead.') request('/beta/users/' + id, type: Delete) end end diff --git a/lib/vonage/version.rb b/lib/vonage/version.rb index 27b6a61d..20fe1c6e 100644 --- a/lib/vonage/version.rb +++ b/lib/vonage/version.rb @@ -1,5 +1,5 @@ # typed: strong module Vonage - VERSION = '7.21.0' + VERSION = '7.22.0' end diff --git a/test/vonage/client_test.rb b/test/vonage/client_test.rb index 819eb897..c771b9c7 100644 --- a/test/vonage/client_test.rb +++ b/test/vonage/client_test.rb @@ -26,6 +26,10 @@ def test_calls_method assert_kind_of Vonage::Voice, client.voice end + def test_conversation_method + assert_kind_of Vonage::Conversation, client.conversation + end + def test_conversations_method assert_kind_of Vonage::Conversations, client.conversations end diff --git a/test/vonage/conversation/event_test.rb b/test/vonage/conversation/event_test.rb new file mode 100644 index 00000000..c1811bc7 --- /dev/null +++ b/test/vonage/conversation/event_test.rb @@ -0,0 +1,86 @@ +# typed: false +require_relative '../test' + +class Vonage::Conversation::EventTest < Vonage::Test + def event + Vonage::Conversation::Event.new(config) + end + + def event_id + 1 + end + + def events_uri + "https://api.nexmo.com/v1/conversations/#{conversation_id}/events" + end + + def event_uri + "https://api.nexmo.com/v1/conversations/#{conversation_id}/events/#{event_id}" + end + + def test_list_method + stub_request(:get, events_uri).to_return(events_list_response) + + events_list = event.list(conversation_id: conversation_id) + + assert_kind_of Vonage::Conversation::Event::ListResponse, events_list + events_list.each { |event| assert_kind_of Vonage::Entity, event } + end + + def test_list_method_with_optional_params + stub_request(:get, events_uri + '?order=asc&page_size=1').to_return(events_list_response) + + events_list = event.list(conversation_id: conversation_id, order: 'asc', page_size: 1) + + assert_kind_of Vonage::Conversation::Event::ListResponse, events_list + events_list.each { |event| assert_kind_of Vonage::Entity, event } + end + + def test_list_method_without_conversation_id + assert_raises(ArgumentError) { event.list } + end + + def test_create_method + stub_request(:post, events_uri).to_return(response) + + assert_kind_of Vonage::Response, event.create(conversation_id: conversation_id) + end + + def test_create_method_with_optional_params + stub_request(:post, events_uri).with(body: { type: 'message:delivered' }).to_return(response) + + assert_kind_of Vonage::Response, event.create(conversation_id: conversation_id, type: 'message:delivered') + end + + def test_create_method_without_conversation_id + assert_raises(ArgumentError) { event.create } + end + + def test_find_method + stub_request(:get, event_uri).to_return(response) + + assert_kind_of Vonage::Response, event.find(conversation_id: conversation_id, event_id: event_id) + end + + def test_find_method_without_conversation_id + assert_raises(ArgumentError) { event.find } + end + + def test_find_method_without_event_id + assert_raises(ArgumentError) { event.find(conversation_id: conversation_id) } + end + + def test_delete_method + stub_request(:delete, event_uri).to_return(response) + + assert_kind_of Vonage::Response, event.delete(conversation_id: conversation_id, event_id: event_id) + end + + def test_delete_method_without_conversation_id + assert_raises(ArgumentError) { event.delete } + end + + def test_delete_method_without_event_id + assert_raises(ArgumentError) { event.delete(conversation_id: conversation_id) } + end +end diff --git a/test/vonage/conversation/member_test.rb b/test/vonage/conversation/member_test.rb new file mode 100644 index 00000000..b9309b15 --- /dev/null +++ b/test/vonage/conversation/member_test.rb @@ -0,0 +1,82 @@ +# typed: false +require_relative '../test' + +class Vonage::Conversation::MemberTest < Vonage::Test + def member + Vonage::Conversation::Member.new(config) + end + + def members_uri + "https://api.nexmo.com/v1/conversations/#{conversation_id}/members" + end + + def member_uri + "https://api.nexmo.com/v1/conversations/#{conversation_id}/members/#{member_id}" + end + + def test_list_method + stub_request(:get, members_uri).to_return(members_list_response) + + members_list = member.list(conversation_id: conversation_id) + + assert_kind_of Vonage::Conversation::Member::ListResponse, members_list + members_list.each { |member| assert_kind_of Vonage::Entity, member } + end + + def test_list_method_with_optional_params + stub_request(:get, members_uri + '?order=asc&page_size=1').to_return(members_list_response) + + members_list = member.list(conversation_id: conversation_id, order: 'asc', page_size: 1) + + assert_kind_of Vonage::Conversation::Member::ListResponse, members_list + members_list.each { |member| assert_kind_of Vonage::Entity, member } + end + + def test_list_method_without_conversation_id + assert_raises(ArgumentError) { member.list } + end + + def test_create_method + stub_request(:post, members_uri).to_return(response) + + assert_kind_of Vonage::Response, member.create(conversation_id: conversation_id) + end + + def test_create_method_with_optional_params + stub_request(:post, members_uri).with(body: { state: 'joined' }).to_return(response) + + assert_kind_of Vonage::Response, member.create(conversation_id: conversation_id, state: 'joined') + end + + def test_create_method_without_conversation_id + assert_raises(ArgumentError) { member.create } + end + + def test_find_method + stub_request(:get, member_uri).to_return(response) + + assert_kind_of Vonage::Response, member.find(conversation_id: conversation_id, member_id: member_id) + end + + def test_find_method_without_conversation_id + assert_raises(ArgumentError) { member.find(member_id: member_id) } + end + + def test_find_method_without_member_id + assert_raises(ArgumentError) { member.find(conversation_id: conversation_id) } + end + + def test_update_method + stub_request(:patch, member_uri).with(body: { state: 'left' }).to_return(response) + + assert_kind_of Vonage::Response, member.update(conversation_id: conversation_id, member_id: member_id, state: 'left') + end + + def test_update_method_without_conversation_id + assert_raises(ArgumentError) { member.update(member_id: member_id) } + end + + def test_update_method_without_member_id + assert_raises(ArgumentError) { member.update(conversation_id: conversation_id) } + end +end diff --git a/test/vonage/conversation/user_test.rb b/test/vonage/conversation/user_test.rb new file mode 100644 index 00000000..c1061ded --- /dev/null +++ b/test/vonage/conversation/user_test.rb @@ -0,0 +1,52 @@ +# typed: false +require_relative '../test' + +class Vonage::Conversation::UserTest < Vonage::Test + def user + Vonage::Conversation::User.new(config) + end + + def user_uri + 'https://api.nexmo.com/v1/users/' + user_id + end + + def test_list_conversations_method + stub_request(:get, user_uri + '/conversations').to_return(conversation_list_response) + user_conversations_list = user.list_conversations(user_id: user_id) + + assert_kind_of Vonage::Conversation::User::ConversationsListResponse, user_conversations_list + user_conversations_list.each { |conversation| assert_kind_of Vonage::Entity, conversation } + end + + def test_list_conversations_method_with_optional_params + stub_request(:get, user_uri + '/conversations?order=asc&page_size=1').to_return(conversation_list_response) + user_conversations_list = user.list_conversations(user_id: user_id, order: 'asc', page_size: 1) + + assert_kind_of Vonage::Conversation::User::ConversationsListResponse, user_conversations_list + user_conversations_list.each { |conversation| assert_kind_of Vonage::Entity, conversation } + end + + def test_list_conversations_method_without_user_id + assert_raises(ArgumentError) { user.list_conversations } + end + + def test_list_sessions_method + stub_request(:get, user_uri + '/sessions').to_return(session_list_response) + user_sessions_list = user.list_sessions(user_id: user_id) + + assert_kind_of Vonage::Conversation::User::SessionsListResponse, user_sessions_list + user_sessions_list.each { |session| assert_kind_of Vonage::Entity, session } + end + + def test_list_sessions_method_with_optional_params + stub_request(:get, user_uri + '/sessions?order=asc&page_size=1').to_return(session_list_response) + user_sessions_list = user.list_sessions(user_id: user_id, order: 'asc', page_size: 1) + + assert_kind_of Vonage::Conversation::User::SessionsListResponse, user_sessions_list + user_sessions_list.each { |session| assert_kind_of Vonage::Entity, session } + end + + def test_list_sessions_method_without_user_id + assert_raises(ArgumentError) { user.list_sessions } + end +end diff --git a/test/vonage/conversation_test.rb b/test/vonage/conversation_test.rb new file mode 100644 index 00000000..699af004 --- /dev/null +++ b/test/vonage/conversation_test.rb @@ -0,0 +1,86 @@ +# typed: false +require_relative './test' + +class Vonage::ConversationTest < Vonage::Test + def conversation + Vonage::Conversation.new(config) + end + + def conversations_uri + 'https://api.nexmo.com/v1/conversations' + end + + def conversation_uri + 'https://api.nexmo.com/v1/conversations/' + conversation_id + end + + def test_list_method + stub_request(:get, conversations_uri).to_return(conversation_list_response) + conversation_list = conversation.list + + assert_kind_of Vonage::Conversation::ListResponse, conversation_list + conversation_list.each { |conversation| assert_kind_of Vonage::Entity, conversation } + end + + def test_list_method_with_optional_params + stub_request(:get, conversations_uri + "?page_size=1&order=asc").to_return(conversation_list_response) + conversation_list = conversation.list(order: 'asc', page_size: 1) + + assert_kind_of Vonage::Conversation::ListResponse, conversation_list + conversation_list.each { |conversation| assert_kind_of Vonage::Entity, conversation } + end + + def test_create_method + stub_request(:post, conversations_uri).to_return(response) + + assert_kind_of Vonage::Response, conversation.create + end + + def test_create_method_with_optional_params + stub_request(:post, conversations_uri).with(body: { display_name: 'Test Conversation' }).to_return(response) + + assert_kind_of Vonage::Response, conversation.create(display_name: 'Test Conversation') + end + + def test_find_method + stub_request(:get, conversation_uri).to_return(response) + + assert_kind_of Vonage::Response, conversation.find(conversation_id: conversation_id) + end + + def test_find_method_without_conversation_id + assert_raises(ArgumentError) { conversation.find } + end + + def test_update_method + stub_request(:put, conversation_uri).with(body: { display_name: 'Updated Conversation' }).to_return(response) + + assert_kind_of Vonage::Response, conversation.update(conversation_id: conversation_id, display_name: 'Updated Conversation') + end + + def test_update_method_without_conversation_id + assert_raises(ArgumentError) { conversation.update } + end + + def test_delete_method + stub_request(:delete, conversation_uri).to_return(response) + + assert_kind_of Vonage::Response, conversation.delete(conversation_id: conversation_id) + end + + def test_delete_method_without_conversation_id + assert_raises(ArgumentError) { conversation.delete } + end + + def test_user_method + assert_kind_of Vonage::Conversation::User, conversation.user + end + + def test_member_method + assert_kind_of Vonage::Conversation::Member, conversation.member + end + + def test_event_method + assert_kind_of Vonage::Conversation::Event, conversation.event + end +end diff --git a/test/vonage/test.rb b/test/vonage/test.rb index 522b9027..16f5c560 100644 --- a/test/vonage/test.rb +++ b/test/vonage/test.rb @@ -134,6 +134,22 @@ def applications_response { body: '{"_embedded": {"applications":[]}}', headers: response_headers } end + def conversation_list_response + { body: '{"_embedded": {"conversations":[]}}', headers: response_headers } + end + + def session_list_response + { body: '{"_embedded": {"sessions":[]}}', headers: response_headers } + end + + def members_list_response + { body: '{"_embedded": {"members":[]}}', headers: response_headers } + end + + def events_list_response + { body: '{"_embedded": []}', headers: response_headers } + end + def secrets_response { body: '{"_embedded": {"secrets":[]}}', headers: response_headers } end diff --git a/test/vonage/video/moderation_test.rb b/test/vonage/video/moderation_test.rb index 883f75c0..4146be34 100644 --- a/test/vonage/video/moderation_test.rb +++ b/test/vonage/video/moderation_test.rb @@ -1,7 +1,7 @@ # typed: false require_relative '../test' -class Vonage::Video::SignalsTest < Vonage::Test +class Vonage::Video::ModerationTest < Vonage::Test def moderation Vonage::Video::Moderation.new(config) end