baidu-sms 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/baidu-sms/report_service.rb +27 -4
- data/lib/baidu-sms/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: 125f13235de60599a74661d20d494aafb319f518
|
4
|
+
data.tar.gz: 55b21fb9657383e6077a5d8ee57dbf930a162f99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36d2bc6f87716aa2f509eff8d6ccaf414c83c0ae89a92a420775712951949aa74ed1680c4681dcad709768efc1db061abcd1c77deb57eb4d186e65f9caae6201
|
7
|
+
data.tar.gz: bc9da75759366e14427982c8d7740e115b1bc7d45c0f5a802c67175255f17c27229aa568fcd18f953b379fc082c43d0d673cdb1b4c23f9e9110eaac1aa3342f7
|
@@ -1,12 +1,18 @@
|
|
1
|
+
require 'curl'
|
2
|
+
|
1
3
|
module BaiduSMS
|
2
4
|
class ReportService
|
3
5
|
include BaiduSMS::Core
|
4
6
|
|
5
7
|
REPORT_SERVICE = "ReportService"
|
6
8
|
MESSAGE_PARAM_ORDER = [ :performanceData, :startDate, :endDate, :levelOfDetails, :reportType, :device ]
|
9
|
+
DEFAULT_OPTIONS = { max_retries: 10, retry_timeout: false, current_retry: 0 }
|
10
|
+
|
11
|
+
attr_reader :max_retries, :retry_timeout, :current_retry
|
7
12
|
|
8
|
-
def initialize(credentials)
|
13
|
+
def initialize(credentials, options = {})
|
9
14
|
@client = initialise_client(REPORT_SERVICE, credentials)
|
15
|
+
set_options(options)
|
10
16
|
end
|
11
17
|
|
12
18
|
def create_report(report, params)
|
@@ -29,12 +35,29 @@ module BaiduSMS
|
|
29
35
|
private
|
30
36
|
|
31
37
|
def call(*args)
|
32
|
-
response = @client.call(*args)
|
33
38
|
# debugger
|
34
|
-
|
35
|
-
|
39
|
+
response = nil
|
40
|
+
|
41
|
+
begin
|
42
|
+
response = @client.call(*args)
|
43
|
+
header = response.header[:res_header]
|
44
|
+
raise BaiduSMSInvalidRequestError.new("#{header[:failures][:code]} - #{header[:failures][:message]}") unless header[:status].to_i == 0
|
45
|
+
rescue Curl::Err::TimeoutError => e
|
46
|
+
raise e unless retry_timeout && current_retry < max_retries
|
47
|
+
current_retry += 1
|
48
|
+
sleep [10 * (2 ** current_retry), 600].min
|
49
|
+
p "Retry number: #{current_retry}"
|
50
|
+
response = self.call(args)
|
51
|
+
end
|
52
|
+
|
36
53
|
response
|
37
54
|
end
|
55
|
+
|
56
|
+
def set_options(options)
|
57
|
+
DEFAULT_OPTIONS.each do |key, value|
|
58
|
+
instance_variable_set("@#{key}", options[key] || value)
|
59
|
+
end
|
60
|
+
end
|
38
61
|
|
39
62
|
def process_message_params(message)
|
40
63
|
MESSAGE_PARAM_ORDER.inject({}) do |result, param|
|
data/lib/baidu-sms/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: baidu-sms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Borkowski
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-11-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: savon
|