Class: UserApp::ProxyClient

Inherits:
Object
  • Object
show all
Defined in:
lib/userapp/userapp.rb,
lib/userapp/proxy_client.rb

Direct Known Subclasses

API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ProxyClient

Returns a new instance of ProxyClient.



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

def initialize(*args)
	@services = Hash.new()
	if args.length == 2 and args[0].is_a?(Client)
		@client = args[0]
		@service_name = args[1]
	else
		@client = Client.new(*args)
	end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *args) ⇒ Object



26
27
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/userapp/proxy_client.rb', line 26

def method_missing(method_id, *args)
	if args.length > 0
		if self.service_name.nil?
			raise UserApp::Error.new("Unable to call method on base service.")
		end

		self.client.call(self.get_options().version, self.service_name, self.camel_case_lower(method_id.to_s()), args[0])
	else
		target_service = nil

		if self.services[method_id]
			return self.services[method_id]
		end

		if self.service_name.nil? and method_id.length >= 2 and method_id[0] == 'v' and method_id[1, method_id.length-1].match(/\A[0-9]+\Z/)
			self.get_options().version = method_id[1].to_i
		else
			if !self.service_name.nil?
				target_service = self.service_name.to_s + '.' + self.camel_case_lower(method_id.to_s)
			else
				target_service = self.camel_case_lower(method_id.to_s)
			end
		end

		proxy = ProxyClient.new(self.client, target_service)
		self.services[method_id] = proxy

		return proxy
	end
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



8
9
10
# File 'lib/userapp/proxy_client.rb', line 8

def client
  @client
end

#service_nameObject

Returns the value of attribute service_name.



10
11
12
# File 'lib/userapp/proxy_client.rb', line 10

def service_name
  @service_name
end

#servicesObject

Returns the value of attribute services.



9
10
11
# File 'lib/userapp/proxy_client.rb', line 9

def services
  @services
end

Instance Method Details

#get_optionsObject



22
23
24
# File 'lib/userapp/proxy_client.rb', line 22

def get_options()
	return self.client.get_options()
end