Module: ChinaSMS::Service::Emay

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

Constant Summary collapse

URL =
"http://sdkhttp.eucp.b2m.cn/sdkproxy"

Instance Method Summary collapse

Instance Method Details

#get(options) ⇒ Object



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

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

#result(body) ⇒ Object



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

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

#to(phone, content, options) ⇒ Object



8
9
10
11
12
# File 'lib/china_sms/service/emay.rb', line 8

def to(phone, content, options)
  phones = Array(phone).join(',')
  res = Net::HTTP.post_form(URI.parse("#{URL}/sendsms.action"), cdkey: options[:username], password: options[:password], phone: phones, message: content)
  result res.body
end