class UmengPusher::Client
Constants
- CANCEL_URL
- CAST_TYPE
- SEND_URL
- STATUS_URL
- UPLOAD_URL
Attributes
content[R]
error_code[R]
file_id[R]
payload[R]
platform[R]
ret[R]
task_id[R]
Public Class Methods
new(platform, options, debug_mode = true)
click to toggle source
# File lib/umeng_pusher/client.rb, line 14 def initialize(platform, options, debug_mode = true) @platform = platform @options = options @debug_mode = debug_mode end
Public Instance Methods
cancel()
click to toggle source
# File lib/umeng_pusher/client.rb, line 36 def cancel post(CANCEL_URL, Params.cancel_params(@platform, @options[:task_id])) end
send()
click to toggle source
unicast-单播 listcast-列播,要求不超过500个device_token broadcast-广播 filecast-文件播,多个device_token可通过文件形式批量发送 groupcast-组播,按照filter筛选用户群,请参照filter参数 customizedcast,通过alias进行推送,包括以下两种case:
-alias:对单个或者多个alias进行推送 -file_id:将alias存放到文件后,根据file_id来推送
# File lib/umeng_pusher/client.rb, line 28 def send post(SEND_URL, Params.send_params(@platform, @options)) end
status()
click to toggle source
# File lib/umeng_pusher/client.rb, line 32 def status post(STATUS_URL, Params.status_params(@platform, @options[:task_id])) end
upload()
click to toggle source
# File lib/umeng_pusher/client.rb, line 40 def upload post(UPLOAD_URL, Params.upload_params(@platform, @options)) end
Private Instance Methods
post(url, payload)
click to toggle source
# File lib/umeng_pusher/client.rb, line 46 def post(url, payload) sign = Sign.generate @platform, url, payload puts payload.to_json if @debug_mode resp = HTTPX.post("#{url}?sign=#{sign}", json: payload) if resp.status == 200 r = JSON.parse(resp.body) { message: r["ret"], error_code: r["data"]["error_code"] || 0, data: r["data"] } elsif resp.status == 400 r = JSON.parse(resp.body) { message: r["data"]["error_msg"], error_code: r["data"]["error_code"], data: r["data"] } else { message: "系统错误", error_code: "999", data: {} } end end