Module: RocketSMS

Extended by:
RocketSMS
Included in:
RocketSMS
Defined in:
lib/rocket_sms.rb,
lib/rocket_sms/did.rb,
lib/rocket_sms/gateway.rb,
lib/rocket_sms/message.rb,
lib/rocket_sms/version.rb,
lib/rocket_sms/scheduler.rb,
lib/rocket_sms/transceiver.rb

Defined Under Namespace

Classes: Did, Gateway, Message, Scheduler, Transceiver

Constant Summary collapse

LIB_PATH =
File.dirname(__FILE__) + '/rocket_sms/'
VERSION =
"0.1.1"

Instance Method Summary collapse

Instance Method Details

#configure {|_self| ... } ⇒ Object

Configuration and Setup

Yields:

  • (_self)

Yield Parameters:

  • _self (RocketSMS)

    the object that the method was called on



62
63
64
# File 'lib/rocket_sms.rb', line 62

def configure
  yield self
end

#gatewayObject



53
54
55
# File 'lib/rocket_sms.rb', line 53

def gateway
  @gateway ||= RocketSMS::Gateway.instance
end

#log_locationObject



88
89
90
# File 'lib/rocket_sms.rb', line 88

def log_location
  @log_location ||= STDOUT
end

#log_location=(location) ⇒ Object



92
93
94
# File 'lib/rocket_sms.rb', line 92

def log_location=(location)
  @log_location = location unless location.nil?
end

#loggerObject



84
85
86
# File 'lib/rocket_sms.rb', line 84

def logger
  @logger ||= Logger.new(log_location)
end

#queuesObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rocket_sms.rb', line 41

def queues
  @queues ||= {
    mt: {
      pending: 'gateway:queues:mt:pending',
      success: 'gateway:queues:mt:success',
      failure: 'gateway:queues:mt:failure'
    },
    mo: 'gateway:queues:mo:received',
    dr: 'gateway:queues:dr'
  }
end

#redisObject



57
58
59
# File 'lib/rocket_sms.rb', line 57

def redis
  @redis ||= EM::Hiredis.connect(redis_url)
end

#redis_urlObject



76
77
78
# File 'lib/rocket_sms.rb', line 76

def redis_url
  @redis_url ||= "redis://localhost:6379"
end

#redis_url=(url) ⇒ Object



80
81
82
# File 'lib/rocket_sms.rb', line 80

def redis_url=(url)
  @redis_url = url unless url.nil?
end

#settingsObject



72
73
74
# File 'lib/rocket_sms.rb', line 72

def settings
  @settings
end

#settings=(yaml_file_location) ⇒ Object



66
67
68
69
70
# File 'lib/rocket_sms.rb', line 66

def settings=(yaml_file_location)
  @settings = symbolize_keys(YAML.load(IO.read(yaml_file_location)))
  redis_url = @settings[:redis] && @settings[:redis][:url]
  log_location = @settings[:log] && @settings[:log][:location]
end

#startObject



35
36
37
38
39
# File 'lib/rocket_sms.rb', line 35

def start
  @pid = Process.pid
  #Process.daemon
  gateway.start
end

#symbolize_keys(hash) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/rocket_sms.rb', line 96

def symbolize_keys(hash)
  hash.inject({}){|result, (key, value)|
    new_key = case key
              when String then key.to_sym
              else key
              end
    new_value = case value
                when Hash then symbolize_keys(value)
                else value
                end
    result[new_key] = new_value
    result
  }
end