Class: Xiaomi::Push::Services::Message
- Inherits:
-
Object
- Object
- Xiaomi::Push::Services::Message
- Defined in:
- lib/xiaomi/push/services/message.rb
Overview
单条消息类 API
允许向单个设备或多个设备发送同样的推送消息
设备的标识支持 reg_id/alias/user/topic/topics/all
Constant Summary collapse
- MESSAGE_TYPE =
消息类型模板
{ reg_id: { uri: 'regid', query: 'registration_id' }, alias: { uri: 'alias', query: 'alias' }, user: { uri: 'user_account', query: 'user_account' }, topic: { uri: 'topic', query: 'topic' }, topics: { uri: 'multi_topic', query: 'topics' }, topic_op: { uri: 'multi_topic', query: 'topic_op' }, all: { uri: 'all', query: 'all' }, }
Instance Attribute Summary collapse
-
#context ⇒ Client
The current value of context.
Instance Method Summary collapse
-
#counters(start_date, end_date, package_name) ⇒ Hash
获取消息的统计数据.
-
#initialize(context) ⇒ Message
constructor
A new instance of Message.
-
#send(**options) ⇒ Hash
推送消息.
Constructor Details
#initialize(context) ⇒ Message
Returns a new instance of Message.
50 51 52 |
# File 'lib/xiaomi/push/services/message.rb', line 50 def initialize(context) @context = context end |
Instance Attribute Details
#context ⇒ Client
Returns the current value of context.
15 16 17 |
# File 'lib/xiaomi/push/services/message.rb', line 15 def context @context end |
Instance Method Details
#counters(start_date, end_date, package_name) ⇒ Hash
获取消息的统计数据
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/xiaomi/push/services/message.rb', line 92 def counters(start_date, end_date, package_name) url = @context.build_uri('stats/message/counters') params = { start_date: start_date, end_date: end_date, restricted_package_name: package_name } @context.get(url, params) end |
#send(**options) ⇒ Hash
推送消息
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/xiaomi/push/services/message.rb', line 63 def send(**) type, value = () if type && value url = @context.build_uri("message/#{type[:uri]}") if [:message].kind_of?Xiaomi::Push::Message::Base [:message].type(type[:query], value) params = [:message].to_params else params = [:message] params[type[:query].to_sym] = value end @context.post(url, params) else raise Xiaomi::Push::RequestError, '无效的消息类型,请检查是否符合这些类型: reg_id/alias/topic/topics/all' end end |