Class: ZapierRuby::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/zapier_ruby/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



5
6
7
8
9
10
# File 'lib/zapier_ruby/config.rb', line 5

def initialize
  self.base_uri = "https://zapier.com/hooks/catch/"
  self.web_hooks = { example_webhook: "webhook_id" }
  self.enable_logging = true
  self.logger = Logger.new(STDOUT)
end

Instance Attribute Details

#base_uriObject

Returns the value of attribute base_uri.



3
4
5
# File 'lib/zapier_ruby/config.rb', line 3

def base_uri
  @base_uri
end

#enable_loggingObject

Returns the value of attribute enable_logging.



3
4
5
# File 'lib/zapier_ruby/config.rb', line 3

def enable_logging
  @enable_logging
end

#loggerObject

Returns the value of attribute logger.



3
4
5
# File 'lib/zapier_ruby/config.rb', line 3

def logger
  @logger
end

#web_hooksObject

Returns the value of attribute web_hooks.



3
4
5
# File 'lib/zapier_ruby/config.rb', line 3

def web_hooks
  @web_hooks
end

Instance Method Details

#configure_with(path_to_yaml_file) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/zapier_ruby/config.rb', line 12

def configure_with(path_to_yaml_file)
  begin
    config_yaml = YAML::load(IO.read(path_to_yaml_file))
    reconfigure(config_yaml)
  rescue StandardError => e
    logger.error "YAML configuration file cannot be loaded. Using defaults. Error :#{e.message}"
    return
  end
end

#reconfigure(config = {}) ⇒ Object



22
23
24
# File 'lib/zapier_ruby/config.rb', line 22

def reconfigure(config = {})
  config.keys.select{|k| respond_to?("#{k}=")}.each{|k| self.send("#{k}=", config[k])}
end