baidu-sms 0.0.3 → 0.0.4

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: 125f13235de60599a74661d20d494aafb319f518
4
- data.tar.gz: 55b21fb9657383e6077a5d8ee57dbf930a162f99
3
+ metadata.gz: da1a6b1d4c9c33e89428e12c5416449607ddf211
4
+ data.tar.gz: 7892dfcf0a9a73d01998aec21b49002a6568b9e2
5
5
  SHA512:
6
- metadata.gz: 36d2bc6f87716aa2f509eff8d6ccaf414c83c0ae89a92a420775712951949aa74ed1680c4681dcad709768efc1db061abcd1c77deb57eb4d186e65f9caae6201
7
- data.tar.gz: bc9da75759366e14427982c8d7740e115b1bc7d45c0f5a802c67175255f17c27229aa568fcd18f953b379fc082c43d0d673cdb1b4c23f9e9110eaac1aa3342f7
6
+ metadata.gz: 1b4c80345dfe7226bd5adc77cda1529d6310041bf4b9f4da3b4c950bbf7095d83413ef4d1fac2120bdee65dbaeb0ed4297097f0280ef06999e9d0fbebff376d7
7
+ data.tar.gz: 3d3f7ba23db2e08ba0a4785fb2e0299b8089afa7037e052174ee66c368768e88e2a32c3d7cbc5e366a202b0ac03271f98dd2d4aa3f2a0cd535292c5d99ec679c
@@ -5,6 +5,7 @@ module BaiduSMS
5
5
  SMS_RESOURCE = "/sem/sms/v3/"
6
6
  COMMON_RESOURCE = "/sem/common/v2"
7
7
  AUTH_NS = "ns2"
8
+ DEFAULT_CLIENT_OPTIONS = { open_timeout: 300, read_timeout: 300, ssl_verify_mode: :none }
8
9
 
9
10
  def authorise_headers(username, password, token)
10
11
  { auth_namespace('AuthHeader') => { auth_namespace('username') => username,
@@ -12,15 +13,25 @@ module BaiduSMS
12
13
  auth_namespace('token') => token } }
13
14
  end
14
15
 
15
- def initialise_client(service, credentials)
16
+ def initialise_client(service, credentials, options = {})
17
+ client_options = set_client_options(options)
16
18
  wsdl_namespace_location = BAIDU_HOST[:secure] + SMS_RESOURCE + service + "?wsdl"
17
19
  authorise_namespace_location = BAIDU_HOST[:basic] + COMMON_RESOURCE
18
20
  Savon.client(wsdl: wsdl_namespace_location,
19
21
  namespaces: { "xmlns:#{AUTH_NS}" => authorise_namespace_location },
20
- soap_header: authorise_headers(credentials[:username], credentials[:password], credentials[:token])
22
+ soap_header: authorise_headers(credentials[:username], credentials[:password], credentials[:token]),
23
+ open_timeout: client_options[:open_timeout],
24
+ read_timeout: client_options[:read_timeout],
25
+ ssl_verify_mode: client_options[:ssl_verify_mode]
21
26
  )
22
27
  end
23
28
 
29
+ private
30
+
31
+ def set_client_options(options)
32
+ DEFAULT_CLIENT_OPTIONS.inject({}) { |i, (k, v)| i[k] = options[k] || v; i }
33
+ end
34
+
24
35
  def auth_namespace(str)
25
36
  "#{AUTH_NS}:#{str}"
26
37
  end
@@ -1,5 +1,3 @@
1
- require 'curl'
2
-
3
1
  module BaiduSMS
4
2
  class ReportService
5
3
  include BaiduSMS::Core
@@ -42,7 +40,7 @@ module BaiduSMS
42
40
  response = @client.call(*args)
43
41
  header = response.header[:res_header]
44
42
  raise BaiduSMSInvalidRequestError.new("#{header[:failures][:code]} - #{header[:failures][:message]}") unless header[:status].to_i == 0
45
- rescue Curl::Err::TimeoutError => e
43
+ rescue HTTPI::TimeoutError => e
46
44
  raise e unless retry_timeout && current_retry < max_retries
47
45
  current_retry += 1
48
46
  sleep [10 * (2 ** current_retry), 600].min
@@ -1,3 +1,3 @@
1
1
  module BaiduSMS
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
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.3
4
+ version: 0.0.4
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-11-05 00:00:00.000000000 Z
12
+ date: 2013-11-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: savon
@@ -79,4 +79,3 @@ signing_key:
79
79
  specification_version: 4
80
80
  summary: Wrapper for connecting to the Baidu Search Marketing API
81
81
  test_files: []
82
- has_rdoc: