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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9207662a2ceccbb39bb4ffb8bf46f57772b944c
4
- data.tar.gz: 7731f1fbdb18bee98036e188ee3b292cf1302613
3
+ metadata.gz: 982afd6c28026de0109e3cbe9e3c99af430d07ab
4
+ data.tar.gz: d33617b3a5e71b38b68eedb056f6f3151860861b
5
5
  SHA512:
6
- metadata.gz: 566042cd726c1c6229f6335aa1f57b4bea730bb96c6a4e038ecb4beebb2b876b4e572ee0da279654260d79f24e50d5013022aa1b48584c1f1972c15b9bbac54c
7
- data.tar.gz: e7e9d7c61d2e7cbd995a755800a9861cc91446759c00debe54f270842e1f217bae869caced903b8899345957ad4888d1b865f0adc631965312732d040ca5f044
6
+ metadata.gz: d1d8f51e53ce05183ac12956608a259b9be821145a73ca6f696696457158430ca2250baa3e78833591230f788a59a1f8a219a4ed939f6ef2850ff5224db2856c
7
+ data.tar.gz: 3689598367d44ad20103e091dda436b5d1aea199570fc513090b067282c3c08a749ad556ac7129865eed5a988c5e2167f5363c5dbb0becc9c0e4ba7288906581
@@ -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
- @request.start(@resource_name,@method_name,merge_params(@params))
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'
@@ -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
- body = JSON.parse(http_response.body)
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
- @request_id = body["request_id"]
18
- @error_code = body["error_code"]
19
- @error_msg = body["error_msg"]
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
@@ -5,3 +5,4 @@ end
5
5
  require 'baidu/cloud_push'
6
6
  require 'baidu/response'
7
7
  require 'baidu/request'
8
+ require 'baidu/configuration'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baidu-cloud_push
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tesla Lee