Sha256: efccbf298f006511d823ea07fa30a7f9d27b412d799a43db311e201dbe8517b4

Contents?: true

Size: 1.19 KB

Versions: 4

Compression:

Stored size: 1.19 KB

Contents

module Connfu

  module Provisioning

    #
    # connFu Dtmf press key (belongs to a Voice channel)
    #
    class Dtmf

      # tone
      attr_accessor :tone

      # message
      attr_accessor :message

      # voice channel unique identifier
      attr_reader :voice

      # @param voice voice channel identifier
      # @param tone
      # @param message
      def initialize(voice, tone, message = "")
        @voice = voice
        @tone = tone
        @message = message
      end
      
      # Hash way to retrieve attributes
      def [](value)
        self.respond_to?(value.to_sym) ? self.send(value.to_sym) : nil
      end

      def to_hash
        {"tone" => tone, "message" => message}
      end

      def to_s
        "#{self.class.to_s}: #{to_hash}"
      end

      #
      # Creates a Dtmf object using the raw data from the provisioning API
      # @param voice channel unique identifier
      # @param data Hash containing the raw data
      def self.unmarshal(voice, data)
        if data.is_a?(Array)
          data.map{|item| Dtmf.new(voice, item["tone"], item["message"])}
        else
          Dtmf.new(voice, data["tone"], data["message"])
        end
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
connfu-client-0.1.6 lib/connfu/provisioning/dtmf.rb
connfu-client-0.1.5 lib/connfu/provisioning/dtmf.rb
connfu-client-0.1.4 lib/connfu/provisioning/dtmf.rb
connfu-client-0.1.3 lib/connfu/provisioning/dtmf.rb