Class: Kerio::Api::Method::Generic

Inherits:
Object
  • Object
show all
Includes:
ChainableMethod
Defined in:
lib/kerio-api/method/generic.rb

Direct Known Subclasses

Download, Session::Login, Upload

Instance Method Summary collapse

Methods included from ChainableMethod

#next_method

Constructor Details

#initialize(params) ⇒ Generic

Returns a new instance of Generic.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/kerio-api/method/generic.rb', line 7

def initialize (params)

	@names = params[:names]

	@session = params[:session]

	@args = params[:args]

	@block = params[:block]

	if ((@args.count > 0) || (@names.count == 2))
		__invoke_method
	end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



39
40
41
42
43
44
# File 'lib/kerio-api/method/generic.rb', line 39

def method_missing(method, *args, &block)

	@names.push(method)

	return next_method(names: @names, session: @session, args: args)
end

Instance Method Details

#[](index) ⇒ Object



31
32
33
# File 'lib/kerio-api/method/generic.rb', line 31

def [](index)
	return __result[index]
end

#__invoke_methodObject



22
23
24
25
# File 'lib/kerio-api/method/generic.rb', line 22

def __invoke_method
		name = @names.join('.')
		@resp = @session.json_method(name, @args[0])
end

#__resultObject



27
28
29
# File 'lib/kerio-api/method/generic.rb', line 27

def __result
	return @resp['result']
end

#pretty_print(pp) ⇒ Object



35
36
37
# File 'lib/kerio-api/method/generic.rb', line 35

def pretty_print pp
	pp __result
end