Class: Baidu::CloudPush

Inherits:
Object
  • Object
show all
Defined in:
lib/baidu/cloud_push.rb

Overview

云推送的主类

Constant Summary collapse

LIMITED_ALLOWED =
["single_device","batch_device"]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(apikey, apisecret, options = {}) ⇒ CloudPush

构造函数

Parameters:

  • apikey (String)

    应用的key

  • apisecret (String)

    应用的secret

  • options (Hash) (defaults to: {})

    自定义参数

Options Hash (options):

  • :use_ssl (boolean)

    默认:false,不使用https请求



28
29
30
31
32
# File 'lib/baidu/cloud_push.rb', line 28

def initialize(apikey,apisecret,options={})
	@apikey = apikey
	@request = Baidu::Request.new(apisecret,options)
	@config = Baidu::Configuration.instance
end

Instance Attribute Details

#apikeyString (readonly)

应用的key

Returns:

  • (String)

    the current value of apikey



15
16
17
# File 'lib/baidu/cloud_push.rb', line 15

def apikey
  @apikey
end

#device_typeObject

Returns the value of attribute device_type.



18
19
20
# File 'lib/baidu/cloud_push.rb', line 18

def device_type
  @device_type
end

#devise_typeFixnum

设备类型,3安卓设备,4iOS设备

Returns:

  • (Fixnum)

    the current value of devise_type



15
16
17
# File 'lib/baidu/cloud_push.rb', line 15

def devise_type
  @devise_type
end

#expiresFixnum

用户指定本次请求签名的失效时间。格式为unix时间戳形式,用于防止 replay 型攻击。为保证防止 replay攻击算法的正确有效,请保证客户端系统时间正确

Returns:

  • (Fixnum)

    the current value of expires



15
16
17
# File 'lib/baidu/cloud_push.rb', line 15

def expires
  @expires
end

#method_nameString (readonly)

api的请求方式,如single_device

Returns:

  • (String)

    the current value of method_name



15
16
17
# File 'lib/baidu/cloud_push.rb', line 15

def method_name
  @method_name
end

#paramsHash (readonly)

请求参数

Returns:

  • (Hash)

    the current value of params



15
16
17
# File 'lib/baidu/cloud_push.rb', line 15

def params
  @params
end

#requestBaidu::Request (readonly)

Baidu::Response 实例

Returns:



15
16
17
# File 'lib/baidu/cloud_push.rb', line 15

def request
  @request
end

#resource_nameString (readonly)

api的资源名称,如push

Returns:

  • (String)

    the current value of resource_name



15
16
17
# File 'lib/baidu/cloud_push.rb', line 15

def resource_name
  @resource_name
end

Class Method Details

.configure(&block) ⇒ Object

Configuration

Parameters:

  • &block (Block)


257
258
259
# File 'lib/baidu/cloud_push.rb', line 257

def self.configure(&block)
	block.call(Baidu::Configuration.instance)
end

Instance Method Details

#app_create_tag(tag) ⇒ Baidu::Response

创建标签组

Parameters:

  • tag (String)

    标签名称

Returns:



151
152
153
154
155
# File 'lib/baidu/cloud_push.rb', line 151

def app_create_tag(tag)
	set_resource_and_method(__method__)
	@params = {tag: tag}
	send_request
end

#app_del_tag(tag) ⇒ Baidu::Response

删除标签组

Parameters:

  • tag (String)

    标签名称

Returns:



161
162
163
164
165
# File 'lib/baidu/cloud_push.rb', line 161

def app_del_tag(tag)
	set_resource_and_method(__method__)
	@params = {tag:tag}
	send_request
end

#app_query_tags(opt = {}) ⇒ Baidu::Response

查询标签组的列表

Parameters:

  • opt (Hash) (defaults to: {})

    自定义参数

Options Hash (opt):

  • :tag (String)

    标签名称

  • :start (Fixnum)

    返回记录的索引起始位置

  • :limit (Fixnum)

    返回的记录条数

Returns:



141
142
143
144
145
# File 'lib/baidu/cloud_push.rb', line 141

def app_query_tags(opt={})
  set_resource_and_method(__method__)
	@params = opt
	send_request
end

#push_all(msg, opt = {}) ⇒ Baidu::Response

推送广播消息

