Module: ChinaSMS::Service::Tui3

Extended by:
Tui3
Included in:
Tui3
Defined in:
lib/china_sms/service/tui3.rb

Overview

Constant Summary collapse

URL =
"http://tui3.com/api/send/"

Instance Method Summary collapse

Instance Method Details

#result(body) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/china_sms/service/tui3.rb', line 19

def result(body)
  {
    success: body['err_code'] == 0,
    code: body['err_code'],
    message: body['err_msg']
  }
end

#to(phone, content, options) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/china_sms/service/tui3.rb', line 11

def to(phone, content, options)
  phones = Array(phone).join(',')
  res = Net::HTTP.post_form(URI.parse(URL), k: options[:password], t: phones, c: content, p: 1, r: 'json')
  body = res.body
  body = "{\"err_code\": 2, \"err_msg\":\"非法apikey:#{options[:password]}\"}" if body == 'invalid parameters'
  result JSON[body]
end