Module: EmaySms

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

Defined Under Namespace

Modules: Models Classes: Configuration

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.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

.registerObject



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/emay_sms.rb', line 31

def register
  # @client.call(:regist_ex, message: { softwareSerialNo: EmaySms.config.account, 
  #                                                  key: EmaySms.config.secrect, 
  #                                           serialpass: EmaySms.config.password })
  response = client.call(:regist_ex, message: { arg0: EmaySms.config., 
                                                arg1: EmaySms.config.secrect, 
                                                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

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



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/emay_sms.rb', line 45

def send(message, mobiles = [])
  # response = @client.call(:send_sms, message: { softwareSerialNo: EmaySms.config.account,
  #                                                            key: EmaySms.config.secrect,
  #                                                       sendTime: "",
  #                                                        mobiles: mobiles,
  #                                                     smsContent: message,
  #                                                      addSerial: "",
  #                                                     srcCharset: "UTF-8",
  #                                                    smsPriority: 1,
  #                                                          smsID: 0 })
  response = client.call(:send_sms, message: { arg0: EmaySms.config.,
                                               arg1: EmaySms.config.secrect,
                                               arg2: "",
                                               arg3: mobiles,
                                               arg4: EmaySms.sign_message(message),
                                               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) ⇒ Object



27
28
29
# File 'lib/emay_sms.rb', line 27

def sign_message(message)
  "#{EmaySms.config.sign}#{message}"
end