Module: JPush::Device

Extended by:
Device
Included in:
Device
Defined in:
lib/jpush/device.rb

Instance Method Summary collapse

Instance Method Details

#add_tags(registration_id, tags) ⇒ Object

下面两个方法接受一个参数,其类型为数组或字符串



37
38
39
# File 'lib/jpush/device.rb', line 37

def add_tags(registration_id, tags)
  update(registration_id, tags_add: tags)
end

#clear_tags(registration_id) ⇒ Object



45
46
47
# File 'lib/jpush/device.rb', line 45

def clear_tags(registration_id)
  update(registration_id, clear_tags: true)
end

#delete_alias(registration_id) ⇒ Object



53
54
55
# File 'lib/jpush/device.rb', line 53

def delete_alias(registration_id)
  update(registration_id, alis: '')
end

#remove_tags(registration_id, tags) ⇒ Object



41
42
43
# File 'lib/jpush/device.rb', line 41

def remove_tags(registration_id, tags)
  update(registration_id, tags_remove: tags)
end

#show(registration_id) ⇒ Object

GET /v3/devices/registration_id 获取当前设备的所有属性



9
10
11
12
# File 'lib/jpush/device.rb', line 9

def show(registration_id)
  url = base_url + registration_id
  Http::Client.get(url)
end

#status(registration_ids) ⇒ Object

获取用户在线状态 POST /v3/devices/status/



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

def status(registration_ids)
  registration_ids = [registration_ids].flatten
  url = base_url + 'status'
  body = { registration_ids: registration_ids }
  Http::Client.post(url, body: body)
end

#update(registration_id, tags_add: nil, tags_remove: nil, clear_tags: false, alis: nil, mobile: nil) ⇒ Object

POST /v3/devices/registration_id 更新当前设备的指定属性,当前支持tags, alias,手机号码mobile



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

def update(registration_id, tags_add: nil, tags_remove: nil, clear_tags: false, alis: nil, mobile: nil)
  tags =
    if clear_tags
        ''
    else
      hash = {}
      hash[:add] = [tags_add].flatten unless tags_add.nil?
      hash[:remove] = [tags_remove].flatten unless tags_remove.nil?
      hash.empty? ? nil : hash
    end
  body = {
    tags: tags,
    alias: alis,
    mobile: mobile
  }.select { |_, value| !value.nil? }

  url = base_url + registration_id
  Http::Client.post(url, body: body)
end

#update_alias(registration_id, alis) ⇒ Object



49
50
51
# File 'lib/jpush/device.rb', line 49

def update_alias(registration_id, alis)
  update(registration_id, alis: alis)
end

#update_mobile(registration_id, mobile) ⇒ Object



57
58
59
# File 'lib/jpush/device.rb', line 57

def update_mobile(registration_id, mobile)
  update(registration_id, mobile: mobile)
end