~singpolyma/sgx-jmp

ref: 045da39f25b74034e7bba44cb5f1db48a935ba84 sgx-jmp/lib/api.rb -rw-r--r-- 764 bytes
045da39fStephen Paul Weber Hotfix: arguments in wrong order 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
# frozen_string_literal: true

class API
	def self.for(customer)
		EMPromise.all([
			sgx_jmp?(customer),
			api_version(customer)
		]).then do |is_jmp, api|
			is_jmp ? JMP.new : api
		end
	end

	def self.sgx_jmp?(customer)
		key = "catapult_cred-customer_#{customer.customer_id}@jmp.chat"
		REDIS.exists(key).then { |is_sgx| is_sgx == 1 }
	end

	def self.api_version(customer)
		REDIS.lindex("catapult_cred-#{customer.jid}", 0).then do |api|
			case api
			when CONFIG.dig(:catapult, :user)
				V1.new
			when CONFIG.dig(:creds, :account)
				V2.new
			else
				new
			end
		end
	end

	class V1 < API
		def to_s
			"v1"
		end
	end

	class V2 < API
		def to_s
			"v2"
		end
	end

	class JMP < V2
		def to_s
			"sgx-jmp"
		end
	end

	def to_s
		"not JMP"
	end
end