Class: Pindo::BossClient

Inherits:
Object
  • Object
show all
Defined in:
lib/pindo/client/bossclient.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_type: "FunnyApp", is_dev: true, base_url: nil) ⇒ BossClient

Returns a new instance of BossClient.



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
56
57
58
59
60
61
62
63
# File 'lib/pindo/client/bossclient.rb', line 27

def initialize(app_type:"FunnyApp", is_dev:true, base_url:nil)

#   
    @app_type = app_type
    @is_dev = is_dev

    begin

      boss_config_file = File.join(File::expand_path(Pindoconfig.instance.pindo_common_configdir), "boss_client_config.json")
      @boss_config_json = JSON.parse(File.read(boss_config_file))
    
      @device_info_config = @boss_config_json["default_device_info"] 
      @base_url_config = @boss_config_json["base_url_config"]
      @salts_config = @boss_config_json["salts"]
      @requests_config = @boss_config_json["boss_req_config"]

    rescue => error
        raise Informative,  "加载boss 配置文件失败, 需要执行 pindo setup 或者pindo env dreamstudio"
    end 

    app_type_base_url_config = @base_url_config[@app_type]

    @base_url = nil

    if base_url.nil?
      if @is_dev
          @base_url = app_type_base_url_config["dev"]
      else
          @base_url = app_type_base_url_config["prod"]
      end
    else
      @base_url = base_url
    end



end

Instance Attribute Details

#app_typeObject

Returns the value of attribute app_type.



22
23
24
# File 'lib/pindo/client/bossclient.rb', line 22

def app_type
  @app_type
end

#base_urlObject

Returns the value of attribute base_url.



24
25
26
# File 'lib/pindo/client/bossclient.rb', line 24

def base_url
  @base_url
end

#base_url_configObject

Returns the value of attribute base_url_config.



15
16
17
# File 'lib/pindo/client/bossclient.rb', line 15

def base_url_config
  @base_url_config
end

#boss_default_platformObject

Returns the value of attribute boss_default_platform.



16
17
18
# File 'lib/pindo/client/bossclient.rb', line 16

def boss_default_platform
  @boss_default_platform
end

#device_info_configObject

Returns the value of attribute device_info_config.



14
15
16
# File 'lib/pindo/client/bossclient.rb', line 14

def device_info_config
  @device_info_config
end

#is_devObject

Returns the value of attribute is_dev.



23
24
25
# File 'lib/pindo/client/bossclient.rb', line 23

def is_dev
  @is_dev
end

#requests_configObject

Returns the value of attribute requests_config.



18
19
20
# File 'lib/pindo/client/bossclient.rb', line 18

def requests_config
  @requests_config
end

#salts_configObject

Returns the value of attribute salts_config.



17
18
19
# File 'lib/pindo/client/bossclient.rb', line 17

def salts_config
  @salts_config
end

Class Method Details

.is_in_review_status_with_confirm_key(confirm_key: nil) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/pindo/client/bossclient.rb', line 65

def self.is_in_review_status_with_confirm_key(confirm_key:nil)

    if confirm_key.nil?
        raise Informative,  "confirm_key 是空,判断in review 状态失败!"
    end
    is_in_review_status = false

    confirm_array =  confirm_key.bytes || []
    confirm_value = 0
    confirm_array.each do |char_value|
      confirm_value += char_value
    end

    if confirm_value % 2 == 0
      is_in_review_status = false
    else
      is_in_review_status = true
    end

    return is_in_review_status

end

Instance Method Details

#do_request(boss_url: nil, params: nil) ⇒ Object



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/pindo/client/bossclient.rb', line 174

def do_request(boss_url:nil, params:nil)

    # puts JSON.pretty_generate(params)

    con = Faraday.new 
    res = con.get do |req|
        req.url boss_url
        req.headers['Content-Type'] = 'application/json'
        req.params = params
    end

    
    res_json = JSON.parse(res.body)
    data_json = nil
    if !res_json.nil? && !res_json["result"].nil?
      data_json = req_data_aes_decrypt(encrypt_string:res_json["result"])
    end

    return data_json

