Sha256: 3ebf0c38c39ce2e2fb5d94486e326165e5fab799cfd4595470ed4dd299abaf96

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

# -*- coding: utf-8 -*-
module Smshelper
  module Api
    class Base
      include APISmith::Client

      attr_reader :sent_message_ids, :sent_message_statuses
      attr_accessor :extra_options
      def initialize(*args)
        @sent_message_ids, @sent_message_statuses = Array.new, Hash.new
        @response_code = ResponseCodes.new
        @extra_options = args.shift
        @uuid = UUID.new
        class_factory 'DeliveryReport', 'InboundMessage', 'UnknownReply'
      end

      protected
      def class_factory(*names)
        names.each do |name|
          klass = self.class.const_set(name, Class.new)
          klass.class_eval do
            attr_reader :uuid, :service

            define_method(:initialize) do |args = {}|
              args.each do |k,v|
                unless k.to_s =~ (/splat/ || /captures/)
                  self.class.send(:define_method, k.to_sym) {v}
                  instance_variable_set("@"+k.to_s, v)
                end
              end
              instance_variable_set("@uuid", UUID.generate)
              instance_variable_set("@service", self.class.name.split('::')[2])
            end

            #TODO: Find out why is this needed!
            define_method("_dump".to_sym) do |level|
              self.to_yaml
            end

            def self._load(str)
              YAML.load str
            end

          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
smshelper-0.4.5 lib/smshelper/api/base.rb