Class: Payoneer::Configuration::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/payoneer/configuration.rb

Constant Summary collapse

SANDBOX_API_URL =
'https://api.sandbox.payoneer.com/Payouts/HttpApi/API.aspx'
PRODUCTION_API_URL =
'https://api.payoneer.com/Payouts/HttpApi/API.aspx'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Config

Returns a new instance of Config.



27
28
29
30
31
32
# File 'lib/payoneer/configuration.rb', line 27

def initialize(options)
  options.each do |key, value|
    send("#{key}=", value)
  end
  self.normalize_proxies
end

Instance Attribute Details

#envObject

Returns the value of attribute env.



25
26
27
# File 'lib/payoneer/configuration.rb', line 25

def env
  @env
end

#partner_api_passwordObject

Returns the value of attribute partner_api_password.



25
26
27
# File 'lib/payoneer/configuration.rb', line 25

def partner_api_password
  @partner_api_password
end

#partner_idObject

Returns the value of attribute partner_id.



25
26
27
# File 'lib/payoneer/configuration.rb', line 25

def partner_id
  @partner_id
end

#partner_usernameObject

Returns the value of attribute partner_username.



25
26
27
# File 'lib/payoneer/configuration.rb', line 25

def partner_username
  @partner_username
end

#program_idObject

Returns the value of attribute program_id.



25
26
27
# File 'lib/payoneer/configuration.rb', line 25

def program_id
  @program_id
end

#proxyObject

Returns the value of attribute proxy.



25
26
27
# File 'lib/payoneer/configuration.rb', line 25

def proxy
  @proxy
end

#proxy_indexObject

Returns the value of attribute proxy_index.



25
26
27
# File 'lib/payoneer/configuration.rb', line 25

def proxy_index
  @proxy_index
end

Instance Method Details

#api_urlObject



47
48
49
# File 'lib/payoneer/configuration.rb', line 47

def api_url
  production? ? PRODUCTION_API_URL : SANDBOX_API_URL
end

#normalize_proxiesObject



34
35
36
37
# File 'lib/payoneer/configuration.rb', line 34

def normalize_proxies
  self.proxy = self.proxy ? Array(proxy) : []
  self.proxy_index = 0
end

#production?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/payoneer/configuration.rb', line 43

def production?
  self.env == 'production'
end

#rotate_proxyObject



57
58
59
# File 'lib/payoneer/configuration.rb', line 57

def rotate_proxy
  self.proxy_index = (self.proxy_index + 1) % self.proxy.size
end

#setup_proxy_if_setObject



51
52
53
54
55
# File 'lib/payoneer/configuration.rb', line 51

def setup_proxy_if_set
  return if self.proxy.size == 0
  # TODO New in 2.0: Specify a per-request proxy https://github.com/rest-client/rest-client#proxy
  RestClient.proxy = self.proxy[self.proxy_index]
end

#validate!Object

Raises:

  • (ConfigurationError)


39
40
41
# File 'lib/payoneer/configuration.rb', line 39

def validate!
  raise ConfigurationError.new unless %w(partner_username partner_api_password partner_id program_id env).all?{|k| self.send(k).present? }
end