class JPush::Device

Public Instance Methods

add_tags(registration_id, tags) click to toggle source

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

# File lib/jpush/device.rb, line 37
def add_tags(registration_id, tags)
  update(registration_id, tags_add: tags)
end
clear_tags(registration_id) click to toggle source
# File lib/jpush/device.rb, line 45
def clear_tags(registration_id)
  update(registration_id, clear_tags: true)
end
delete_alias(registration_id) click to toggle source
# File lib/jpush/device.rb, line 53
def delete_alias(registration_id)
  update(registration_id, alis: '')
end
remove_tags(registration_id, tags) click to toggle source
# File lib/jpush/device.rb, line 41
def remove_tags(registration_id, tags)
  update(registration_id, tags_remove: tags)
end
show(registration_id) click to toggle source

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

# File lib/jpush/device.rb, line 9
def show(registration_id)
  url = base_url + registration_id
  Http::Client.get(@jpush, url)
end
status(registration_ids) click to toggle source

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

# 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(@jpush, url, body: body)
end
update(registration_id, tags_add: nil, tags_remove: nil, clear_tags: false, alis: nil, mobile: nil) click to toggle source

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

# 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(@jpush, url, body: body)
end
update_alias(registration_id, alis) click to toggle source
# File lib/jpush/device.rb, line 49
def update_alias(registration_id, alis)
  update(registration_id, alis: alis)
end
update_mobile(registration_id, mobile) click to toggle source
# File lib/jpush/device.rb, line 57
def update_mobile(registration_id, mobile)
  update(registration_id, mobile: mobile)
end

Private Instance Methods

base_url() click to toggle source
# File lib/jpush/device.rb, line 72
def base_url
  'https://device.jpush.cn/v3/devices/'
end