baidusms 0.0.1 → 0.0.2

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: 610869d7af34278e968fe30e1eae60f27c02658c
4
- data.tar.gz: eb0034e0887b3f278611e15a9e72b630e038491c
3
+ metadata.gz: 41ba0d3a465bc55c2b41166033843f34430648b6
4
+ data.tar.gz: 3b478d18812f3699875b5b3877296919e1128400
5
5
  SHA512:
6
- metadata.gz: 3841f73b72a90d3e34b0e7e960a2fa6270acf8483913a18e059f605c1c9b5ed0d42306bfac790a17f298f4966bae594ecd8d80c7739ce230acb0e06c3d3b5193
7
- data.tar.gz: 727430c716f00c7d44cdd042161089c22339478e58c9dea0aaf4a9e9a3a1b782049aab0fe051fcada65bb41efe5b29c07f62102bb97a2817c16b9d9665810975
6
+ metadata.gz: 4ed6eb0be80c3a919a548834a84e1725deb579b41d2f21713f1650519d4e1a4d3af4abf63499109903a4d57471b5bcaed1329e1ee2786c59bcb139507a8c8ea1
7
+ data.tar.gz: 9309c5fad07e44754631429beacb04eff62aacb19ccf04a2bba38dc3f16a68ef29bb7909e21724340c1496fa90e7d3aa62a7a16f6e8abce67bb17149826829c1
@@ -11,7 +11,7 @@ module Baidusms
11
11
  @debug = attrs[:debug]
12
12
  end
13
13
 
14
- def call(service,method,body=nil,base_uri='https://api.baidu.com/json/sms/v3')
14
+ def call(service,method,body={},base_uri='https://api.baidu.com/json/sms/v3')
15
15
  message = {
16
16
  :header => {
17
17
  :username => @username,
@@ -23,21 +23,22 @@ module Baidusms
23
23
  pp message if @debug
24
24
 
25
25
  response = {}
26
- loop do
26
+ 5.times do |i|
27
27
  response = HTTParty.post("#{base_uri}/#{service}/#{method}",:body => JSON(message), :headers => {'content-type' => 'application/json;charset=utf-8'})
28
28
  pp response if @debug
29
29
 
30
30
  break if response['header']['desc'] == 'success'
31
- break unless [8904].include? response['header']['failures'][0]['code']
31
+ # retry if the error is caused by Baidu and will by OK after retry
32
+ break unless [8904,9013].include? response['header']['failures'][0]['code']
32
33
 
33
- sleep(10)
34
+ sleep(20*(i+1))
34
35
  end
35
36
 
36
37
  response
37
38
  end
38
39
 
39
40
  def download(file_path,local_file=nil)
40
- file = HTTParty.get(file_path).body.encode('UTF-8','GBK')
41
+ file = HTTParty.get(file_path).body.encode('UTF-8','GB18030')
41
42
  open(local_file,'w').puts file unless local_file.nil?
42
43
  file
43
44
  end
@@ -1,3 +1,3 @@
1
1
  module Baidusms
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baidusms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - MingQian Zhang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-03 00:00:00.000000000 Z
11
+ date: 2014-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler