Sha256: e1ae1280d7cd2a91fe5e7c76ca3acdb1a210558c9ba05aeef94cf82aae096805
Contents?: true
Size: 1.72 KB
Versions: 5
Compression:
Stored size: 1.72 KB
Contents
module FinApps module REST class Configuration # :nodoc: include FinApps::HashConstructable using CoreExtensions::Integerable 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? 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 def valid_host? host.start_with?('http://', 'https://') end end end end
Version data entries
5 entries across 5 versions & 1 rubygems