Class: JPush::PushClient

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

Constant Summary collapse

@@PUSH_API_URL =
'https://api.jpush.cn/v3/push'
@@VALIDATE =
'/validate'
@@_timeToLive =
60 * 60 * 24

Instance Method Summary collapse

Constructor Details

#initialize(maxRetryTimes) ⇒ PushClient

Returns a new instance of PushClient.


15
16
17
# File 'lib/jpush/push_client.rb', line 15

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

Instance Method Details

#sendPush(payload) ⇒ Object

Parameters:

  • payload

    is the instance of PushPayload


22
23
24
25
26
27
28
# File 'lib/jpush/push_client.rb', line 22

def sendPush(payload)
  json_data = JSON.generate(payload.toJSON)
  result = JPush::PushResult.new
  wrapper = @httpclient.sendPost(@@PUSH_API_URL, json_data)
  result.fromResponse(wrapper)
  return result
end

#validate(payload) ⇒ Object

The API is used only to verify push call whether can succeed, lies in the difference with the push of API: not to send any message to user.

Parameters:

  • payload

    is the instance of PushPayload


35
36
37
38
39
40
41
# File 'lib/jpush/push_client.rb', line 35

def validate(payload)
  json_data = JSON.generate(payload.toJSON)
  result = JPush::PushResult.new
  wrapper = @httpclient.sendPost(@@PUSH_API_URL + @@VALIDATE, json_data)
  result.fromResponse(wrapper)
  return result
end