class BaseCRM::Configuration

Attributes

access_token[R]
base_url[R]
debug?[R]
logger[R]
max_retry[R]
retry_statuses[R]
timeout[R]
user_agent[R]
verbose[R]
verify_ssl[R]

Public Class Methods

new(options={}) click to toggle source
# File lib/basecrm/configuration.rb, line 16
def initialize(options={})
  @access_token = options[:access_token]
  @base_url = options[:base_url] || "https://api.getbase.com"
  @user_agent = options[:user_agent] || "BaseCRM/v2 Ruby/#{VERSION}"
  @logger = options[:logger]
  @verbose = !!options[:verbose]
  @timeout = options[:timeout] || 30
  @verify_ssl = options.fetch(:verify_ssl, true)
  @max_retry = options[:max_retry]
  @retry_statuses = options[:retry_statuses]
end

Public Instance Methods

inspect() click to toggle source
# File lib/basecrm/configuration.rb, line 57
def inspect
  instance_variables.map { |ivar|
    "#{ivar}=#{self.instance_variable_get(ivar)}"
  }.join("\n")
end
validate!() click to toggle source
# File lib/basecrm/configuration.rb, line 28
def validate!
  unless @access_token
    raise ConfigurationError.new('No access token provided. '\
      'Set your access token during client initialization using: '\
      '"Base::Client.new(access_token: <YOUR_PERSONAL_ACCESS_TOKEN>)".')
  end

  if @access_token =~ /\s/
    raise ConfigurationError.new('Provided access token is invalid '\
      'as it contains disallowed characters. '\
      'Please double-check your access token.')
  end

  if @access_token.length != 64
    raise ConfigurationError.new('Provided access token is invalid '\
      'as it has invalid length. '\
      'Please double-check your access token.')

  end

  unless /\A#{URI.regexp(%w(http https)).to_s}\z/.match(@base_url)
    raise ConfigurationError.new('Provided base url is invalid '\
      'as it is not a valid URI. '\
      'Please make sure it includes the scheme part, both http and https are accepted, '\
      'and the hierarchical part.')
  end

end