Class: BaseCRM::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/basecrm/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Configuration

Returns a new instance of Configuration.



16
17
18
19
20
21
22
23
24
25
26
# 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

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



5
6
7
# File 'lib/basecrm/configuration.rb', line 5

def access_token
  @access_token
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



6
7
8
# File 'lib/basecrm/configuration.rb', line 6

def base_url
  @base_url
end

#loggerObject (readonly)

Returns the value of attribute logger.



13
14
15
# File 'lib/basecrm/configuration.rb', line 13

def logger
  @logger
end

#max_retryObject (readonly)

Returns the value of attribute max_retry.



10
11
12
# File 'lib/basecrm/configuration.rb', line 10

def max_retry
  @max_retry
end

#retry_statusesObject (readonly)

Returns the value of attribute retry_statuses.



11
12
13
# File 'lib/basecrm/configuration.rb', line 11

def retry_statuses
  @retry_statuses
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



8
9
10
# File 'lib/basecrm/configuration.rb', line 8

def timeout
  @timeout
end

#user_agentObject (readonly)

Returns the value of attribute user_agent.



7
8
9
# File 'lib/basecrm/configuration.rb', line 7

def user_agent
  @user_agent
end

#verboseObject (readonly) Also known as: debug?

Returns the value of attribute verbose.



13
14
15
# File 'lib/basecrm/configuration.rb', line 13

def verbose
  @verbose
end

#verify_sslObject (readonly)

Returns the value of attribute verify_ssl.



9
10
11
# File 'lib/basecrm/configuration.rb', line 9

def verify_ssl
  @verify_ssl
end

Instance Method Details

#inspectObject



57
58
59
60
61
# File 'lib/basecrm/configuration.rb', line 57

def inspect
  instance_variables.map { |ivar|
    "#{ivar}=#{self.instance_variable_get(ivar)}"
  }.join("\n")
end

#validate!Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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