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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4866a8eab55ee7d162867adfcff91123c573918c
4
- data.tar.gz: 16ff9b33578d31d833acb1c96ab7345b483ed04a
3
+ metadata.gz: 125f13235de60599a74661d20d494aafb319f518
4
+ data.tar.gz: 55b21fb9657383e6077a5d8ee57dbf930a162f99
5
5
  SHA512:
6
- metadata.gz: e75b59f0cd8c96dfe74c8e8edf0c9f438d0fab6e8ba27d5153a0199808c6549641fde5c5b6439836a2664dbab626aa559d9bf3e589af7f7acac04598a8eabb28
7
- data.tar.gz: 1f7dc48abcda2a85628e3f223868c707923261936872e99821817aa505d2660cffc7795443ba2faed1570aa377cf2483b1ebbea9aaf2059209de738cea316b56
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
- header = response.header[:res_header]
35
- raise BaiduSMSInvalidRequestError.new("#{header[:failures][:code]} - #{header[:failures][:message]}") unless header[:status].to_i == 0
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|
@@ -1,3 +1,3 @@
1
1
  module BaiduSMS
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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.2
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-10-18 00:00:00.000000000 Z
12
+ date: 2013-11-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: savon