Parameters:

  • msg (Hash)

    消息内容

  • opt (Hash) (defaults to: {})

    自定义参数

Options Hash (opt):

  • :msg_type (Fixnum)

    消息类型

  • :msg_expires (Fixnum)

    消息过期时间,unix timestamp

  • :deploy_status (Fixnum)

    iOS应用部署状态

  • :send_time (Fixnum)

    指定发送的实际时间

Returns:



58
59
60
61
62
# File 'lib/baidu/cloud_push.rb', line 58

def push_all(msg,opt={})
	set_resource_and_method(__method__)
	@params = {msg:msg.to_json}.merge(opt)
	send_request
end

#push_batch_device(channel_ids, msg, opt = {}) ⇒ Object

推送到给定的一组设备

Parameters:

  • channel_ids (Array<String>)

    一组channel_ids

  • msg (Hash)

    消息内容

  • opt (Hash) (defaults to: {})

    自定义参数

Options Hash (opt):

  • :msg_type (Fixnum)

    消息类型

  • :msg_expires (Fixnum)

    消息过期时间,unix timestamp

  • :topic_id (String)

    分类主题名称



88
89
90
91
92
# File 'lib/baidu/cloud_push.rb', line 88

def push_batch_device(channel_ids,msg,opt={})
	set_resource_and_method(__method__)
	@params = {channel_ids: channel_ids.to_json, msg: msg.to_json}.merge(opt)
	send_request
end

#push_single_device(channel_id, msg, opt = {}) ⇒ Baidu::Response

推送消息到单台设备

Parameters:

  • channel_id (String)

    设备唯一的channel_id

  • msg (Hash)

    消息内容

  • opt (Hash) (defaults to: {})

    自定义参数

Options Hash (opt):

  • :msg_type (Fixnum)

    消息类型

  • :msg_expires (Fixnum)

    消息过期时间,unix timestamp

  • :deploy_status (Fixnum)

    iOS应用部署状态

Returns:



43
44
45
46
47
# File 'lib/baidu/cloud_push.rb', line 43

def push_single_device(channel_id,msg,opt={})
	set_resource_and_method(__method__)
	@params = {channel_id:channel_id,msg:msg.to_json}.merge(opt)
	send_request
end

#push_tags(tag, msg, opt = {}) ⇒ Baidu::Response

推送组播消息

Parameters:

  • tag (String)

    标签类型

  • msg (Hash)

    消息内容

  • opt (Hash) (defaults to: {})

    自定义参数

Options Hash (opt):

  • :msg_type (Fixnum)

    消息类型

  • :msg_expires (Fixnum)

    消息过期时间,unix timestamp

  • :deploy_status (Fixnum)

    iOS应用部署状态

  • :send_time (Fixnum)

    指定发送的实际时间

Returns:



74
75
76
77
78
# File 'lib/baidu/cloud_push.rb', line 74

def push_tags(tag,msg,opt={})
	set_resource_and_method(__method__)
	@params = {msg:msg.to_json,tag:tag,type:1}.merge(opt)
	send_request
end

#report_query_msg_status(msg_ids) ⇒ Baidu::Response

查询消息的发送状态

Parameters:

  • msg_ids (Array<String>)

    msg_id的数组

Returns:



98
99
100
101
102
# File 'lib/baidu/cloud_push.rb', line 98

def report_query_msg_status(msg_ids)
	set_resource_and_method(__method__)
	@params = {msg_id: msg_ids.to_json}
	send_request
end

#report_query_timer_records(timer_id, opt = {}) ⇒ Baidu::Response

查询定时消息的发送记录

Parameters:

  • timer_id (String)

    推送接口返回的timer_id

  • opt (Hash) (defaults to: {})

    自定义参数

Options Hash (opt):

  • :start (Fixnum)

    返回记录的索引起始位置

  • :limit (Fixnum)

    返回的记录条数

  • :range_start (Fixnum)

    查询的起始时间,unix timestamp

  • :range_end (Fixnum)

    查询的戒指时间,unix timestamp

Returns:



113
114
115
116
117
# File 'lib/baidu/cloud_push.rb', line 113

def report_query_timer_records(timer_id,opt={})
	set_resource_and_method(__method__)
	@params = {timer_id: timer_id}.merge(opt)
	send_request
