Class: Xiaomi::Push::Services::Topic

Inherits:
Object
  • Object
show all
Defined in:
lib/xiaomi/push/services/topic.rb

Overview

标签类 API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Topic

初始化

Parameters:



13
14
15
# File 'lib/xiaomi/push/services/topic.rb', line 13

def initialize(context)
  @context = context
end

Instance Attribute Details

#contextClient

Returns the current value of context.

Returns:

  • (Client)

    the current value of context



7
8
9
# File 'lib/xiaomi/push/services/topic.rb', line 7

def context
  @context
end

Instance Method Details

#subscribe(**options) ⇒ Hash

订阅标签

可使用 reg id 或 alias 的方式订阅标签

Examples:

subscribe(reg_id: 'abc', topic: 'beijing')
subscribe(alias: 'abc', topic: 'beijing')
subscribe(alias: 'abc,def,ghi,jkl', topic: 'beijing')

Parameters:

  • options (Hash)

Options Hash (**options):

  • :reg_id (String)

    订阅 reg id,多个以逗号分割,最多 1000 个

  • :aliases (String)

    订阅 alias,多个以逗号分割,最多 1000 个

  • :topic (String)

    订阅名

  • :category (String)

    分类,可选项

Returns:

  • (Hash)

    小米返回数据结构



32
33
34
35
# File 'lib/xiaomi/push/services/topic.rb', line 32

def subscribe(**options)
  url, params = prepare_params(__method__.to_s, options)
  @context.post(url, params)
end

#unsubscribe(**options) ⇒ Hash

取消订阅标签

可使用 reg id 或 alias 的方式取消订阅标签

Examples:

unsubscribe(reg_id: 'abc', topic: 'beijing')
unsubscribe(alias: 'abc', topic: 'beijing')
unsubscribe(alias: 'abc,def,ghi,jkl', topic: 'beijing')

Parameters:

  • options (Hash)

Options Hash (**options):

  • :reg_id (String)

    订阅 reg id,多个以逗号分割,最多 1000 个

  • :aliases (String)

    订阅 alias,多个以逗号分割,最多 1000 个

  • :topic (String)

    订阅名

  • :category (String)

    分类,可选项

Returns:

  • (Hash)

    小米返回数据结构



52
53
54
55
# File 'lib/xiaomi/push/services/topic.rb', line 52

def unsubscribe(**options)
  url, params = prepare_params(__method__.to_s, options)
  @context.post(url, params)
end