Class: Pindo::PgyerClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePgyerClient

Returns a new instance of PgyerClient.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pindo/client/pgyerclient.rb', line 19

def initialize()

    begin

      @pgyer_token_file = File.join(File::expand_path(Pindoconfig.instance.pindo_dir), ".pgyer_token")
      config_file = File.join(File::expand_path(Pindoconfig.instance.pindo_common_configdir), "pgyer_client_config.json")
      config_json = JSON.parse(File.read(config_file))

      @use_local_wechat_url = config_json["use_local_wechat_url"]
      @baseurl = config_json["pgyerapps_base_url"]
      @request_config = config_json["pgyerapps_req_config"]
      @pgyer_aes_key = config_json["pgyerapps_aes_key"]

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

end

Instance Attribute Details

#baseurlObject

Returns the value of attribute baseurl.



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

def baseurl
  @baseurl
end

#request_configObject

Returns the value of attribute request_config.



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

def request_config
  @request_config
end

#tokenObject

Returns the value of attribute token.



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

def token
  @token
end

#use_local_wechat_urlObject

Returns the value of attribute use_local_wechat_url.



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

def use_local_wechat_url
  @use_local_wechat_url
end

Instance Method Details

#do_login(force_login: false) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/pindo/client/pgyerclient.rb', line 43

def (force_login:false)



     = false
    @token = load_token()
    if !@token.nil? && !@token["token"].nil? && !
         = true

        # puts "用户#{@token["username"]}登录pgyer成功!!!"
        # puts

    else
        username = nil
        if !@token.nil? && !@token["username"].nil?
            username = @token["username"]
            checksum_password = nil
            if !@token["password"].nil?
              checksum_password = @token["password"]
            end
        end
        token = (username:username, checksum_password:checksum_password)
        if !token.nil? && !token["token"].nil?
            @token = token
             = true
        end
    end

    return 
end

#do_login_req(username: nil, checksum_password: nil) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/pindo/client/pgyerclient.rb', line 74

def (username:nil, checksum_password:nil)


     = username
    if .nil? || .empty?
         = ask('请输入pgger网站的usernmae:') || nil
    end

    checksum_pass = checksum_password
    if checksum_pass.nil? || checksum_pass.empty?
         = ask('请输入pgger网站的密码:') || nil
        checksum_pass = Digest::MD5.hexdigest()
    end

  if !.nil? && !.empty? && !checksum_pass.nil? && !checksum_pass.empty?

  else
      raise Informative, "请输入正确的用户名和密码!"
  end


  Funlog.instance.fancyinfo_start("正在登录pgyer...")


  result_data = do_send_code(username:)


    boss_url = @baseurl + @request_config["do_login"]
    body_params = {
        username:,
        phoneCode:result_data["msg"],
        password:checksum_pass
    }

    # puts JSON.pretty_generate(body_params)

     = nil

    begin

  con = HttpClient.create_instance_with_proxy
  res = con.post do |req|
      req.url boss_url
      req.headers['Content-Type'] = 'application/json'
      req.body = body_params.to_json
  end

  if !res.body.nil?

       = JSON.parse(res.body)
  end

    rescue => error
        Funlog.instance.fancyinfo_error("pgyer登录失败!")
        puts "登录失败,请重试!!!"
    end



    # puts JSON.pretty_generate(login_response_data)

    if !.nil? && !["code"].nil? && ["code"].to_s.eql?("200")

        token = {}
        token= ["data"]
        token["password"] = checksum_pass
        # puts JSON.pretty_generate(token)
        store_token(token:token)

        Funlog.instance.fancyinfo_success("用户:#{@token["username"]}登录pgyer成功!")

    else
        if File.exist?(@pgyer_token_file)
          FileUtils.rm_rf(@pgyer_token_file)
        end
        Funlog.instance.fancyinfo_error("pgyer登录失败!")
    end

    return token

end

#do_send_code(username: nil) ⇒ Object



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/pindo/client/pgyerclient.rb', line 203

