Class: BaseCRM::Configuration
- Inherits:
-
Object
- Object
- BaseCRM::Configuration
- Defined in:
- lib/basecrm/configuration.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#max_retry ⇒ Object
readonly
Returns the value of attribute max_retry.
-
#retry_statuses ⇒ Object
readonly
Returns the value of attribute retry_statuses.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#user_agent ⇒ Object
readonly
Returns the value of attribute user_agent.
-
#verbose ⇒ Object
(also: #debug?)
readonly
Returns the value of attribute verbose.
-
#verify_ssl ⇒ Object
readonly
Returns the value of attribute verify_ssl.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #inspect ⇒ Object
- #validate! ⇒ Object
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(={}) @access_token = [:access_token] @base_url = [:base_url] || "https://api.getbase.com" @user_agent = [:user_agent] || "BaseCRM/v2 Ruby/#{VERSION}" @logger = [:logger] @verbose = !![:verbose] @timeout = [:timeout] || 30 @verify_ssl = .fetch(:verify_ssl, true) @max_retry = [:max_retry] @retry_statuses = [:retry_statuses] end |
Instance Attribute Details
#access_token ⇒ Object (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_url ⇒ Object (readonly)
Returns the value of attribute base_url.
6 7 8 |
# File 'lib/basecrm/configuration.rb', line 6 def base_url @base_url end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
13 14 15 |
# File 'lib/basecrm/configuration.rb', line 13 def logger @logger end |
#max_retry ⇒ Object (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_statuses ⇒ Object (readonly)
Returns the value of attribute retry_statuses.
11 12 13 |
# File 'lib/basecrm/configuration.rb', line 11 def retry_statuses @retry_statuses end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
8 9 10 |
# File 'lib/basecrm/configuration.rb', line 8 def timeout @timeout end |
#user_agent ⇒ Object (readonly)
Returns the value of attribute user_agent.
7 8 9 |
# File 'lib/basecrm/configuration.rb', line 7 def user_agent @user_agent end |
#verbose ⇒ Object (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_ssl ⇒ Object (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
#inspect ⇒ Object
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 |