Class: Insightly::Configuration

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

Constant Summary collapse

API_VERSION =

:nodoc:

"v1"
DEFAULT_ENDPOINT =

:nodoc:

"https://api.insight.ly/v1"

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Configuration

Returns a new instance of Configuration.



53
54
55
56
57
# File 'lib/insightly/configuration.rb', line 53

def initialize(options = {})
  [:endpoint, :api_key, :custom_user_agent, :logger].each do |attr|
    instance_variable_set "@#{attr}", options[attr]
  end
end

Class Attribute Details

.api_key=(value) ⇒ Object (writeonly)

Sets the attribute api_key

Parameters:

  • value

    the value to set the attribute api_key to.



15
16
17
# File 'lib/insightly/configuration.rb', line 15

def api_key=(value)
  @api_key = value
end

.custom_user_agent=(value) ⇒ Object (writeonly)

Sets the attribute custom_user_agent

Parameters:

  • value

    the value to set the attribute custom_user_agent to.



15
16
17
# File 'lib/insightly/configuration.rb', line 15

def custom_user_agent=(value)
  @custom_user_agent = value
end

.endpoint=(value) ⇒ Object (writeonly)

Sets the attribute endpoint

Parameters:

  • value

    the value to set the attribute endpoint to.



15
16
17
# File 'lib/insightly/configuration.rb', line 15

def endpoint=(value)
  @endpoint = value
end

.loggerObject



49
50
51
# File 'lib/insightly/configuration.rb', line 49

def self.logger
  @logger ||= _default_logger
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



17
18
19
# File 'lib/insightly/configuration.rb', line 17

def api_key
  @api_key
end

#custom_user_agentObject (readonly)

Returns the value of attribute custom_user_agent.



17
18
19
# File 'lib/insightly/configuration.rb', line 17

def custom_user_agent
  @custom_user_agent
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



17
18
19
# File 'lib/insightly/configuration.rb', line 17

def endpoint
  @endpoint
end

Class Method Details

._debug_loggerObject

:nodoc:



81
82
83
84
85
# File 'lib/insightly/configuration.rb', line 81

def self._debug_logger # :nodoc:
  logger = Logger.new(STDOUT)
  logger.level = Logger::DEBUG
  logger
end

._default_loggerObject

:nodoc:



76
77
78
79
80
# File 'lib/insightly/configuration.rb', line 76

def self._default_logger # :nodoc:
  logger = Logger.new(STDOUT)
  logger.level = Logger::INFO
  logger
end

.custom_fields_for_contacts(*args) ⇒ Object



45
46
47
# File 'lib/insightly/configuration.rb', line 45

def self.custom_fields_for_contacts(*args)
  Insightly::Contact.custom_fields(*args)
end

.custom_fields_for_opportunities(*args) ⇒ Object



39
40
41
# File 'lib/insightly/configuration.rb', line 39

def self.custom_fields_for_opportunities(*args)
  Insightly::Opportunity.custom_fields(*args)
end

.custom_fields_for_organisations(*args) ⇒ Object



42
43
44
# File 'lib/insightly/configuration.rb', line 42

def self.custom_fields_for_organisations(*args)
  Insightly::Organisation.custom_fields(*args)
end

.expectant_reader(*attributes) ⇒ Object

:nodoc:



19
20
21
22
23
24
25
26
27
# File 'lib/insightly/configuration.rb', line 19

def self.expectant_reader(*attributes) # :nodoc:
  attributes.each do |attribute|
    (class << self; self; end).send(:define_method, attribute) do
      attribute_value = instance_variable_get("@#{attribute}")
      raise ConfigurationError.new(attribute.to_s, "needs to be set") unless attribute_value
      attribute_value
    end
  end
end

.instantiateObject

:nodoc:



30
31
32
33
34
35
36
37
# File 'lib/insightly/configuration.rb', line 30

def self.instantiate # :nodoc:
  config = new(
    :custom_user_agent => @custom_user_agent,
    :endpoint => @endpoint,
    :logger => logger,
    :api_key => api_key
  )
end

Instance Method Details

#api_versionObject

:nodoc:



59
60
61
# File 'lib/insightly/configuration.rb', line 59

def api_version # :nodoc:
  API_VERSION
end

#loggerObject



67
68
69
# File 'lib/insightly/configuration.rb', line 67

def logger
  @logger ||= self.class._default_logger
end

#user_agentObject

:nodoc:



71
72
73
74
# File 'lib/insightly/configuration.rb', line 71

def user_agent # :nodoc:
  base_user_agent = "Insightly Ruby Gem #{Insightly::Version::String}"
  @custom_user_agent ? "#{base_user_agent} (#{@custom_user_agent})" : base_user_agent
end