Class: JPush::JPushClient

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

Overview

The global entrance of JPush API library.

Instance Method Summary collapse

Constructor Details

#initialize(appkey, masterSecret, maxRetryTimes = 5) ⇒ JPushClient

Create a JPush Client. masterSecret API access secret of the appKey. appKey The KEY of one application on JPush.


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/jpush/jpush_client.rb', line 17

def initialize(appkey, masterSecret, maxRetryTimes = 5)
  begin
    @logger = Logger.new(STDOUT)
    if appkey.class == String && appkey.length == 24 then
      @appkey = appkey
    else
      @logger.error('appkey is format error  ')
    end
    if masterSecret.class == String && masterSecret.length == 24 then
      @masterSecret = masterSecret

    else
      @logger.error('masterSecret is format error')
    end
  end
  @masterSecret = masterSecret
  @pushClient = JPush::PushClient.new(maxRetryTimes = maxRetryTimes)
  @reportClient = JPush::ReportClient.new(maxRetryTimes = maxRetryTimes)
  @deviceClient = JPush::DeviceClient.new(maxRetryTimes = maxRetryTimes)
  $authcode = ServiceHelper.getAuthorizationBase64(appkey, masterSecret)
end

Instance Method Details

#aliasDelete(alias_value, platform = nil) ⇒ Object

Alias Delete

Parameters:

  • alias_value
  • platform (defaults to: nil)

145
146
147
# File 'lib/jpush/jpush_client.rb', line 145

def aliasDelete(alias_value, platform = nil)
  return @deviceClient.aliasDelete(alias_value, platform)
end

#getAliasUids(alias_value, platform = nil) ⇒ Object

get alias uids

Parameters:

  • alias_value
  • platform (defaults to: nil)

    default is all


136
137
138
# File 'lib/jpush/jpush_client.rb', line 136

def getAliasUids(alias_value, platform = nil)
  return @deviceClient.getAliasUids(alias_value, platform)
end

#getAppkeyTagListObject

Appkey Tag List


100
101
102
# File 'lib/jpush/jpush_client.rb', line 100

def getAppkeyTagList()
  return @deviceClient.getAppkeyTagList
end

#getDeviceTagAlias(registration_id) ⇒ Object

Get user profile Response Data {

"tags": ["tag1", "tag2"],
"alias": "alias1"  }

Parameters:

  • registration_id

84
85
86
# File 'lib/jpush/jpush_client.rb', line 84

def getDeviceTagAlias(registration_id)
  return @deviceClient.getDeviceTagAlias(registration_id)
end

#getReportMessages(msgIds) ⇒ Object

Get message report.

Parameters:

  • msgIds

    100 msgids to batch getting is supported.

Returns:

  • JSON data.


63
64
65
66
# File 'lib/jpush/jpush_client.rb', line 63

def getReportMessages(msgIds)
  result =  @reportClient.getMessages(msgIds)
  return result
end

#getReportReceiveds(msgIds) ⇒ Object

Get received report.

Parameters:

  • msgIds

    100 msgids to batch getting is supported.

Returns:

  • JSON data.


55
56
57
58
# File 'lib/jpush/jpush_client.rb', line 55

def getReportReceiveds(msgIds)
  result = @reportClient.getReceiveds(msgIds)
  return result
end

#getReportUsers(timeUnit, start, duration) ⇒ Object

Get user report.

Parameters:

  • timeunit

    is 'DAY','HOUR' or 'MONTH'

  • start

    is a string for example 2014-06-10

Returns:

  • JSON data.


73
74
75
76
# File 'lib/jpush/jpush_client.rb', line 73

def getReportUsers(timeUnit, start, duration)
  result =  @reportClient.getUsers(timeUnit, start, duration)
  return result
end

#sendPush(payload) ⇒ Object

Send a push with object.

Parameters:

  • pushPayload

    payload object of a push.

Returns:

  • JSON data.


42
43
44
45
# File 'lib/jpush/jpush_client.rb', line 42

def sendPush(payload)
  result = @pushClient.sendPush(payload)
  return  result
end

#tagAddingOrRemovingUsers(tag_value, registration_ids) ⇒ Object

Tag Adding or Removing Users

Parameters:

  • tag_value
  • registration_ids

118
119
120
# File 'lib/jpush/jpush_client.rb', line 118

def  tagAddingOrRemovingUsers(tag_value, registration_ids)
  return @deviceClient.tagAddingOrRemovingUsers(tag_value, registration_ids)
end

#tagDelete(tag_value, platform = nil) ⇒ Object

Tag Delete

Parameters:

  • tag_value
  • platform (defaults to: nil)

    default is all


127
128
129
# File 'lib/jpush/jpush_client.rb', line 127

def tagDelete(tag_value, platform = nil)
  return @deviceClient.tagDelete(tag_value, platform)
end

#updateDeviceTagAlias(registration_id, tagAlias) ⇒ Object

Update user device profile

Parameters:

  • registration_id
  • tagAlias

93
94
95
# File 'lib/jpush/jpush_client.rb', line 93

def updateDeviceTagAlias(registration_id, tagAlias)
  return @deviceClient.updateDeviceTagAlias(registration_id, tagAlias);
end

#userExistsInTag(tag_value, registration_id) ⇒ Object

User Exists In Tag

Parameters:

  • tag_value
  • registration_id

109
110
111
# File 'lib/jpush/jpush_client.rb', line 109

def userExistsInTag(tag_value, registration_id)
  return @deviceClient.userExistsInTag(tag_value, registration_id)
end

#validate(payload) ⇒ Object


47
48
49
50
# File 'lib/jpush/jpush_client.rb', line 47

def validate(payload)
  result = @pushClient.validate(payload)
  return result
end