Class: JPush::DeviceClient

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

Constant Summary collapse

@@DEVICE_HOST_NAME =
'https://device.jpush.cn'
@@DEVICE_PATH =
'/v3/devices/'
@@TAG_PATH_LIST =
'/v3/tags/'

Instance Method Summary collapse

Constructor Details

#initialize(maxRetryTimes) ⇒ DeviceClient

Returns a new instance of DeviceClient.


14
15
16
# File 'lib/jpush/device_client.rb', line 14

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

Instance Method Details

#aliasDelete(alias_value, platform) ⇒ Object


75
76
77
78
79
80
81
# File 'lib/jpush/device_client.rb', line 75

def aliasDelete(alias_value, platform)
  url = @@DEVICE_HOST_NAME + '/v3/aliases/' + alias_value  
  if platform != nil
    url = url + '?platform=' + platform 
  end
  return @httpclient.sendDelete(url, nil)
end

#getAliasUids(alias_value, platform) ⇒ Object


64
65
66
67
68
69
70
71
72
73
# File 'lib/jpush/device_client.rb', line 64

def getAliasUids(alias_value, platform)
  aliasUidsResult = JPush::AliasUidsResult.new
  url = @@DEVICE_HOST_NAME + '/v3/aliases/' + alias_value  
  if platform != nil
    url = url + '?platform=' + platform
  end
  wrapper = @httpclient.sendGet(url, nil)
  aliasUidsResult.fromResponse(wrapper)
  return aliasUidsResult
end

#getAppkeyTagListObject


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

def getAppkeyTagList()
  url = @@DEVICE_HOST_NAME + @@TAG_PATH_LIST
  tag_list = JPush::TagListResult.new
  wrapper =  @httpclient.sendGet(url, nil)
  tag_list.fromResponse(wrapper)
  return tag_list
end

#getDeviceTagAlias(registration_id) ⇒ Object


18
19
20
21
22
23
24
25
# File 'lib/jpush/device_client.rb', line 18

def getDeviceTagAlias(registration_id)
  result = JPush::TagAliasResult.new
  url = @@DEVICE_HOST_NAME + @@DEVICE_PATH + registration_id
  puts url
  wrapper = @httpclient.sendGet(url, nil)
  result.fromResponse(wrapper)
  return result
end

#tagAddingOrRemovingUsers(tag_value, tagManager) ⇒ Object


49
50
51
52
53
# File 'lib/jpush/device_client.rb', line 49

def  tagAddingOrRemovingUsers(tag_value, tagManager)
  json_data = JSON.generate(tagManager.toJSON)
  url = @@DEVICE_HOST_NAME + '/v3/tags/' + tag_value
  return @httpclient.sendPost(url, json_data)
end

#tagDelete(tag_value, platform) ⇒ Object


55
56
57
58
59
60
61
62
# File 'lib/jpush/device_client.rb', line 55

def tagDelete(tag_value, platform)

  url = @@DEVICE_HOST_NAME + '/v3/tags/' + tag_value 
  if platform != nil
    url = url + '?platform=' + platform 
  end
  return @httpclient.sendDelete(url, nil)
end

#updateDeviceTagAlias(registration_id, tagAlias) ⇒ Object


27
28
29
30
31
# File 'lib/jpush/device_client.rb', line 27

def updateDeviceTagAlias(registration_id, tagAlias)
  json_data = JSON.generate(tagAlias.toJSON)
  url = @@DEVICE_HOST_NAME + @@DEVICE_PATH + registration_id 
  return @httpclient.sendPost(url, json_data)
end

#userExistsInTag(tag_value, registration_id) ⇒ Object


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

def userExistsInTag(tag_value, registration_id)
  result = JPush::ExistResult.new
  url = @@DEVICE_HOST_NAME + '/v3/tags/' + tag_value + '/registration_ids/' + registration_id 
  wrapper = @httpclient.sendGet(url, nil)
  result.fromResponse(wrapper)
  return result
end