Class: JPush::ReportClient

Inherits:
Object
  • Object
show all
Defined in:
lib/jpush/report_client.rb

Constant Summary collapse

@@REPORT_HOST_NAME =
'https://report.jpush.cn'
@@REPORT_RECEIVE_PATH =
'/v3/received'
@@REPORT_USER_PATH =
'/v3/users'
@@REPORT_MESSAGE_PATH =
'/v3/messages'

Instance Method Summary collapse

Constructor Details

#initialize(maxRetryTimes) ⇒ ReportClient

Returns a new instance of ReportClient.


12
13
14
# File 'lib/jpush/report_client.rb', line 12

def initialize(maxRetryTimes)
  @httpclient=JPush::NativeHttpClient.new(maxRetryTimes)
end

Instance Method Details

#checkMsgids(msg_ids) ⇒ Object


41
42
43
44
45
46
47
# File 'lib/jpush/report_client.rb', line 41

def checkMsgids(msg_ids)
  if msg_ids.empty?
    raise ArgumentError.new('msgIds param is required')
  end
  msg_ids = msg_ids.split.join('').to_s
  return msg_ids
end

#getMessages(msg_ids) ⇒ Object


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

def getMessages(msg_ids)
  msg_ids = checkMsgids(msg_ids)
  @url = @@REPORT_HOST_NAME + @@REPORT_MESSAGE_PATH + '?msg_ids=' + msg_ids
  result = JPush::GetMessagesResult.new
  wrapper = @httpclient.sendGet(@url, nil)
  return result.fromResponse(wrapper)
end

#getReceiveds(msg_ids) ⇒ Object


17
18
19
20
21
22
23
# File 'lib/jpush/report_client.rb', line 17

def getReceiveds(msg_ids)
  msg_ids = checkMsgids(msg_ids)
  @url = @@REPORT_HOST_NAME + @@REPORT_RECEIVE_PATH + '?msg_ids=' + msg_ids
  result = JPush::ReceivedsResult.new
  wrapper = @httpclient.sendGet(@url, nil)
  return result.fromResponse(wrapper)
end

#getUsers(timeUnit, start, duration) ⇒ Object


33
34
35
36
37
38
39
# File 'lib/jpush/report_client.rb', line 33

def getUsers(timeUnit, start, duration)
  @url = @@REPORT_HOST_NAME + @@REPORT_USER_PATH + '?time_unit=' + timeUnit + '&start=' + start + '&duration=' + duration.to_s
  result = JPush::UserResult.new
  puts @url
  wrapper = @httpclient.sendGet(@url, nil)
  return result.fromResponse(wrapper)
end