baidusms 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/baidusms/client.rb +6 -5
- data/lib/baidusms/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41ba0d3a465bc55c2b41166033843f34430648b6
|
4
|
+
data.tar.gz: 3b478d18812f3699875b5b3877296919e1128400
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ed6eb0be80c3a919a548834a84e1725deb579b41d2f21713f1650519d4e1a4d3af4abf63499109903a4d57471b5bcaed1329e1ee2786c59bcb139507a8c8ea1
|
7
|
+
data.tar.gz: 9309c5fad07e44754631429beacb04eff62aacb19ccf04a2bba38dc3f16a68ef29bb7909e21724340c1496fa90e7d3aa62a7a16f6e8abce67bb17149826829c1
|
data/lib/baidusms/client.rb
CHANGED
@@ -11,7 +11,7 @@ module Baidusms
|
|
11
11
|
@debug = attrs[:debug]
|
12
12
|
end
|
13
13
|
|
14
|
-
def call(service,method,body=
|
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
|
-
|
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
|
-
|
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(
|
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','
|
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
|
data/lib/baidusms/version.rb
CHANGED
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.
|
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
|
11
|
+
date: 2014-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|