Class: ZammadAPI::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/zammad_api/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Client

Returns a new instance of Client.



15
16
17
18
19
20
# File 'lib/zammad_api/client.rb', line 15

def initialize(config)
  @config    = config
  @logger    = ZammadAPI::Log.new(@config)
  @transport = ZammadAPI::Transport.new(@config, @logger)
  check_config
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *_args) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/zammad_api/client.rb', line 29

def method_missing(method, *_args)
  method     = modulize( method.to_s )
  class_name = "ZammadAPI::Resources::#{method}"
  begin
    class_object = Kernel.const_get(class_name)
  rescue
    raise "Resource for #{method} does not exist"
  end
  ZammadAPI::Dispatcher.new(@transport, class_object)
end

Instance Method Details

#perform_on_behalf_of(identifier) ⇒ Object



22
23
24
25
26
27
# File 'lib/zammad_api/client.rb', line 22

def perform_on_behalf_of(identifier)
  self.on_behalf_of = identifier
  yield.tap do |_|
    self.on_behalf_of = nil
  end
end