1# frozen_string_literal: true
2
3class API
4 def self.for(customer)
5 EMPromise.all([
6 sgx_jmp?(customer),
7 api_version(customer)
8 ]).then do |is_jmp, api|
9 is_jmp ? JMP.new : api
10 end
11 end
12
13 def self.sgx_jmp?(customer)
14 key = "catapult_cred-customer_#{customer.customer_id}@jmp.chat"
15 REDIS.exists(key).then { |is_sgx| is_sgx == 1 }
16 end
17
18 def self.api_version(customer)
19 REDIS.lindex("catapult_cred-#{customer.jid}", 0).then do |api|
20 case api
21 when CONFIG.dig(:creds, :account)
22 V2.new
23 else
24 new
25 end
26 end
27 end
28
29 class V2 < API
30 def to_s
31 "v2"
32 end
33 end
34
35 class JMP < V2
36 def to_s
37 "sgx-jmp"
38 end
39 end
40
41 def to_s
42 "not JMP"
43 end
44end