Module: ChinaSMS::Service::Emay

Extended by:
Emay
Included in:
Emay
Defined in:
lib/china_sms/service/emay.rb

Constant Summary collapse

SEND_URL =
"http://sdkhttp.eucp.b2m.cn/sdkproxy/sendsms.action"
GET_URL =
"http://sdkhttp.eucp.b2m.cn/sdkproxy/getmo.action"

Instance Method Summary collapse

Instance Method Details

#get(options) ⇒ Object



16
17
18
19
20
21
# File 'lib/china_sms/service/emay.rb', line 16

def get(options)
  # res = Net::HTTP.post_form(URI.parse(GET_URL), cdkey: options[:username], password: options[:password])
  url = GET_URL + "?cdkey=#{options[:username]}&password=#{options[:password]}"
  res = Net::HTTP.get(URI.parse(url))
  res.body
end

#result(body) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/china_sms/service/emay.rb', line 23

def result(body)
  code = body.match(/.+error>(.+)\<\/error/)[1]
  {
    success: (code.to_i >= 0),
    code: code
  }
end

#to(phone, content, options) ⇒ Object



10
11
12
13
14
# File 'lib/china_sms/service/emay.rb', line 10

def to(phone, content, options)
  phones = Array(phone).join(',')
  res = Net::HTTP.post_form(URI.parse(SEND_URL), cdkey: options[:username], password: options[:password], phone: phones, message: content)
  result res.body
end