vonage 7.20.0 → 8.0.0.beta
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 +4 -4
- data/README.md +87 -386
- data/lib/vonage/applications.rb +4 -12
- data/lib/vonage/client.rb +0 -42
- data/lib/vonage/client_error.rb +1 -1
- data/lib/vonage/config.rb +1 -9
- data/lib/vonage/errors.rb +20 -37
- data/lib/vonage/gsm7.rb +1 -1
- data/lib/vonage/jwt.rb +0 -17
- data/lib/vonage/keys.rb +0 -2
- data/lib/vonage/logger.rb +3 -5
- data/lib/vonage/messaging/channels/viber.rb +1 -8
- data/lib/vonage/messaging/channels/whats_app.rb +1 -3
- data/lib/vonage/messaging.rb +0 -11
- data/lib/vonage/namespace.rb +57 -128
- data/lib/vonage/numbers.rb +6 -29
- data/lib/vonage/server_error.rb +1 -1
- data/lib/vonage/signature.rb +5 -5
- data/lib/vonage/sms.rb +20 -20
- data/lib/vonage/version.rb +1 -1
- data/lib/vonage/video/archives.rb +53 -18
- data/lib/vonage/video/list_response.rb +11 -0
- data/lib/vonage/video/moderation.rb +22 -7
- data/lib/vonage/video/signals.rb +9 -4
- data/lib/vonage/video/streams.rb +12 -6
- data/lib/vonage/video.rb +13 -31
- data/lib/vonage/voice/actions/connect.rb +3 -27
- data/lib/vonage/voice/actions/conversation.rb +2 -2
- data/lib/vonage/voice/actions/pay.rb +107 -0
- data/lib/vonage/voice/actions/talk.rb +2 -11
- data/lib/vonage/voice/talk.rb +1 -11
- data/lib/vonage/voice.rb +0 -22
- data/lib/vonage.rb +0 -2
- data/vonage.gemspec +1 -2
- metadata +9 -65
- data/lib/vonage/api_error.rb +0 -33
- data/lib/vonage/meetings/applications.rb +0 -25
- data/lib/vonage/meetings/dial_in_numbers/list_response.rb +0 -11
- data/lib/vonage/meetings/dial_in_numbers.rb +0 -23
- data/lib/vonage/meetings/recordings.rb +0 -36
- data/lib/vonage/meetings/rooms/list_response.rb +0 -11
- data/lib/vonage/meetings/rooms.rb +0 -155
- data/lib/vonage/meetings/sessions/list_response.rb +0 -11
- data/lib/vonage/meetings/sessions.rb +0 -28
- data/lib/vonage/meetings/themes/list_response.rb +0 -11
- data/lib/vonage/meetings/themes.rb +0 -218
- data/lib/vonage/meetings.rb +0 -38
- data/lib/vonage/number_insight_2.rb +0 -36
- data/lib/vonage/proactive_connect/events/list_response.rb +0 -11
- data/lib/vonage/proactive_connect/events.rb +0 -68
- data/lib/vonage/proactive_connect/item.rb +0 -104
- data/lib/vonage/proactive_connect/items/file_response.rb +0 -32
- data/lib/vonage/proactive_connect/items/list_response.rb +0 -11
- data/lib/vonage/proactive_connect/items.rb +0 -107
- data/lib/vonage/proactive_connect/list.rb +0 -168
- data/lib/vonage/proactive_connect/lists/list_response.rb +0 -11
- data/lib/vonage/proactive_connect/lists.rb +0 -35
- data/lib/vonage/proactive_connect.rb +0 -33
- data/lib/vonage/subaccounts/balance_transfers/list_response.rb +0 -11
- data/lib/vonage/subaccounts/credit_transfers/list_response.rb +0 -11
- data/lib/vonage/subaccounts/list_response.rb +0 -15
- data/lib/vonage/subaccounts.rb +0 -203
- data/lib/vonage/users/list_response.rb +0 -11
- data/lib/vonage/users.rb +0 -156
- data/lib/vonage/verify2/channels/email.rb +0 -36
- data/lib/vonage/verify2/channels/silent_auth.rb +0 -45
- data/lib/vonage/verify2/channels/sms.rb +0 -53
- data/lib/vonage/verify2/channels/voice.rb +0 -32
- data/lib/vonage/verify2/channels/whats_app.rb +0 -38
- data/lib/vonage/verify2/channels/whats_app_interactive.rb +0 -32
- data/lib/vonage/verify2/start_verification_options.rb +0 -62
- data/lib/vonage/verify2/workflow.rb +0 -39
- data/lib/vonage/verify2/workflow_builder.rb +0 -25
- data/lib/vonage/verify2.rb +0 -93
- data/lib/vonage/video/archives/list_response.rb +0 -11
- data/lib/vonage/video/broadcasts/list_response.rb +0 -11
- data/lib/vonage/video/broadcasts.rb +0 -75
- data/lib/vonage/video/sip.rb +0 -48
- data/lib/vonage/video/streams/list_response.rb +0 -11
    
        data/lib/vonage/client.rb
    CHANGED
    
    | @@ -61,13 +61,6 @@ module Vonage | |
| 61 61 | 
             
                  @files ||= T.let(Files.new(config), T.nilable(Vonage::Files))
         | 
| 62 62 | 
             
                end
         | 
| 63 63 |  | 
| 64 | 
            -
                # @return [Meetings]
         | 
| 65 | 
            -
                #
         | 
| 66 | 
            -
                sig { returns(T.nilable(Vonage::Meetings)) }
         | 