def do_send_code(username:nil)


    boss_url = @baseurl + @request_config["do_send_code"]

    body_params = {
        username:username
    }
    # puts JSON.pretty_generate(body_params)

    con = HttpClient.create_instance_with_proxy
    res = con.post do |req|
        req.url boss_url
        req.headers['Content-Type'] = 'application/json'
        req.body = body_params.to_json
    end

    result_date = nil
    if !res.body.nil?
        result_date = JSON.parse(res.body)
    end

    # puts JSON.pretty_generate(result_date)

    if !result_date.nil? && !result_date["code"].nil? && result_date["code"].to_s.eql?("200")


        res = con.post do |req|
            req.url boss_url
            req.headers['Content-Type'] = 'application/json'
            req.body = body_params.to_json
        end

        if !res.body.nil?
            result_date = JSON.parse(res.body)
        end

    end


    # puts JSON.pretty_generate(result_date)

    return  result_date

end

#get_app_list_req(params: nil) ⇒ Object



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/pindo/client/pgyerclient.rb', line 251

def get_app_list_req(params:nil)


    boss_url = @baseurl + @request_config["get_app_list"]

    # puts boss_url
    get_params = {
        orderByColumn:"app_name",
        sort:"ASC",
        pageNo:1,
        pageSize:1000,
    }

    params.each { |key,value| get_params[key] = value }


    con = HttpClient.create_instance_with_proxy
    res = con.get do |req|
        req.url boss_url
        req.headers['Content-Type'] = 'application/json'
        req.headers['token'] = @token["token"]
        req.params = get_params
    end

    result_date = nil
    if !res.body.nil?
        result_date = JSON.parse(res.body)

        if !result_date["code"].nil? && result_date["code"].to_s.eql?("401")
            (force_login:true)
        end
    end


    # puts JSON.pretty_generate(result_date)

    return  result_date

end

#get_app_version_list_req(appId: nil, params: nil) ⇒ Object



371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
# File 'lib/pindo/client/pgyerclient.rb', line 371

def get_app_version_list_req(appId:nil, params:nil)

    params = {} if params.nil?
    boss_url = @baseurl + @request_config["get_app_version_list"]

    get_params = {
        appId:appId,
        pageNo:1,
        pageSize:20,
    }

    params.each { |key,value| get_params[key] = value }


    con = HttpClient.create_instance_with_proxy
    res = con.get do |req|
        req.url boss_url
        req.headers['Content-Type'] = 'application/json'
        req.headers['token'] = @token["token"]
        req.params = get_params
    end

    result_date = nil
    if !res.body.nil?
        result_date = JSON.parse(res.body)
    end


    # puts JSON.pretty_generate(result_date)

    return  result_date

end

#get_cert_listObject



441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
# File 'lib/pindo/client/pgyerclient.rb', line 441

def get_cert_list( )

    params = {} if params.nil?
    boss_url = @baseurl + @request_config["get_cert_list"]

    con = HttpClient.create_instance_with_proxy
    res = con.get do |req|
        req.url boss_url
        req.headers['Content-Type'] = 'application/json'
        req.headers['token'] = @token["token"]
    end

    result_date = nil
    if !res.body.nil?
        result_date = JSON.parse(res.body)
    end


    # puts JSON.pretty_generate(result_date)

    return  result_date

end

#get_faraday_instanceObject



38
39
40
# File 'lib/pindo/client/pgyerclient.rb', line 38

def get_faraday_instance

end

#load_tokenObject



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/pindo/client/pgyerclient.rb', line 156

def load_token()

    @token = nil
    Funlog.instance.fancyinfo_success("正在读取pgyer token...")
    if File.exist?(@pgyer_token_file)
        begin
          data = File.read(@pgyer_token_file)

          data_string = AESHelper::aes_128_ecb_decrypt(@pgyer_aes_key, data)
          temp_token = data_string
          temp_token = JSON.parse(data_string)
          if !temp_token.nil? && !temp_token["token"].nil? && !temp_token["username"].nil?
              @token = temp_token
              Funlog.instance.fancyinfo_success("读取pgyer token成功!")
          end
        rescue => error
            puts error
            # puts "加载pgyer token 失败!!! "
            if File.exist?(@pgyer_token_file)
              FileUtils.rm_rf(@pgyer_token_file)
            end
            Funlog.instance.fancyinfo_error("pgyer token文件不存在!")
            @token  = nil
        end
    else
        Funlog.instance.fancyinfo_error("pgyer token文件不存在!")
    end

    return @token
