Module: EmaySms

Defined in:
lib/emay_sms.rb,
lib/emay_sms/version.rb,
lib/emay_sms/configuration.rb

Defined Under Namespace

Classes: Configuration

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.activeObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/emay_sms.rb', line 35

def active
  response = client.call(:regist_ex, message: { arg0: EmaySms.config., 
                                                arg1: EmaySms.config.secret, 
                                                arg2: EmaySms.config.password })
  if response.body[:regist_ex_response].nil? || response.body[:regist_ex_response][:return] != "0"
    return false
  else
    return true
  end
end

.clientObject



20
21
22
23
24
25
# File 'lib/emay_sms.rb', line 20

def client
  @client ||= Savon.client(wsdl: EmaySms.config.server, 
                            log: true,
                      log_level: :debug,
               pretty_print_xml: true)
end

.configObject



12
13
14
# File 'lib/emay_sms.rb', line 12

def config
  @config ||= Configuration.new
end

.loggerObject



16
17
18
# File 'lib/emay_sms.rb', line 16

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

.register(hash = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/emay_sms.rb', line 46

def register(hash = {})
  response = client.call(:regist_detail_info, message: { arg0: EmaySms.config., 
                                                         arg1: EmaySms.config.secret, 
                                                         arg2: hash[:name],
                                                         arg3: hash[:contact],
                                                         arg4: hash[:phone_number],
                                                         arg5: hash[:mobile],
                                                         arg6: hash[:email],
                                                         arg7: hash[:fax],
                                                         arg8: hash[:address],
                                                         arg9: hash[:post_code]})
  if response.body[:regist_detail_info_response].nil? || response.body[:regist_detail_info_response][:return] != "0"
    return false
  else
    return true
  end
end

.send(message, mobiles = [], sign = nil) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/emay_sms.rb', line 64

def send(message, mobiles = [], sign = nil)
  response = client.call(:send_sms, message: { arg0: EmaySms.config.,
                                               arg1: EmaySms.config.secret,
                                               arg2: "",
                                               arg3: mobiles,
                                               arg4: EmaySms.sign_message(message, sign),
                                               arg5: "",
                                               arg6: "UTF-8",
                                               arg7: 1,
                                               arg8: 0 })
  if response.body[:send_sms_response].nil? || response.body[:send_sms_response][:return] != "0"
    return false
  else
    return true
  end
end

.setup {|config| ... } ⇒ Object

Yields:



8
9
10
# File 'lib/emay_sms.rb', line 8

def setup
  yield config
end

.sign_message(message, sign = nil) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/emay_sms.rb', line 27

def sign_message(message, sign = nil)
  if sign.nil?
    "#{EmaySms.config.sign}#{message}"
  else
    "#{sign}#{message}"
  end
end