| 67 | 
            -
                def meetings
         | 
| 68 | 
            -
                  @meetings ||= T.let(Meetings.new(config), T.nilable(Vonage::Meetings))
         | 
| 69 | 
            -
                end
         | 
| 70 | 
            -
             | 
| 71 64 | 
             
                # @return [Messages]
         | 
| 72 65 | 
             
                #
         | 
| 73 66 | 
             
                sig { returns(T.nilable(Vonage::Messages)) }
         | 
| @@ -89,13 +82,6 @@ module Vonage | |
| 89 82 | 
             
                  @number_insight ||= T.let(NumberInsight.new(config), T.nilable(Vonage::NumberInsight))
         | 
| 90 83 | 
             
                end
         | 
| 91 84 |  | 
| 92 | 
            -
                # @return [NumberInsight2]
         | 
| 93 | 
            -
                #
         | 
| 94 | 
            -
                sig { returns(T.nilable(Vonage::NumberInsight2)) }
         | 
| 95 | 
            -
                def number_insight_2
         | 
| 96 | 
            -
                  @number_insight_2 ||= T.let(NumberInsight2.new(config), T.nilable(Vonage::NumberInsight2))
         | 
| 97 | 
            -
                end
         | 
| 98 | 
            -
             | 
| 99 85 | 
             
                # @return [Numbers]
         | 
| 100 86 | 
             
                #
         | 
| 101 87 | 
             
                sig { returns(T.nilable(Vonage::Numbers)) }
         | 
| @@ -110,13 +96,6 @@ module Vonage | |
| 110 96 | 
             
                  @pricing ||= T.let(PricingTypes.new(config), T.nilable(Vonage::PricingTypes))
         | 
| 111 97 | 
             
                end
         | 
| 112 98 |  | 
| 113 | 
            -
                # @return [ProactiveConnect]
         | 
| 114 | 
            -
                #
         | 
| 115 | 
            -
                sig { returns(T.nilable(Vonage::ProactiveConnect)) }
         | 
| 116 | 
            -
                def proactive_connect
         | 
| 117 | 
            -
                  @proactive_connect ||= T.let(ProactiveConnect.new(config), T.nilable(Vonage::ProactiveConnect))
         | 
| 118 | 
            -
                end
         | 
| 119 | 
            -
             | 
| 120 99 | 
             
                # @return [Redact]
         | 
| 121 100 | 
             
                #
         | 
| 122 101 | 
             
                sig { returns(T.nilable(Vonage::Redact)) }
         | 
| @@ -138,13 +117,6 @@ module Vonage | |
| 138 117 | 
             
                  @sms ||= T.let(SMS.new(config), T.nilable(Vonage::SMS))
         | 
| 139 118 | 
             
                end
         | 
| 140 119 |  | 
| 141 | 
            -
                # @return [Subaccounts]
         | 
| 142 | 
            -
                #
         | 
| 143 | 
            -
                sig { returns(T.nilable(Vonage::Subaccounts)) }
         | 
| 144 | 
            -
                def subaccounts
         | 
| 145 | 
            -
                  @subaccounts ||= T.let(Subaccounts.new(config), T.nilable(Vonage::Subaccounts))
         | 
| 146 | 
            -
                end
         | 
| 147 | 
            -
             | 
| 148 120 | 
             
                # @return [TFA]
         | 
| 149 121 | 
             
                #
         | 
| 150 122 | 
             
                sig { returns(T.nilable(Vonage::TFA)) }
         | 
| @@ -152,13 +124,6 @@ module Vonage | |
| 152 124 | 
             
                  @tfa ||= T.let(TFA.new(config), T.nilable(Vonage::TFA))
         | 
| 153 125 | 
             
                end
         | 
| 154 126 |  | 
| 155 | 
            -
                # @return [Users]
         | 
| 156 | 
            -
                #
         | 
| 157 | 
            -
                sig { returns(T.nilable(Vonage::Users)) }
         | 
| 158 | 
            -
                def users
         | 
| 159 | 
            -
                  @users ||= T.let(Users.new(config), T.nilable(Vonage::Users))
         | 
| 160 | 
            -
                end
         | 
| 161 | 
            -
             | 
| 162 127 | 
             
                # @return [Verify]
         | 
| 163 128 | 
             
                #
         | 
| 164 129 | 
             
                sig { returns(T.nilable(Vonage::Verify)) }
         | 
| @@ -166,13 +131,6 @@ module Vonage | |
| 166 131 | 
             
                  @verify ||= T.let(Verify.new(config), T.nilable(Vonage::Verify))
         | 
| 167 132 | 
             
                end
         | 
| 168 133 |  | 
| 169 | 
            -
                # @return [Verify2]
         | 
| 170 | 
            -
                #
         | 
| 171 | 
            -
                sig { returns(T.nilable(Vonage::Verify2)) }
         | 
| 172 | 
            -
                def verify2
         | 
| 173 | 
            -
                  @verify2 ||= T.let(Verify2.new(config), T.nilable(Vonage::Verify2))
         | 
| 174 | 
            -
                end
         | 
| 175 | 
            -
             | 
| 176 134 | 
             
                # @return [Video]
         | 
| 177 135 | 
             
                #
         | 
| 178 136 | 
             
                sig { returns(T.nilable(Vonage::Video)) }
         | 
    
        data/lib/vonage/client_error.rb
    CHANGED
    
    
    
        data/lib/vonage/config.rb
    CHANGED
    
    | @@ -19,7 +19,6 @@ module Vonage | |
