~singpolyma/sgx-jmp

sgx-jmp/lib/api.rb -rw-r--r-- 669 bytes
c4fc3de0Stephen Paul Weber Revert "Merge branch 'limit-top-up-freq'" a day 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
# 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(:creds, :account)
				V2.new
			else
				new
			end
		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