baidu-cloud_push 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/baidu/cloud_push.rb +19 -2
- data/lib/baidu/response.rb +16 -12
- data/lib/baidu.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 982afd6c28026de0109e3cbe9e3c99af430d07ab
|
4
|
+
data.tar.gz: d33617b3a5e71b38b68eedb056f6f3151860861b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1d8f51e53ce05183ac12956608a259b9be821145a73ca6f696696457158430ca2250baa3e78833591230f788a59a1f8a219a4ed939f6ef2850ff5224db2856c
|
7
|
+
data.tar.gz: 3689598367d44ad20103e091dda436b5d1aea199570fc513090b067282c3c08a749ad556ac7129865eed5a988c5e2167f5363c5dbb0becc9c0e4ba7288906581
|
data/lib/baidu/cloud_push.rb
CHANGED
@@ -16,6 +16,9 @@ module Baidu
|
|
16
16
|
attr_reader :request,:apikey
|
17
17
|
attr_reader :resource_name,:method_name,:params
|
18
18
|
attr_accessor :device_type,:expires
|
19
|
+
|
20
|
+
LIMITED_ALLOWED = ["single_device","batch_device"]
|
21
|
+
|
19
22
|
# 构造函数
|
20
23
|
#
|
21
24
|
# @param apikey [String] 应用的key
|
@@ -25,6 +28,8 @@ module Baidu
|
|
25
28
|
def initialize(apikey,apisecret,options={})
|
26
29
|
@apikey = apikey
|
27
30
|
@request = Baidu::Request.new(apisecret,options)
|
31
|
+
@config = Baidu::Configuration.instance
|
32
|
+
@config.mode = :limited
|
28
33
|
end
|
29
34
|
|
30
35
|
# 推送消息到单台设备
|
@@ -206,7 +211,6 @@ module Baidu
|
|
206
211
|
send_request
|
207
212
|
end
|
208
213
|
|
209
|
-
|
210
214
|
# 取消定时任务
|
211
215
|
#
|
212
216
|
# @param timer_id [String] 定时任务ID
|
@@ -248,6 +252,13 @@ module Baidu
|
|
248
252
|
send_request
|
249
253
|
end
|
250
254
|
|
255
|
+
# Configuration
|
256
|
+
#
|
257
|
+
# @param &block [Block]
|
258
|
+
def self.configure(&block)
|
259
|
+
block.call(Baidu::Configuration.instance)
|
260
|
+
end
|
261
|
+
|
251
262
|
private
|
252
263
|
def merge_params(args={})
|
253
264
|
now_time = Time.now.to_i
|
@@ -271,9 +282,15 @@ module Baidu
|
|
271
282
|
end
|
272
283
|
|
273
284
|
def send_request
|
274
|
-
@
|
285
|
+
if @config.mode == :super || LIMITED_ALLOWED.include?(@method_name)
|
286
|
+
@request.start(@resource_name,@method_name,merge_params(@params))
|
287
|
+
else
|
288
|
+
return Baidu::Response.new()
|
289
|
+
end
|
275
290
|
end
|
276
291
|
end
|
277
292
|
end
|
278
293
|
|
279
294
|
require 'baidu/request'
|
295
|
+
require 'baidu/response'
|
296
|
+
require 'baidu/configuration'
|
data/lib/baidu/response.rb
CHANGED
@@ -4,19 +4,23 @@ module Baidu
|
|
4
4
|
class Response
|
5
5
|
attr_reader :request_id,:response_params,:error_code,:error_msg,:result
|
6
6
|
|
7
|
-
def initialize(http_response)
|
8
|
-
|
9
|
-
if http_response.code.to_i == 200
|
10
|
-
# success
|
11
|
-
@result = true
|
12
|
-
@request_id = body["request_id"]
|
13
|
-
@response_params = body["response_params"]
|
14
|
-
else
|
15
|
-
# failed
|
7
|
+
def initialize(http_response=nil)
|
8
|
+
if http_response.nil?
|
16
9
|
@result = false
|
17
|
-
|
18
|
-
|
19
|
-
|
10
|
+
else
|
11
|
+
body = JSON.parse(http_response.body)
|
12
|
+
if http_response.code.to_i == 200
|
13
|
+
# success
|
14
|
+
@result = true
|
15
|
+
@request_id = body["request_id"]
|
16
|
+
@response_params = body["response_params"]
|
17
|
+
else
|
18
|
+
# failed
|
19
|
+
@result = false
|
20
|
+
@request_id = body["request_id"]
|
21
|
+
@error_code = body["error_code"]
|
22
|
+
@error_msg = body["error_msg"]
|
23
|
+
end
|
20
24
|
end
|
21
25
|
end
|
22
26
|
|
data/lib/baidu.rb
CHANGED