lib/finapps/rest/configuration.rb in finapps-2.0.6 vs lib/finapps/rest/configuration.rb in finapps-2.0.10

- old
+ new

@@ -1,52 +1,24 @@ +# frozen_string_literal: true module FinApps module REST + # Represents the client configuration options class Configuration # :nodoc: - include FinApps::HashConstructable + using ObjectExtensions + using HashExtensions - using CoreExtensions::Integerable + attr_accessor :host, + :tenant_identifier, :tenant_token, + :user_identifier, :user_token, + :proxy, :timeout, :retry_limit, :log_level - RUBY = "#{RUBY_ENGINE}/#{RUBY_PLATFORM} #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}".freeze - HEADERS = { - accept: 'application/json', - user_agent: "finapps-ruby/#{FinApps::VERSION} (#{RUBY})" - }.freeze - - attr_accessor :host, :timeout, :tenant_credentials, :user_credentials, :url, - :proxy_addr, :proxy_port, :proxy_user, :proxy_pass, - :retry_limit, :log_level - - def initialize(options) - super(options, FinApps::REST::Defaults::DEFAULTS) - validate - @url = "#{host}/v#{FinApps::REST::Defaults::API_VERSION}/" - end - - def connection_options - {url: url, - request: {open_timeout: timeout, timeout: timeout}, - headers: {accept: HEADERS[:accept], user_agent: HEADERS[:user_agent]}} - end - - def valid_user_credentials? - valid_credentials? user_credentials - end - - private - - def validate - raise FinApps::MissingArgumentsError.new 'Missing tenant_credentials.' unless valid_tenant_credentials? + def initialize(options={}) + FinApps::REST::Defaults::DEFAULTS.merge(options.compact).each {|key, value| public_send("#{key}=", value) } raise FinApps::InvalidArgumentsError.new "Invalid argument. {host: #{host}}" unless valid_host? raise FinApps::InvalidArgumentsError.new "Invalid argument. {timeout: #{timeout}}" unless timeout.integer? end - def valid_tenant_credentials? - valid_credentials? tenant_credentials - end - - def valid_credentials?(h) - h.is_a?(Hash) && %i(identifier token).all? {|x| h.key? x } && h.values.all?(&:present?) - end + private def valid_host? host.start_with?('http://', 'https://') end end