end

#get_default_apps_flyer_infoObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/pindo/client/bossclient.rb', line 97

def get_default_apps_flyer_info( )

    apps_flyer_info = {
        conversion_info:{
          is_first_launch:true,
          af_status:"Organic",
          af_message:"organic install",
          install_time:"nil"
        },
        apps_flyer_uid:nil
      }


    apps_flyer_info[:apps_flyer_uid] = @boss_config_json["apps_flyer_uid"] || "1686395365581-9548642"
    time_install = Time.now - 5 * 60
    time_install_str = time_install.strftime("%Y-%m-%d %H:%M:%S")
    apps_flyer_info[:conversion_info][:install_time] = time_install_str
    return apps_flyer_info
end

#get_default_device_infoObject



89
90
91
92
93
94
95
# File 'lib/pindo/client/bossclient.rb', line 89

def get_default_device_info( )

    device_info = DeviceInfo.new
    device_info.reset_with_config(device_config:@device_info_config)

    return device_info
end

#refresh_setting(app_info_dict: nil) ⇒ Object

app_info_dict = {

login_device_id: "294D0303-6692-47F2-8EF2-DF6A1847D1CD",
app_version:"3.2023.07",
bundle_id:"com.heroneverdie101.fancyapptest",
api_version:"1.0",
platform:"iOS_Funny_Release",
apps_flyer_info:{
  conversion_info:{
    is_first_launch:true,
    af_status:"Organic",
    af_message:"organic install",
    install_time:"2023-06-12 08:54:52"
  }, 
  apps_flyer_uid:  "1686395365581-9548642"
},
device_info:@device_info

}



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/pindo/client/bossclient.rb', line 135

def refresh_setting(app_info_dict:nil)
    # puts app_info_dict
  
    qerry_dict = {
      app_info:[
        app_info_dict.to_json
      ]
    }

    data_dict = {
        path: "",
        query:"",
        method:"GET",
        response_key:"result",
        response_data:{
        status:"success"
      }
    }

    req_config_item = @requests_config.find { |item| item["name"].eql?("get_settings_refresh")}
    data_dict[:path] = req_config_item["path"]
    data_dict[:query] = URI.encode_www_form(qerry_dict)

    encrypt_string = req_data_aes_encrypt(data_dict:data_dict)

    setting_params = {
      app_version: app_info_dict[:app_version],
      content: encrypt_string
    }

   data_json = do_request(boss_url:@base_url, params:setting_params)
    

    
    # puts JSON.pretty_generate(data_json)
    return data_json

end

#req_data_aes_decrypt(encrypt_string: nil) ⇒ Object



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/pindo/client/bossclient.rb', line 211

def req_data_aes_decrypt(encrypt_string:nil)


      response_data = encrypt_string
      response_data = response_data[16..-1]
      response_data = response_data[0..-16]
      result_aes_key_name = response_data.slice(response_data.length-1)
      result_aes_key_value = @salts_config[result_aes_key_name]
      origin_result_data = response_data[0..-2]

      data =  AESHelper::aes_128_ecb_decrypt(result_aes_key_value, origin_result_data)
      data_json = JSON.parse(data)
    
      return data_json
end

#req_data_aes_encrypt(data_dict: nil) ⇒ Object



197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/pindo/client/bossclient.rb', line 197

def req_data_aes_encrypt(data_dict:nil)

    aes_origin_data = data_dict.to_json
    req_aes_key_nane = @salts_config.keys.sample
    req_aes_key_value = @salts_config[req_aes_key_nane]
    content = AESHelper::aes_128_ecb_encrypt(req_aes_key_value, aes_origin_data)

    front_rand_str = (0...16).map{65.+(rand(26)).chr}.join
    back_rand_str = (0...15).map{65.+(rand(26)).chr}.join

    encrypt_string = front_rand_str + content + req_aes_key_nane + back_rand_str
    return encrypt_string
end