payoneer_ruby_sdk 0.1.3 → 0.1.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: f6540d80493796dfe1f55732d520e23ee03dd155
4
- data.tar.gz: d7d80db98ade09cdc0f11c823d96d50720353289
3
+ metadata.gz: e157dfc6e430bda6a7c4af180e75792afeccd0af
4
+ data.tar.gz: c09dd594c046f92793b6782c31881d51c0770c42
5
5
  SHA512:
6
- metadata.gz: 05bce2ac84a5b885af81ec591b0f5174ceb97edaef4c9feff2f56ef96d8fb2718b6fe7832b920506a74654110ef6e242a46f2db4d1416770802786bcc9ef8cbc
7
- data.tar.gz: 490b550e49bd959eb3aecfe87500bf5519cbb2d42f7051b4dbde4f47b0775597244d5b90ee6176390d087124e2439a160711f431cfc1d1d044dff55002614c9a
6
+ metadata.gz: e0a36cebe97264dabc45576117a1876275e7587a2a8ec542e6419c79d748c24bebc5f263f2b60d98fc1360e3853fcd7fdbfd8a7302fafda9ffb6b91955fcc059
7
+ data.tar.gz: 50afdede823c22ffa7e5f428ca4b03a38c86e3a89d21bcefe318168465832aa40f4ce80b8986a91e18b43840e9c4ea08bc427099a048a13f4eafe4e78cfb08b1
data/README.md CHANGED
@@ -26,7 +26,8 @@ Payoneer.configure({
26
26
  partner_api_password: '<payoneer_api_password>',
27
27
  partner_id: '<payoneer_partner_id>',
28
28
  program_id: '<payoneer_program_id>',
29
- env: 'production'
29
+ env: 'production',
30
+ proxy: 'http://example.com' # optional
30
31
  })
31
32
  ```
32
33
 
@@ -25,13 +25,35 @@ module Payoneer
25
25
 
26
26
  request_params = default_params.merge(mname: method_name).merge(params)
27
27
 
28
- response = RestClient.post(config.api_url, request_params)
28
+ request = Request.new(config)
29
+ response = request.execute(request_params)
29
30
 
30
31
  fail Errors::ApiError.new(response.code, response.body) unless response.code == 200
31
32
 
32
33
  to_response(response)
33
34
  end
34
35
 
36
+ class Request
37
+ attr_accessor :max_attempts, :num_attempts, :config
38
+ def initialize(config)
39
+ self.config = config
40
+ self.max_attempts = config.proxy.size
41
+ self.num_attempts = 0
42
+ end
43
+ def execute(request_params)
44
+ self.num_attempts += 1
45
+ config.setup_proxy_if_set
46
+ RestClient.post(config.api_url, request_params)
47
+ rescue RestClient::RequestTimeout => e
48
+ # if Net::OpenTimeout === e.original_exception &&
49
+ if self.max_attempts > self.num_attempts
50
+ config.rotate_proxy
51
+ retry
52
+ end
53
+ raise e
54
+ end
55
+ end
56
+
35
57
  def config
36
58
  ::Payoneer.config
37
59
  end
@@ -22,12 +22,18 @@ module Payoneer
22
22
  class Config
23
23
  SANDBOX_API_URL = 'https://api.sandbox.payoneer.com/Payouts/HttpApi/API.aspx'
24
24
  PRODUCTION_API_URL = 'https://api.payoneer.com/Payouts/HttpApi/API.aspx'
25
- attr_accessor :partner_username, :partner_api_password, :partner_id, :program_id, :env
25
+ attr_accessor :partner_username, :partner_api_password, :partner_id, :program_id, :env, :proxy, :proxy_index
26
26
 
27
27
  def initialize(options)
28
28
  options.each do |key, value|
29
29
  send("#{key}=", value)
30
30
  end
31
+ self.normalize_proxies
32
+ end
33
+
34
+ def normalize_proxies
35
+ self.proxy = self.proxy ? Array(proxy) : []
36
+ self.proxy_index = 0
31
37
  end
32
38
 
33
39
  def validate!
@@ -41,6 +47,17 @@ module Payoneer
41
47
  def api_url
42
48
  production? ? PRODUCTION_API_URL : SANDBOX_API_URL
43
49
  end
50
+
51
+ def setup_proxy_if_set
52
+ return if self.proxy.size == 0
53
+ # TODO New in 2.0: Specify a per-request proxy https://github.com/rest-client/rest-client#proxy
54
+ RestClient.proxy = self.proxy[self.proxy_index]
55
+ end
56
+
57
+ def rotate_proxy
58
+ self.proxy_index = (self.proxy_index + 1) % self.proxy.size
59
+ end
60
+
44
61
  end
45
62
  end
46
63
  end
@@ -1,3 +1,3 @@
1
1
  module Payoneer
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: payoneer_ruby_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - kissrobber
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-09 00:00:00.000000000 Z
11
+ date: 2015-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client