| 19 19 | 
             
                  self.signature_method = ENV['VONAGE_SIGNATURE_METHOD'] || 'md5hash'
         | 
| 20 20 | 
             
                  self.token = T.let(nil, T.nilable(String))
         | 
| 21 21 | 
             
                  self.video_host = 'video.api.vonage.com'
         | 
| 22 | 
            -
                  self.vonage_host = 'api-eu.vonage.com'
         | 
| 23 22 | 
             
                end
         | 
| 24 23 |  | 
| 25 24 | 
             
                # Merges the config with the given options hash.
         | 
| @@ -131,11 +130,7 @@ module Vonage | |
| 131 130 |  | 
| 132 131 | 
             
                # @return [Vonage::Logger]
         | 
| 133 132 | 
             
                #
         | 
| 134 | 
            -
                sig { params(logger: T.nilable(
         | 
| 135 | 
            -
                  defined?(ActiveSupport::BroadcastLogger) ?
         | 
| 136 | 
            -
                    T.any(::Logger, Vonage::Logger, ActiveSupport::BroadcastLogger)
         | 
| 137 | 
            -
                  : T.any(::Logger, Vonage::Logger)
         | 
| 138 | 
            -
                )).returns(T.nilable(Vonage::Logger)) }
         | 
| 133 | 
            +
                sig { params(logger: T.nilable(T.any(::Logger, Vonage::Logger))).returns(T.nilable(Vonage::Logger)) }
         | 
| 139 134 | 
             
                def logger=(logger)
         | 
| 140 135 | 
             
                  @logger = T.let(Logger.new(logger), T.nilable(Vonage::Logger))
         | 
| 141 136 | 
             
                end
         | 
| @@ -206,9 +201,6 @@ module Vonage | |
| 206 201 |  | 
| 207 202 | 
             
                sig { returns(String) }
         | 
| 208 203 | 
             
                attr_accessor :video_host
         | 
| 209 | 
            -
                
         | 
| 210 | 
            -
                sig { returns(String) }
         | 
| 211 | 
            -
                attr_accessor :vonage_host
         | 
| 212 204 |  | 
| 213 205 | 
             
                protected
         | 
| 214 206 |  | 
    
        data/lib/vonage/errors.rb
    CHANGED
    
    | @@ -1,25 +1,14 @@ | |
| 1 1 | 
             
            # typed: strict
         | 
| 2 2 | 
             
            # frozen_string_literal: true
         | 
| 3 | 
            -
            require  | 
| 3 | 
            +
            require 'json'
         | 
| 4 4 |  | 
| 5 5 | 
             
            module Vonage
         | 
| 6 6 | 
             
              module Errors
         | 
| 7 7 | 
             
                extend T::Sig
         | 
| 8 8 |  | 
| 9 | 
            -
                sig  | 
| 10 | 
            -
                  params(
         | 
| 11 | 
            -
                    response:
         | 
| 12 | 
            -
                      T.any(
         | 
| 13 | 
            -
                        Net::HTTPUnauthorized,
         | 
| 14 | 
            -
                        Net::HTTPClientError,
         | 
| 15 | 
            -
                        Net::HTTPServerError,
         | 
| 16 | 
            -
                        T.untyped
         | 
| 17 | 
            -
                      )
         | 
| 18 | 
            -
                  ).returns(Vonage::Error)
         | 
| 19 | 
            -
                end
         | 
| 9 | 
            +
                sig {params(response: T.any(Net::HTTPUnauthorized, Net::HTTPClientError, Net::HTTPServerError, T.untyped)).returns(Vonage::Error)}
         | 
| 20 10 | 
             
                def self.parse(response)
         | 
| 21 | 
            -
                  exception_class =
         | 
| 22 | 
            -
                    case response
         | 
| 11 | 
            +
                  exception_class = case response
         | 
| 23 12 | 
             
                    when Net::HTTPUnauthorized
         | 
| 24 13 | 
             
                      AuthenticationError
         | 
| 25 14 | 
             
                    when Net::HTTPClientError
         | 
| @@ -27,40 +16,34 @@ module Vonage | |
| 27 16 | 
             
                    when Net::HTTPServerError
         | 
| 28 17 | 
             
                      ServerError
         | 
| 29 18 | 
             
                    else
         | 
| 30 | 
            -
                       | 
| 19 | 
            +
                      Error
         | 
| 31 20 | 
             
                    end
         | 
| 32 21 |  | 
| 33 | 
            -
                  message = response.content_type | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
                    hash | 
| 43 | 
            -
             | 
| 44 | 
            -
                     | 
| 45 | 
            -
                  elsif hash.key?("description")
         | 
| 46 | 
            -
                    hash["description"]
         | 
| 47 | 
            -
                  elsif hash.key?("message")
         | 
| 48 | 
            -
                    hash["message"]
         | 
| 49 | 
            -
                  elsif problem_details?(hash)
         | 
| 50 | 
            -
                    problem_details_message(hash)
         | 
| 51 | 
            -
                  else
         | 
| 52 | 
            -
                    ""
         | 
| 22 | 
            +
                  message = if response.content_type == 'application/json'
         | 
| 23 | 
            +
                    hash = ::JSON.parse(response.body)
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                    if hash.key?('error_title')
         | 
| 26 | 
            +
                      hash['error_title']
         | 
| 27 | 
            +
                    elsif hash.key?('error-code-label')
         | 
| 28 | 
            +
                      hash['error-code-label']
         | 