end

#post_app_update_binary(appId: nil, params: nil) ⇒ Object

def post_app_update_binary(appId:nil, key_id:nil, description:nil)



329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/pindo/client/pgyerclient.rb', line 329

def post_app_update_binary(appId:nil, params:nil)


    boss_url = @baseurl + @request_config["upload_app_binary"]

    # puts boss_url
    body_params = {
        appId:appId,
        description:"",
        s3Url:"",
        attachFileUrls:[],
    }

    # puts body_params.to_json
    #

    params.each { |key,value| body_params[key] = value }
    # puts body_params.to_json

    # puts JSON.pretty_generate(body_params)
    # puts "111"
    con = HttpClient.create_instance_with_proxy
    res = con.post do |req|
        req.url boss_url
        req.headers['Content-Type'] = 'application/json'
        req.headers['token'] = @token["token"]
        req.body = body_params.to_json
    end


    result_date = nil
    if !res.body.nil?
        result_date = JSON.parse(res.body)
    end


    # puts JSON.pretty_generate(result_date)

    return result_date

end

#post_resign(appVersionId: nil, certId: nil) ⇒ Object



465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
# File 'lib/pindo/client/pgyerclient.rb', line 465

def post_resign(appVersionId:nil, certId:nil)

    boss_url = @baseurl + @request_config["post_resign"]

    body_params = {
          appVersionId:appVersionId,
          certId:certId
      }


    con = HttpClient.create_instance_with_proxy

    res = con.post do |req|
        req.url boss_url
        req.headers['Content-Type'] = 'application/json'
        req.headers['token'] = @token["token"]
        req.body = body_params.to_json
    end


    result_date = nil
    if !res.body.nil?
        result_date = JSON.parse(res.body)
    end


    # puts JSON.pretty_generate(result_date)

    return result_date

end

#post_update_upload_comment(appId: nil, id: nil, comment: nil) ⇒ Object



406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
# File 'lib/pindo/client/pgyerclient.rb', line 406

def post_update_upload_comment(appId:nil, id:nil, comment:nil)


  boss_url = @baseurl + @request_config["update_upload_comment"]

    # puts boss_url
  body_params = {
        appId:appId,
        id:id,
        description:comment || ""
    }


    con = HttpClient.create_instance_with_proxy

    res = con.post do |req|
        req.url boss_url
        req.headers['Content-Type'] = 'application/json'
        req.headers['token'] = @token["token"]
        req.body = body_params.to_json
    end


    result_date = nil
    if !res.body.nil?
        result_date = JSON.parse(res.body)
    end


    # puts JSON.pretty_generate(result_date)

    return result_date

end

#store_token(token: nil) ⇒ Object



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/pindo/client/pgyerclient.rb', line 187

def store_token(token:nil)

    begin
      @token = token

      data_string = AESHelper::aes_128_ecb_encrypt(@pgyer_aes_key, @token.to_json)
      File.open(@pgyer_token_file, "w") do |f|
        f.write(data_string)
      end
      Funlog.instance.fancyinfo_success("token 存储成功!")
      # puts "store pgyer token---- sucess !!!"
    rescue => error
      Funlog.instance.fancyinfo_error("token存储失败!")
    end
end

#update_app_info_req(params: nil) ⇒ Object



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/pindo/client/pgyerclient.rb', line 291

def update_app_info_req(params:nil)

    boss_url = @baseurl + @request_config["update_app_info"]
    # puts boss_url
    body_params = {

    }

    if params.nil?
        return
    end
    params.each { |key,value| body_params[key] = value }


    con = HttpClient.create_instance_with_proxy
    res = con.post do |req|
        req.url boss_url
        req.headers['Content-Type'] = 'application/json'
        req.headers['token'] = @token["token"]
        req.body = body_params.to_json
    end
    # puts JSON.pretty_generate(body_params)

    result_date = nil
    if !res.body.nil?
        result_date = JSON.parse(res.body)
    end


    # puts JSON.pretty_generate(result_date)

    return  result_date

end