Sha256: b75b171bdac8bacb4837cccd68054b9ab7cb85656a72454d63f8ab4fdd399364

Contents?: true

Size: 1.3 KB

Versions: 4

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module FinAppsCore
  module REST
    # Represents the client configuration options
    class Configuration # :nodoc:
      using ObjectExtensions

      attr_accessor :tenant_token, :user_identifier, :user_token,
                    :host, :proxy, :timeout, :retry_limit, :rashify,
                    :log_level, :request_id, :consumer_id

      def initialize(options = {})
        FinAppsCore::REST::Defaults::DEFAULTS.merge(remove_empty_options(options))
                                             .each {|key, value| public_send("#{key}=", value) }
        fail_invalid_host
        fail_invalid_timeout
      end

      def valid_user_credentials?
        FinAppsCore::REST::Credentials.new(user_identifier, user_token).valid?
      end

      private

      def fail_invalid_host
        return if valid_host?

        fail FinAppsCore::InvalidArgumentsError,
             "Invalid argument. {host: #{host}}"
      end

      def fail_invalid_timeout
        return if timeout.integer?

        fail FinAppsCore::InvalidArgumentsError,
             "Invalid argument. {timeout: #{timeout}}"
      end

      def valid_host?
        host.start_with?('http://', 'https://')
      end

      def remove_empty_options(hash)
        hash.reject {|_, value| value.nil? }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
finapps_core-5.0.11 lib/finapps_core/rest/configuration.rb
finapps_core-5.0.10 lib/finapps_core/rest/configuration.rb
finapps_core-5.0.9 lib/finapps_core/rest/configuration.rb
finapps_core-5.0.8 lib/finapps_core/rest/configuration.rb