lib/braintree/configuration.rb in braintree-2.42.0 vs lib/braintree/configuration.rb in braintree-2.43.0
- old
+ new
@@ -1,25 +1,43 @@
module Braintree
class Configuration
API_VERSION = "4" # :nodoc:
DEFAULT_ENDPOINT = "api" # :nodoc:
+ READABLE_ATTRIBUTES = [
+ :merchant_id,
+ :public_key,
+ :private_key,
+ ]
+
+ WRITABLE_ATTRIBUTES = [
+ :custom_user_agent,
+ :endpoint,
+ :http_open_timeout,
+ :http_read_timeout,
+ :logger,
+ :merchant_id,
+ :public_key,
+ :private_key,
+ :environment,
+ ]
+
class << self
- attr_writer :custom_user_agent, :endpoint, :logger, :merchant_id, :public_key, :private_key
+ attr_writer *WRITABLE_ATTRIBUTES
end
- attr_reader :merchant_id, :public_key, :private_key
+ attr_reader *READABLE_ATTRIBUTES
def self.expectant_reader(*attributes) # :nodoc:
attributes.each do |attribute|
(class << self; self; end).send(:define_method, attribute) do
attribute_value = instance_variable_get("@#{attribute}")
raise ConfigurationError.new(attribute.to_s, "needs to be set") unless attribute_value
attribute_value
end
end
end
- expectant_reader :environment, :merchant_id, :public_key, :private_key
+ expectant_reader *([:environment] + READABLE_ATTRIBUTES)
# Sets the Braintree environment to use. Valid values are <tt>:sandbox</tt> and <tt>:production</tt>
def self.environment=(env)
unless [:development, :qa, :sandbox, :production].include?(env)
raise ArgumentError, "#{env.inspect} is not a valid environment"
@@ -34,17 +52,27 @@
def self.instantiate # :nodoc:
config = new(
:custom_user_agent => @custom_user_agent,
:endpoint => @endpoint,
:environment => environment,
+ :http_open_timeout => http_open_timeout,
+ :http_read_timeout => http_read_timeout,
:logger => logger,
:merchant_id => merchant_id,
:private_key => private_key,
:public_key => public_key
)
end
+ def self.http_open_timeout
+ @http_open_timeout ||= 60
+ end
+
+ def self.http_read_timeout
+ @http_read_timeout ||= 60
+ end
+
def self.logger
@logger ||= _default_logger
end
def self.signature_service
@@ -54,11 +82,11 @@
def self.sha256_signature_service
instantiate.sha256_signature_service
end
def initialize(options = {})
- [:endpoint, :environment, :public_key, :private_key, :custom_user_agent, :logger].each do |attr|
+ WRITABLE_ATTRIBUTES.each do |attr|
instance_variable_set "@#{attr}", options[attr]
end
@merchant_id = options[:merchant_id] || options[:partner_id]
end
@@ -100,9 +128,17 @@
end
end
def protocol # :nodoc:
ssl? ? "https" : "http"
+ end
+
+ def http_open_timeout
+ @http_open_timeout
+ end
+
+ def http_read_timeout
+ @http_read_timeout
end
def server # :nodoc:
case @environment
when :development