Sha256: ea1bd9904d802e386db021451fa09bc713719bfee41f5c26f8a6e89f0b4cb0a5

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

require 'httparty'

module WavecellOtpAndSms
  class SendOtp
    include HTTParty
    attr_accessor :destination, :country_code, :product_name

    # Initialize OTP parameters
    def initialize(options = {})
      @destination = options[:destination]
      @country_code = options[:country_code]
      @product_name = options[:product_name]
    end

    # Call this to generate url for the api calls
    def send
      generate_url
    end

    private
      # Construct API using the parameters and initial configuration
      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

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wavecell_otp_and_sms-1.1.0 lib/wavecell_otp_and_sms/send_otp.rb
wavecell_otp_and_sms-1.0.9 lib/wavecell_otp_and_sms/send_otp.rb
wavecell_otp_and_sms-1.0.8 lib/wavecell_otp_and_sms/send_otp.rb