class WavecellOtpAndSms::SendOtp

Attributes

country_code[RW]
destination[RW]
product_name[RW]

Public Class Methods

new(options = {}) click to toggle source

Initialize OTP parameters

# File lib/wavecell_otp_and_sms/send_otp.rb, line 9
def initialize(options = {})
  @destination = options[:destination]
  @country_code = options[:country_code]
  @product_name = options[:product_name]
end

Public Instance Methods

send() click to toggle source

Call this to generate url for the api calls

# File lib/wavecell_otp_and_sms/send_otp.rb, line 16
def send
  generate_url
end

Private Instance Methods

generate_url() click to toggle source

Construct API using the parameters and initial configuration

# File lib/wavecell_otp_and_sms/send_otp.rb, line 22
def generate_url
  api_key = WavecellOtpAndSms.configuration.api_key
  sub_account = WavecellOtpAndSms.configuration.sub_account
  details = [destination, country_code, product_name]
  parameters = {
    destination: destination,
    country_code: country_code,
    product_name: product_name
  }
  query_string = parameters.to_a.map { |x| "#{x[0]}=#{x[1]}" }.join("&")
  url = "https://api.wavecell.com/otp/v1/#{sub_account}" + "?#{query_string}"
  HTTParty.post(url.to_str,
  :body => parameters.to_json,
  :headers => {
    "Content-Type" => "application/json",
    "Authorization" => "Bearer #{api_key}"
  })
end