| 29 | 
            +
                    elsif hash.key?('description')
         | 
| 30 | 
            +
                      hash['description']
         | 
| 31 | 
            +
                    elsif problem_details?(hash)
         | 
| 32 | 
            +
                      problem_details_message(hash)
         | 
| 33 | 
            +
                    end
         | 
| 53 34 | 
             
                  end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                  exception_class.new(message)
         | 
| 54 37 | 
             
                end
         | 
| 55 38 |  | 
| 56 39 | 
             
                sig { params(hash: T::Hash[String, T.untyped]).returns(T::Boolean) }
         | 
| 57 40 | 
             
                def self.problem_details?(hash)
         | 
| 58 | 
            -
                  hash.key?( | 
| 41 | 
            +
                  hash.key?('title') && hash.key?('detail') && hash.key?('type')
         | 
| 59 42 | 
             
                end
         | 
| 60 43 |  | 
| 61 44 | 
             
                sig { params(hash: T::Hash[String, T.untyped]).returns(String) }
         | 
| 62 45 | 
             
                def self.problem_details_message(hash)
         | 
| 63 | 
            -
                  "#{hash[ | 
| 46 | 
            +
                  "#{hash['title']}. #{hash['detail']} See #{hash['type']} for more info, or email support@nexmo.com if you have any questions."
         | 
| 64 47 | 
             
                end
         | 
| 65 48 | 
             
              end
         | 
| 66 49 |  | 
    
        data/lib/vonage/gsm7.rb
    CHANGED
    
    | @@ -4,7 +4,7 @@ module Vonage | |
| 4 4 | 
             
              module GSM7
         | 
| 5 5 | 
             
                extend T::Sig
         | 
| 6 6 |  | 
| 7 | 
            -
                CHARACTERS = "\n\f\r !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_abcdefghijklmnopqrstuvwxyz{|}~  | 
| 7 | 
            +
                CHARACTERS = "\n\f\r !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_abcdefghijklmnopqrstuvwxyz{|}~ ¡£¤¥§¿ÄÅÆÉÑÖØÜßàäåæçèéìñòöøùüΓΔΘΛΞΠΣΦΨΩ€"
         | 
| 8 8 |  | 
| 9 9 | 
             
                REGEXP = /\A[#{Regexp.escape(CHARACTERS)}]*\z/
         | 
| 10 10 |  | 
    
        data/lib/vonage/jwt.rb
    CHANGED
    
    | @@ -39,22 +39,5 @@ module Vonage | |
| 39 39 | 
             
                  payload[:private_key] = private_key if private_key && !payload[:private_key]
         | 
| 40 40 | 
             
                  @token = Vonage::JWTBuilder.new(payload).jwt.generate
         | 
| 41 41 | 
             
                end
         | 
| 42 | 
            -
             | 
| 43 | 
            -
                # Validate a JSON Web Token from a Vonage Webhook.
         | 
| 44 | 
            -
                #
         | 
| 45 | 
            -
                # Certain Vonage APIs include a JWT signed with a user's account signature secret in
         | 
| 46 | 
            -
                # the Authorization header of Webhook requests. This method can be used to verify that those requests originate
         | 
| 47 | 
            -
                # from the Vonage API.
         | 
| 48 | 
            -
                #
         | 
| 49 | 
            -
                # @param [String, required] :token The JWT from the Webhook's Authorization header
         | 
| 50 | 
            -
                # @param [String, required] :signature_secret The account signature secret
         | 
| 51 | 
            -
                #
         | 
| 52 | 
            -
                # @return [Boolean] true, if the JWT is verified, false otherwise
         | 
| 53 | 
            -
                #
         | 
| 54 | 
            -
                # @see https://developer.vonage.com/en/getting-started/concepts/webhooks#decoding-signed-webhooks
         | 
| 55 | 
            -
                #
         | 
| 56 | 
            -
                def self.verify_hs256_signature(token:, signature_secret:)
         | 
| 57 | 
            -
                  verify_signature(token, signature_secret, 'HS256')
         | 
| 58 | 
            -
                end
         | 
| 59 42 | 
             
              end
         | 
| 60 43 | 
             
            end
         | 
    
        data/lib/vonage/keys.rb
    CHANGED
    
    
    
        data/lib/vonage/logger.rb
    CHANGED
    
    | @@ -7,11 +7,7 @@ module Vonage | |
| 7 7 | 
             
              class Logger
         | 
| 8 8 | 
             
                extend T::Sig
         | 
| 9 9 |  | 
| 10 | 
            -
                sig { params(logger: T.nilable(
         | 
| 11 | 
            -
                  defined?(ActiveSupport::BroadcastLogger) ?
         | 
| 12 | 
            -
                    T.any(::Logger, Vonage::Logger, ActiveSupport::BroadcastLogger)
         | 
| 13 | 
            -
                  : T.any(::Logger, Vonage::Logger)
         | 
| 14 | 
            -
                )).void }
         | 
| 10 | 
            +
                sig { params(logger: T.nilable(T.any(::Logger, Vonage::Logger))).void }
         | 
| 15 11 | 
             
                def initialize(logger)
         | 
| 16 12 | 
             
                  @logger = logger || ::Logger.new(nil)
         | 
| 17 13 | 
             
                end
         | 
| @@ -24,6 +20,8 @@ module Vonage | |
| 24 20 |  | 
| 25 21 | 
             
                sig { params(request: T.any(Net::HTTP::Post, Net::HTTP::Get, Net::HTTP::Delete, Net::HTTP::Put, Net::HTTP::Patch)).void }
         | 
| 26 22 | 
             
                def log_request_info(request)
         | 
| 23 | 
            +
                  @logger = T.let(@logger, T.nilable(T.any(::Logger, Vonage::Logger)))
         | 
| 24 | 
            +
             | 
| 27 25 | 
             
                  T.must(@logger).info do
         | 
| 28 26 | 
             
                    format('Vonage API request', {
         | 
| 29 27 | 
             
                      method: request.method,
         | 
| @@ -2,7 +2,7 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            module Vonage
         | 
| 4 4 | 
             
              class Messaging::Channels::Viber  < Messaging::Message
         | 
| 5 | 
            -
                MESSAGE_TYPES = ['text', 'image' | 
| 5 | 
            +
                MESSAGE_TYPES = ['text', 'image']
         | 
| 6 6 |  | 
| 7 7 | 
             
                attr_reader :data
         | 
| 8 8 |  | 
| @@ -33,13 +33,6 @@ module Vonage | |
| 33 33 | 
             
                  when 'image'
         | 
| 34 34 | 
             
                    raise Vonage::ClientError.new(":message must be a Hash") unless message.is_a? Hash
         | 
| 35 35 | 
             
                    raise Vonage::ClientError.new(":url is required in :message") unless message[:url]
         | 
| 36 | 
            -
                  when 'video'
         | 
| 37 | 
            -
                    raise Vonage::ClientError.new(":message must be a Hash") unless message.is_a? Hash
         | 
| 38 | 
            -
                    raise Vonage::ClientError.new(":url is required in :message") unless message[:url]
         | 
| 39 | 
            -
                    raise Vonage::ClientError.new(":thumb_url is required in :message") unless message[:thumb_url]
         | 
| 40 | 
            -
                  when 'file'
         | 
| 41 | 
            -
                    raise Vonage::ClientError.new(":message must be a Hash") unless message.is_a? Hash
         | 
| 42 | 
            -
                    raise Vonage::ClientError.new(":url is required in :message") unless message[:url]
         | 
| 43 36 | 
             
                  end
         | 
| 44 37 | 
             
                end
         | 
| 45 38 | 
             
              end
         | 
| @@ -2,7 +2,7 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            module Vonage
         | 
| 4 4 | 
             
              class Messaging::Channels::WhatsApp < Messaging::Message
         | 
| 5 | 
            -
                MESSAGE_TYPES = ['text', 'image', 'audio', 'video', 'file', 'template', ' | 
| 5 | 
            +
                MESSAGE_TYPES = ['text', 'image', 'audio', 'video', 'file', 'template', 'custom']
         | 
| 6 6 |  | 
| 7 7 | 
             
                attr_reader :data
         | 
| 8 8 |  | 
| @@ -35,8 +35,6 @@ module Vonage | |
| 35 35 | 
             
                    raise Vonage::ClientError.new(":name is required in :template") unless message[:name]
         | 
| 36 36 | 
             
                    raise Vonage::ClientError.new(":whatsapp is required in :opts") unless opts[:whatsapp]
         | 
| 37 37 | 
             
                    raise Vonage::ClientError.new(":locale is required in :whatsapp") unless opts[:whatsapp][:locale]
         | 
| 38 | 
            -
                  when 'sticker'
         | 
| 39 | 
            -
                    raise Vonage::ClientError.new(":message must contain either :id or :url") unless message.has_key?(:id) ^ message.has_key?(:url)
         | 
| 40 38 | 
             
                  when 'custom'
         | 
| 41 39 | 
             
                    raise Vonage::ClientError.new(":message must be a Hash") unless message.is_a? Hash
         | 
| 42 40 | 
             
                  else
         | 
    
        data/lib/vonage/messaging.rb
    CHANGED
    
    | @@ -25,16 +25,5 @@ module Vonage | |
| 25 25 | 
             
                def send(params)
         | 
| 26 26 | 
             
                  request('/v1/messages', params: params, type: Post)
         | 
| 27 27 | 
             
                end
         | 
| 28 | 
            -
             | 
| 29 | 
            -
                # Validate a JSON Web Token from a Messages API Webhook.
         | 
| 30 | 
            -
                #
         | 
| 31 | 
            -
                # @param [String, required] :token The JWT from the Webhook's Authorization header
         | 
| 32 | 
            -
                # @param [String, optional] :signature_secret The account signature secret. Required, unless `signature_secret`
         | 
| 33 | 
            -
                #   is set in `Config`
         | 
| 34 | 
            -
                #
         | 
| 35 | 
            -
                # @return [Boolean] true, if the JWT is verified, false otherwise
         | 
| 36 | 
            -
                def verify_webhook_token(token:, signature_secret: @config.signature_secret)
         | 
| 37 | 
            -
                  JWT.verify_hs256_signature(token: token, signature_secret: signature_secret)
         | 
| 38 | 
            -
                end
         | 
| 39 28 | 
             
              end
         | 
| 40 29 | 
             
            end
         | 
    
        data/lib/vonage/namespace.rb
    CHANGED
    
    | @@ -1,8 +1,6 @@ | |
| 1 1 | 
             
            # typed: true
         | 
| 2 2 | 
             
            # frozen_string_literal: true
         | 
| 3 | 
            -
             | 
| 4 3 | 
             
            require 'net/http'
         | 
| 5 | 
            -
            require 'net/http/post/multipart'
         | 
| 6 4 | 
             
            require 'json'
         | 
| 7 5 |  | 
| 8 6 | 
             
            module Vonage
         | 
| @@ -23,7 +21,8 @@ module Vonage | |
| 23 21 | 
             
                end
         | 
| 24 22 |  | 
| 25 23 | 
             
                def self.host=(host)
         | 
| 26 | 
            -
                  raise ArgumentError unless  | 
| 24 | 
            +
                  raise ArgumentError unless host == :rest_host || host == :video_host
         | 
| 25 | 
            +
             | 
| 27 26 | 
             
                  @host = host
         | 
| 28 27 | 
             
                end
         | 
| 29 28 |  | 
| @@ -48,7 +47,6 @@ module Vonage | |
| 48 47 | 
             
                end
         | 
| 49 48 |  | 
| 50 49 | 
             
                protected
         | 
| 51 | 
            -
             | 
| 52 50 | 
             
                # :nocov:
         | 
| 53 51 |  | 
| 54 52 | 
             
                Get = Net::HTTP::Get
         | 
| @@ -61,7 +59,7 @@ module Vonage | |
| 61 59 | 
             
                  authentication = self.class.authentication.new(@config)
         | 
| 62 60 | 
             
                  authentication.update(params)
         | 
| 63 61 |  | 
| 64 | 
            -
                  uri = URI( | 
| 62 | 
            +
                  uri = URI('https://' + @host + path)
         | 
| 65 63 | 
             
                  unless type.const_get(:REQUEST_HAS_BODY) || params.empty?
         | 
| 66 64 | 
             
                    uri.query = Params.encode(params)
         | 
| 67 65 | 
             
                  end
         | 
| @@ -73,20 +71,17 @@ module Vonage | |
| 73 71 | 
             
                  request = type.new(uri)
         | 
| 74 72 |  | 
| 75 73 | 
             
                  # set headers
         | 
| 76 | 
            -
                  request[ | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 80 | 
            -
                   | 
| 81 | 
            -
                  self.class.request_headers.each { |key, value| request[key] = value }
         | 
| 74 | 
            +
                  request['User-Agent'] = UserAgent.string(@config.app_name, @config.app_version)
         | 
| 75 | 
            +
                  request['Accept'] = 'application/json'
         | 
| 76 | 
            +
                  self.class.request_headers.each do |key, value|
         | 
| 77 | 
            +
                    request[key] = value
         | 
| 78 | 
            +
                  end
         | 
| 82 79 |  | 
| 83 80 | 
             
                  # Set BearerToken if needed
         | 
| 84 81 | 
             
                  authentication.update(request)
         | 
| 85 82 |  | 
| 86 83 | 
             
                  # set body
         | 
| 87 | 
            -
                  if type.const_get(:REQUEST_HAS_BODY)
         | 
| 88 | 
            -
                    self.class.request_body.update(request, params)
         | 
| 89 | 
            -
                  end
         | 
| 84 | 
            +
                  self.class.request_body.update(request, params) if type.const_get(:REQUEST_HAS_BODY)
         | 
| 90 85 |  | 
| 91 86 | 
             
                  request
         | 
| 92 87 | 
             
                end
         | 
| @@ -106,31 +101,16 @@ module Vonage | |
| 106 101 | 
             
                end
         | 
| 107 102 |  | 
| 108 103 | 
             
                def request(path, params: nil, type: Get, response_class: Response, &block)
         | 
| 109 | 
            -
                  auto_advance =
         | 
| 110 | 
            -
             | 
| 111 | 
            -
             | 
| 112 | 
            -
                        params[:auto_advance]
         | 
| 113 | 
            -
                      else
         | 
| 114 | 
            -
                        false
         | 
| 115 | 
            -
                      end
         | 
| 116 | 
            -
                    )
         | 
| 117 | 
            -
             | 
| 118 | 
            -
                  params =
         | 
| 119 | 
            -
                    params.tap { |params| params.delete(:auto_advance) } if !params.nil? &&
         | 
| 120 | 
            -
                    params.key?(:auto_advance)
         | 
| 104 | 
            +
                  auto_advance = !params.nil? && params.key?(:auto_advance) ? params[:auto_advance] : false
         | 
| 105 | 
            +
             | 
| 106 | 
            +
                  params = params.tap { |params| params.delete(:auto_advance) } if !params.nil? && params.key?(:auto_advance)
         | 
| 121 107 |  | 
| 122 108 | 
             
                  request = build_request(path: path, params: params || {}, type: type)
         | 
| 123 109 |  | 
| 124 110 | 
             
                  response = make_request!(request, &block)
         | 
| 125 111 |  | 
| 126 112 | 
             
                  if auto_advance
         | 
| 127 | 
            -
                    iterable_request(
         | 
| 128 | 
            -
                      path,
         | 
| 129 | 
            -
                      response: response,
         | 
| 130 | 
            -
                      response_class: response_class,
         | 
| 131 | 
            -
                      params: params,
         | 
| 132 | 
            -
                      &block
         | 
| 133 | 
            -
                    )
         | 
| 113 | 
            +
                    iterable_request(path, response: response, response_class: response_class, params: params, &block)
         | 
| 134 114 | 
             
                  else
         | 
| 135 115 | 
             
                    return if block
         | 
| 136 116 |  | 
| @@ -138,59 +118,22 @@ module Vonage | |
| 138 118 | 
             
                  end
         | 
| 139 119 | 
             
                end
         | 
| 140 120 |  | 
| 141 | 
            -
                def multipart_post_request(path, filepath:, file_name:, mime_type:, params: {}, override_uri: nil, no_auth: false, response_class: Response, &block)
         | 
| 142 | 
            -
                  authentication = self.class.authentication.new(@config) unless no_auth
         | 
| 143 | 
            -
             | 
| 144 | 
            -
                  uri = override_uri ? URI(override_uri) : URI('https://' + @host + path)
         | 
| 145 | 
            -
             | 
| 146 | 
            -
                  http = override_uri ? Net::HTTP.new(uri.host, Net::HTTP.https_default_port, p_addr = nil) : @http
         | 
| 147 | 
            -
                  http.use_ssl = true
         | 
| 148 | 
            -
                  http.set_debug_output($stdout)
         | 
| 149 | 
            -
             | 
| 150 | 
            -
                  response = File.open(filepath) do |file|
         | 
| 151 | 
            -
                    request = Net::HTTP::Post::Multipart.new(
         | 
| 152 | 
            -
                      uri,
         | 
| 153 | 
            -
                      params.merge(file: Multipart::Post::UploadIO.new(file, mime_type, file_name))
         | 
| 154 | 
            -
                    )
         | 
| 155 | 
            -
             | 
| 156 | 
            -
                    request['User-Agent'] = UserAgent.string(@config.app_name, @config.app_version)
         | 
| 157 | 
            -
             | 
| 158 | 
            -
                    # Set BearerToken if needed
         | 
| 159 | 
            -
                    authentication.update(request) unless no_auth
         | 
| 160 | 
            -
             | 
| 161 | 
            -
                    logger.log_request_info(request)
         | 
| 162 | 
            -
             | 
| 163 | 
            -
                    http.request(request, &block)
         | 
| 164 | 
            -
                  end
         | 
| 165 | 
            -
             | 
| 166 | 
            -
                  logger.log_response_info(response, @host)
         | 
| 167 | 
            -
             | 
| 168 | 
            -
                  return if block
         | 
| 169 | 
            -
             | 
| 170 | 
            -
                  logger.debug(response.body) if response.body
         | 
| 171 | 
            -
             | 
| 172 | 
            -
                  parse(response, response_class)
         | 
| 173 | 
            -
                end
         | 
| 174 | 
            -
             | 
| 175 121 | 
             
                def iterable_request(path, response: nil, response_class: nil, params: {}, &block)
         | 
| 176 122 | 
             
                  json_response = ::JSON.parse(response.body)
         | 
| 177 123 | 
             
                  response = parse(response, response_class)
         | 
| 178 124 | 
             
                  remainder = remaining_count(json_response)
         | 
| 179 125 |  | 
| 180 126 | 
             
                  while remainder > 0
         | 
| 181 | 
            -
                    params = { page_size: json_response[ | 
| 182 | 
            -
             | 
| 183 | 
            -
                    if json_response[ | 
| 184 | 
            -
                      params[:record_index] = json_response[ | 
| 185 | 
            -
                    elsif json_response[ | 
| 186 | 
            -
             | 
| 187 | 
            -
                      params[:record_index] = (
         | 
| 188 | 
            -
                        json_response["record_index"] + json_response["page_size"]
         | 
| 189 | 
            -
                      )
         | 
| 127 | 
            +
                    params = { page_size: json_response['page_size'] }
         | 
| 128 | 
            +
             | 
| 129 | 
            +
                    if json_response['record_index'] && json_response['record_index'] == 0
         | 
| 130 | 
            +
                      params[:record_index] = json_response['page_size']
         | 
| 131 | 
            +
                    elsif json_response['record_index'] && json_response['record_index'] != 0
         | 
| 132 | 
            +
                      params[:record_index] = (json_response['record_index'] + json_response['page_size'])
         | 
| 190 133 | 
             
                    end
         | 
| 191 134 |  | 
| 192 | 
            -
                    if json_response[ | 
| 193 | 
            -
                      params[:page] = json_response[ | 
| 135 | 
            +
                    if json_response['total_pages']
         | 
| 136 | 
            +
                      params[:page] = json_response['page'] + 1
         | 
| 194 137 | 
             
                    end
         | 
| 195 138 |  | 
| 196 139 | 
             
                    request = build_request(path: path, type: Get, params: params)
         | 
| @@ -201,15 +144,11 @@ module Vonage | |
| 201 144 | 
             
                    json_response = ::JSON.parse(paginated_response.body)
         | 
| 202 145 | 
             
                    remainder = remaining_count(json_response)
         | 
| 203 146 |  | 
| 204 | 
            -
                    if response.respond_to?( | 
| 205 | 
            -
                      collection_name = collection_name(response[ | 
| 206 | 
            -
                      response[ | 
| 207 | 
            -
                        *next_response["_embedded"][collection_name]
         | 
| 208 | 
            -
                      )
         | 
| 147 | 
            +
                    if response.respond_to?('_embedded')
         | 
| 148 | 
            +
                      collection_name = collection_name(response['_embedded'])
         | 
| 149 | 
            +
                      response['_embedded'][collection_name].push(*next_response['_embedded'][collection_name])
         | 
| 209 150 | 
             
                    else
         | 
| 210 | 
            -
                      response[collection_name(response)].push(
         | 
| 211 | 
            -
                        *next_response[collection_name(next_response)]
         | 
| 212 | 
            -
                      )
         | 
| 151 | 
            +
                      response[collection_name(response)].push(*next_response[collection_name(next_response)])
         | 
| 213 152 | 
             
                    end
         | 
| 214 153 | 
             
                  end
         | 
| 215 154 |  | 
| @@ -217,51 +156,43 @@ module Vonage | |
| 217 156 | 
             
                end
         | 
| 218 157 |  | 
| 219 158 | 
             
                def remaining_count(params)
         | 
| 220 | 
            -
                  if params.key?( | 
| 221 | 
            -
                    params[ | 
| 222 | 
            -
                  elsif params.key?( | 
| 223 | 
            -
                    params[ | 
| 224 | 
            -
                      (
         | 
| 225 | 
            -
                        if params["record_index"] == 0
         | 
| 226 | 
            -
                          params["page_size"]
         | 
| 227 | 
            -
                        else
         | 
| 228 | 
            -
                          (params["record_index"] + params["page_size"])
         | 
| 229 | 
            -
                        end
         | 
| 230 | 
            -
                      )
         | 
| 159 | 
            +
                  if params.key?('total_pages')
         | 
| 160 | 
            +
                    params['total_pages'] - params['page']
         | 
| 161 | 
            +
                  elsif params.key?('count')
         | 
| 162 | 
            +
                    params['count'] - (params['record_index'] == 0 ? params['page_size'] : (params['record_index'] + params['page_size']))
         | 
| 231 163 | 
             
                  else
         | 
| 232 164 | 
             
                    0
         | 
| 233 165 | 
             
                  end
         | 
| 234 166 | 
             
                end
         | 
| 235 167 |  | 
| 236 168 | 
             
                def collection_name(params)
         | 
| 237 | 
            -
                  @collection_name ||=
         | 
| 238 | 
            -
                     | 
| 239 | 
            -
             | 
| 240 | 
            -
             | 
| 241 | 
            -
             | 
| 242 | 
            -
             | 
| 243 | 
            -
             | 
| 244 | 
            -
             | 
| 245 | 
            -
             | 
| 246 | 
            -
             | 
| 247 | 
            -
             | 
| 248 | 
            -
             | 
| 249 | 
            -
             | 
| 250 | 
            -
             | 
| 251 | 
            -
             | 
| 252 | 
            -
             | 
| 253 | 
            -
             | 
| 254 | 
            -
             | 
| 255 | 
            -
             | 
| 256 | 
            -
             | 
| 257 | 
            -
             | 
| 258 | 
            -
             | 
| 259 | 
            -
             | 
| 260 | 
            -
             | 
| 261 | 
            -
             | 
| 262 | 
            -
             | 
| 263 | 
            -
             | 
| 264 | 
            -
                      "events"
         | 
| 169 | 
            +
                  @collection_name ||= case
         | 
| 170 | 
            +
                    when params.respond_to?('calls')
         | 
| 171 | 
            +
                      'calls'
         | 
| 172 | 
            +
                    when params.respond_to?('users')
         | 
| 173 | 
            +
                      'users'
         | 
| 174 | 
            +
                    when params.respond_to?('legs')
         | 
| 175 | 
            +
                      'legs'
         | 
| 176 | 
            +
                    when params.respond_to?('data')
         | 
| 177 | 
            +
                      'data'
         | 
| 178 | 
            +
                    when params.respond_to?('conversations')
         | 
| 179 | 
            +
                      'conversations'
         | 
| 180 | 
            +
                    when params.respond_to?('applications')
         | 
| 181 | 
            +
                      'applications'
         | 
| 182 | 
            +
                    when params.respond_to?('records')
         | 
| 183 | 
            +
                      'records'
         | 
| 184 | 
            +
                    when params.respond_to?('reports')
         | 
| 185 | 
            +
                      'reports'
         | 
| 186 | 
            +
                    when params.respond_to?('networks')
         | 
| 187 | 
            +
                      'networks'
         | 
| 188 | 
            +
                    when params.respond_to?('countries')
         | 
| 189 | 
            +
                      'countries'
         | 
| 190 | 
            +
                    when params.respond_to?('media')
         | 
| 191 | 
            +
                      'media'
         | 
| 192 | 
            +
                    when params.respond_to?('numbers')
         | 
| 193 | 
            +
                      'numbers'
         | 
| 194 | 
            +
                    when params.respond_to?('events')
         | 
| 195 | 
            +
                      'events'
         | 
| 265 196 | 
             
                    else
         | 
| 266 197 | 
             
                      params.entity.attributes.keys[0].to_s
         | 
| 267 198 | 
             
                    end
         | 
| @@ -272,7 +203,7 @@ module Vonage | |
| 272 203 | 
             
                  when Net::HTTPNoContent
         | 
| 273 204 | 
             
                    response_class.new(nil, response)
         | 
| 274 205 | 
             
                  when Net::HTTPSuccess
         | 
| 275 | 
            -
                    if response['Content-Type'] | 
| 206 | 
            +
                    if response['Content-Type'].split(';').first == 'application/json'
         | 
| 276 207 | 
             
                      entity = ::JSON.parse(response.body, object_class: Vonage::Entity)
         | 
| 277 208 |  | 
| 278 209 | 
             
                      response_class.new(entity, response)
         | 
| @@ -296,8 +227,6 @@ module Vonage | |
| 296 227 | 
             
                    @config.rest_host
         | 
| 297 228 | 
             
                  when :video_host
         | 
| 298 229 | 
             
                    @config.video_host
         | 
| 299 | 
            -
                  when :vonage_host
         | 
| 300 | 
            -
                    @config.vonage_host
         | 
| 301 230 | 
             
                  else
         | 
| 302 231 | 
             
                    @config.api_host
         | 
| 303 232 | 
             
                  end
         |