Class: JPush::Report

Inherits:
Handler show all
Defined in:
lib/jpush/report.rb

Constant Summary collapse

TIME_UNIT =
['HOUR', 'DAY', 'MONTH']
TIME_FORMAT =
{ hour: '%F %H', day: '%F', month: '%Y-%m' }
MAX_DURATION =
{ hour: 24, day: 60, month: 2 }

Instance Method Summary collapse

Methods inherited from Handler

#initialize

Constructor Details

This class inherits a constructor from JPush::Handler

Instance Method Details

#messages(msg_ids) ⇒ Object

GET /v3/messages 消息统计



51
52
53
54
55
56
57
58
# File 'lib/jpush/report.rb', line 51

def messages(msg_ids)
  msg_ids = [msg_ids].flatten
  url = base_url + '/messages'
  params = {
    msg_ids: msg_ids.join(',')
  }
  Http::Client.get(@jpush, url, params: params)
end

#messages_detail(msg_ids) ⇒ Object

GET /v3/messages/detail 消息统计详情(VIP 专属接口,新) docs.jiguang.cn/jpush/server/push/rest_api_v3_report/#vip_1



63
64
65
66
67
68
69
70
# File 'lib/jpush/report.rb', line 63

def messages_detail(msg_ids)
  msg_ids = [msg_ids].flatten
  url = base_url + '/messages/detail'
  params = {
    msg_ids: msg_ids.join(',')
  }
  Http::Client.get(@jpush, url, params: params)
end

#received(msg_ids) ⇒ Object

GET /v3/received 送达统计



13
14
15
16
17
18
19
20
# File 'lib/jpush/report.rb', line 13

def received(msg_ids)
  msg_ids = [msg_ids].flatten
  url = base_url + '/received'
  params = {
    msg_ids: msg_ids.join(',')
  }
  Http::Client.get(@jpush, url, params: params)
end

#received_detail(msg_ids) ⇒ Object

GET /v3/received/detail 送达统计 docs.jiguang.cn/jpush/server/push/rest_api_v3_report/#_7



25
26
27
28
29
30
31
32
# File 'lib/jpush/report.rb', line 25

def received_detail(msg_ids)
  msg_ids = [msg_ids].flatten
  url = base_url + '/received/detail'
  params = {
    msg_ids: msg_ids.join(',')
  }
  Http::Client.get(@jpush, url, params: params)
end

#status_message(msg_id:, registration_ids:, date: nil) ⇒ Object

GET /v3/status/message 送达状态查询 Status API 用于查询已推送的一条消息在一组设备上的送达状态。 docs.jiguang.cn/jpush/server/push/rest_api_v3_report/#_11



38
39
40
41
42
43
44
45
46
47
# File 'lib/jpush/report.rb', line 38

def status_message(msg_id: , registration_ids: , date: nil)
  registration_ids = [registration_ids].flatten
  url = base_url + 'status/message'
  body = {
    msg_id: msg_id.to_i,
    registration_ids: registration_ids,
    date: date
  }.select { |_, value| !value.nil? }
  Http::Client.post(@jpush, url, body: body)
end

#users(time_unit, start, duration) ⇒ Object

GET /v3/users 用户统计



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/jpush/report.rb', line 74

def users(time_unit, start, duration)
  start = start.strftime(TIME_FORMAT[time_unit.downcase.to_sym])
  duration = build_duration(time_unit.downcase.to_sym, duration)
  params = {
    time_unit: time_unit.upcase,
    start: start,
    duration: duration
  }
  url = base_url + '/users'
  Http::Client.get(@jpush, url, params: params)
end