Class: Vonage::SMS

Inherits:
Namespace
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/vonage/sms.rb

Instance Method Summary collapse

Instance Method Details

#send(params) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/vonage/sms.rb', line 76

def send(params)
  if unicode?(params.fetch(:text)) && params[:type] != 'unicode'
    message = 'Sending unicode text SMS without setting the type parameter to "unicode". ' \
      'See https://developer.nexmo.com/messaging/sms for details, ' \
      'or email [email protected] if you have any questions.'

    logger.warn(message)
  end

  response = request('/sms/json', params: hyphenate(params), type: Post)

  unless response.messages.first.status == '0'
    raise ServiceError.new(response: response), response.messages.first[:error_text]
  end

  response
end

#verify_webhook_sig(webhook_params:, signature_secret: @config.signature_secret, signature_method: @config.signature_method) ⇒ Boolean

Validate a Signature from an SMS API Webhook.

Parameters:

  • :webhook_params (Hash, required)

    The parameters from the webhook request body

  • :signature_secret (String, optional)

    The account signature secret. Required, unless signature_secret is set in Config

  • :signature_method (String, optional)

    The account signature method. Required, unless signature_method is set in Config

Returns:

  • (Boolean)

    true, if the JWT is verified, false otherwise



103
104
105
# File 'lib/vonage/sms.rb', line 103

def verify_webhook_sig(webhook_params:, signature_secret: @config.signature_secret, signature_method: @config.signature_method)
  signature.check(webhook_params, signature_secret: signature_secret, signature_method: signature_method)
end