end

#report_query_topic_records(topic_id, opt = {}) ⇒ Baidu::Response

查询指定分类主题的发送记录

Parameters:

  • topic_id (String)

    分类主题的名称

  • opt (Hash) (defaults to: {})

    自定义参数

Options Hash (opt):

  • :start (Fixnum)

    返回记录的索引起始位置

  • :limit (Fixnum)

    返回的记录条数

  • :range_start (Fixnum)

    查询的起始时间,unix timestamp

  • :range_end (Fixnum)

    查询的戒指时间,unix timestamp

Returns:



128
129
130
131
132
# File 'lib/baidu/cloud_push.rb', line 128

def report_query_topic_records(topic_id,opt={})
	set_resource_and_method(__method__)
	@params = {topic_id:topic_id}.merge(opt)
	send_request
end

#report_statistic_deviceBaidu::Response

当前应用的设备统计

Returns:



238
239
240
241
242
# File 'lib/baidu/cloud_push.rb', line 238

def report_statistic_device
	set_resource_and_method(__method__)
	@params = {}
	send_request
end

#report_statistic_topic(topic_id) ⇒ Baidu::Response

查看分类主题统计信息

Parameters:

  • topic_id (String)

    一个已使用过的分类主题

Returns:



248
249
250
251
252
# File 'lib/baidu/cloud_push.rb', line 248

def report_statistic_topic(topic_id)
	set_resource_and_method(__method__)
	@params = {topic_id:topic_id}
	send_request
end

#tag_add_devices(tag, channel_ids) ⇒ Baidu::Response

添加设备到标签组

Parameters:

  • tag (String)

    标签名称

  • channel_ids (Array<String>)

    一组channel_id

Returns:



173
174
175
176
177
# File 'lib/baidu/cloud_push.rb', line 173

def tag_add_devices(tag,channel_ids)
	set_resource_and_method(__method__)
	@params = {tag:tag,channel_ids:channel_ids.to_json}
	send_request
end

#tag_del_devices(tag, channel_ids) ⇒ Baidu::Response

将设备从标签组中移除

Parameters:

  • tag (String)

    标签名称

  • channel_ids (Array<String>)

    一组channel_id

Returns:



184
185
186
187
188
# File 'lib/baidu/cloud_push.rb', line 184

def tag_del_devices(tag,channel_ids)
	set_resource_and_method(__method__)
	@params = {tag:tag,channel_ids:channel_ids.to_json}
	send_request
end

#tag_device_num(tag) ⇒ Baidu::Response

查询标签组设备数量

Parameters:

  • tag (String)

    标签名称

Returns:



194
195
196
197
198
# File 'lib/baidu/cloud_push.rb', line 194

def tag_device_num(tag)
	set_resource_and_method(__method__)
	@params = {tag:tag}
	send_request
end

#timer_cancel(timer_id) ⇒ Baidu::Response

取消定时任务

Parameters:

  • timer_id (String)

    定时任务ID

Returns:



217
218
219
220
221
# File 'lib/baidu/cloud_push.rb', line 217

def timer_cancel(timer_id)
	set_resource_and_method(__method__)
	@params = {timer_id:timer_id}
	send_request
end

#timer_query_list(opt = {}) ⇒ Baidu::Response

查询定时任务列表

Parameters:

  • opt (Hash) (defaults to: {})

    自定义参数

Options Hash (opt):

  • :timer_id (String)
  • :start (Fixnum)

    返回记录的索引起始位置

  • :limit (Fixnum)

    返回的记录条数

Returns:



207
208
209
210
211
# File 'lib/baidu/cloud_push.rb', line 207

def timer_query_list(opt={})
	set_resource_and_method(__method__)
	@params = opt
	send_request
end

#topic_query_list(opt = {}) ⇒ Baidu::Response

查询分类主题列表

Parameters:

  • opt (Hash) (defaults to: {})

    自定义参数

Options Hash (opt):

  • :start (Fixnum)

    返回记录的索引起始位置

  • :limit (Fixnum)

    返回的记录条数

Returns:



229
230
231
232
233
# File 'lib/baidu/cloud_push.rb', line 229

def topic_query_list(opt={})
	set_resource_and_method(__method__)
	@params = opt
	send_request
end