Class: Veritrans::Config
- Inherits:
-
Object
- Object
- Veritrans::Config
- Defined in:
- lib/veritrans/config.rb
Instance Method Summary collapse
- #api_host ⇒ Object
-
#api_host=(value) ⇒ Object
API Server hostname, this allow to switch between production and sandbox.
- #client_key ⇒ Object
-
#client_key=(value) ⇒ Object
Merhcant’s Client key, used to make getToken request.
- #http_options ⇒ Object
-
#http_options=(options) ⇒ Object
This will override http request settings for api calls.
-
#initialize(options = nil) ⇒ Config
constructor
A new instance of Config.
- #inspect ⇒ Object
-
#load_config(filename, yml_section = nil) ⇒ Object
(also: #load_yml)
Loads YAML file and assign config values.
- #server_key ⇒ Object
-
#server_key=(value) ⇒ Object
Merhcant’s Server key, used to sign every http API call.
Constructor Details
#initialize(options = nil) ⇒ Config
Returns a new instance of Config.
9 10 11 12 |
# File 'lib/veritrans/config.rb', line 9 def initialize( = nil) @api_host = "https://api.sandbox.veritrans.co.id" apply() if end |
Instance Method Details
#api_host ⇒ Object
52 53 54 |
# File 'lib/veritrans/config.rb', line 52 def api_host @api_host end |
#api_host=(value) ⇒ Object
API Server hostname, this allow to switch between production and sandbox
Should be “api.sandbox.veritrans.co.id” or “api.veritrans.co.id”
Default is “api.sandbox.veritrans.co.id”
48 49 50 |
# File 'lib/veritrans/config.rb', line 48 def api_host=(value) @api_host = value end |
#client_key ⇒ Object
24 25 26 |
# File 'lib/veritrans/config.rb', line 24 def client_key @client_key end |
#client_key=(value) ⇒ Object
Merhcant’s Client key, used to make getToken request. (only for VT-Direct)
Can be found in merchant portal: Settings -> Access Keys
19 20 21 |
# File 'lib/veritrans/config.rb', line 19 def client_key=(value) @client_key = value end |
#http_options ⇒ Object
82 83 84 |
# File 'lib/veritrans/config.rb', line 82 def @http_options end |
#http_options=(options) ⇒ Object
This will override http request settings for api calls. http_options should be hash, it will be merged with connection options for every request.
Full list of options: github.com/excon/excon/blob/master/lib/excon/constants.rb
For unsupported key it will raise ArgumentError
Veritrans.config. = {tcp_nodelay: true, ssl_version: 'TLSv1'}
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/veritrans/config.rb', line 66 def () unless .is_a?(Hash) raise ArgumentError, "http_options should be a hash" end # Validate allowed keys diff = .keys.map(&:to_sym) - Excon::VALID_CONNECTION_KEYS if diff.size > 0 raise ArgumentError, "http_options contain unsupported keys: #{diff.inspect}\n" + "Supported keys are: #{Excon::VALID_CONNECTION_KEYS.inspect}" end @http_options = end |
#inspect ⇒ Object
131 132 133 134 135 136 137 |
# File 'lib/veritrans/config.rb', line 131 def inspect "<Veritrans::Config " + "@api_host=#{@api_host.inspect} " + "@server_key=#{@server_key.inspect} " + "@client_key=#{@client_key.inspect} " + "@http_options=#{@http_options.inspect}>" end |
#load_config(filename, yml_section = nil) ⇒ Object Also known as: load_yml
Loads YAML file and assign config values
Supports #section in filename to choose one section. If you are using Rails, it will try to use Rails.env as a section name
Available config keys: server_key, client_key, api_host, http_options
Veritrans.setup do
config.load_yml "#{Rails.root.to_s}/config/veritrans.yml#development"
end
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/veritrans/config.rb', line 98 def load_config(filename, yml_section = nil) yml_file, file_yml_section = filename.to_s.split('#') config_data = YAML.load(ERB.new(File.read(yml_file)).result) yml_section ||= file_yml_section if defined?(Rails) && !yml_section yml_section = Rails.env.to_s end if yml_section && !config_data.has_key?(yml_section) STDERR.puts "Veritrans: Can not find section #{yml_section.inspect} in file #{yml_file}" STDERR.puts " Available sections: #{config_data.keys}" if config_data['development'] && config_data['development']['server_key'] new_section = 'development' end first_key = config_data.keys.first if config_data[first_key]['server_key'] new_section = first_key end if new_section STDERR.puts "Veritrans: Using first section #{new_section.inspect}" yml_section = new_section end end apply(yml_section ? config_data[yml_section] : config_data) end |
#server_key ⇒ Object
37 38 39 |
# File 'lib/veritrans/config.rb', line 37 def server_key @server_key end |
#server_key=(value) ⇒ Object
Merhcant’s Server key, used to sign every http API call.
Can be found in merchant portal: Settings -> Access Keys
33 34 35 |
# File 'lib/veritrans/config.rb', line 33 def server_key=(value) @server_key = value end |