ZAPKDownloader 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c77a8de29ebebfad2697e8483a362d110998dcf1eb0ee6375f08227e46b926be
4
- data.tar.gz: '09fb9d4e6e1def656495d9f8c6789c0f7579755ff21ca4685747a28a3f254944'
3
+ metadata.gz: bc7dd26c9273d8ba0f1a9edfa617a0f0db92181f11041b3fcc64256122298823
4
+ data.tar.gz: 7a0834a7eff12aca7f10c934aec323860fb95e1efed4698c3a1d8fe8939d0683
5
5
  SHA512:
6
- metadata.gz: 60eff6c13ece4fda94fa3b4eb7808187f357adb1412a9db40c241eaf92a537918a9b67f4065de76c744cdacbf7fb0d05e70edada27a5228bc33f5820434b7659
7
- data.tar.gz: ec4a2a9f52e20eac88123ab6eb2428ff37730535ce94de26603d199cae7dba68510037782ff68ea5455407b55012e2351ae0383fb2e90689fda6208632c71517
6
+ metadata.gz: eccadc1666d805678db86ba53bb2d274909b01f6ea22894bb49ac207b691f1de36d944a584aa23b39bf3671a7c19374746eb2606e2e3764dc290a573dd3543b6
7
+ data.tar.gz: 502d162ec54a6c06695fd2478e42200d4ba580e464270e16782cbb4af10fc750bb00c1d4f9f03a1d7f64df0c4fdef8b11d531e6fc5bf769ce7d1b131aecc971c
data/bin/ZAPKDownloader CHANGED
@@ -4,14 +4,12 @@
4
4
  $lib = File.expand_path('../lib', File.dirname(__FILE__))
5
5
  $LOAD_PATH.unshift($lib)
6
6
 
7
- require "GoogleAPI"
7
+ require "ZAPKDownloader"
8
8
  require "optparse"
9
- require "yaml"
10
- require "fileutils"
11
9
 
12
10
  class Main
13
11
 
14
- attr_accessor :googleAPI
12
+ attr_accessor :downloader
15
13
 
16
14
  def initialize
17
15
 
@@ -61,34 +59,10 @@ class Main
61
59
  return
62
60
  end
63
61
 
64
- @googleAPI = GoogleAPI.new(inputServiceAccount, ["https://www.googleapis.com/auth/androidpublisher"])
65
- apks = googleAPI.request("https://androidpublisher.googleapis.com/androidpublisher/v3/applications/#{inputPackageName}/generatedApks/#{inputVersionCode}")
66
-
67
- downloadId = apks["generatedApks"][0]["generatedUniversalApk"]["downloadId"]
68
- downloadURL = "https://androidpublisher.googleapis.com/androidpublisher/v3/applications/#{inputPackageName}/generatedApks/#{inputPackageName}/downloads/#{downloadId}:download?alt=media"
62
+ @downloader = ZAPKDownloader.new(inputServiceAccount, ["https://www.googleapis.com/auth/androidpublisher"])
69
63
  fileFullPath = "#{inputOutputFilePath}/#{inputOutputFileName}"
70
64
 
71
- puts "PackageName:#{inputPackageName}, versionCode:#{inputVersionCode}"
72
- puts "Download from #{downloadURL} to #{fileFullPath}..."
73
- puts "Downloading..."
74
-
75
- uri = URI(downloadURL)
76
- https = Net::HTTP.new(uri.host, uri.port)
77
- https.use_ssl = true
78
-
79
- request = Net::HTTP::Get.new(uri)
80
- request['Authorization'] = "Bearer #{googleAPI.token}";
81
-
82
- response = https.request(request).read_body
83
-
84
-
85
- File.delete(fileFullPath) if File.exist?(fileFullPath)
86
-
87
- open(fileFullPath, "wb") { |file|
88
- file.write(response)
89
- }
90
-
91
- puts "Downloaded Success!"
65
+ downloader.download_generated_universal_apk(inputPackageName, inputVersionCode, fileFullPath)
92
66
  end
93
67
  end
94
68
 
@@ -4,7 +4,7 @@ require "jwt"
4
4
  require "time"
5
5
  require "net/http"
6
6
 
7
- class GoogleAPI
7
+ class ZAPKDownloader
8
8
 
9
9
  attr_accessor :keyContent, :keyID, :tokenURI, :clientEmail, :scopes, :token
10
10
 
@@ -21,9 +21,48 @@ class GoogleAPI
21
21
 
22
22
  @token = generateJWT()
23
23
 
24
- puts "[GoogleAPI] Init Success."
24
+ puts "[ZAPKDownloader] Init Success."
25
25
  end
26
26
 
27
+ def download_generated_universal_apk(packageName, versionCode, filePath)
28
+ apks = list_generated_apks(packageName, versionCode)
29
+ downloadId = apks["generatedApks"][0]["generatedUniversalApk"]["downloadId"]
30
+
31
+ puts "PackageName:#{packageName}, versionCode:#{versionCode}"
32
+
33
+ download_generated_apk(packageName, versionCode, downloadId, filePath)
34
+ end
35
+
36
+ private
37
+ def list_generated_apks(packageName, versionCode)
38
+ return request("https://androidpublisher.googleapis.com/androidpublisher/v3/applications/#{packageName}/generatedApks/#{versionCode}")
39
+ end
40
+
41
+ private
42
+ def download_generated_apk(packageName, versionCode, downloadId, filePath)
43
+ downloadURL = "https://androidpublisher.googleapis.com/androidpublisher/v3/applications/#{packageName}/generatedApks/#{versionCode}/downloads/#{downloadId}:download?alt=media"
44
+
45
+ puts "Download from #{downloadURL} to #{filePath}..."
46
+ puts "Downloading..."
47
+
48
+ uri = URI(downloadURL)
49
+ https = Net::HTTP.new(uri.host, uri.port)
50
+ https.use_ssl = true
51
+
52
+ request = Net::HTTP::Get.new(uri)
53
+ request['Authorization'] = "Bearer #{token}";
54
+
55
+ response = https.request(request).read_body
56
+ File.delete(filePath) if File.exist?(filePath)
57
+
58
+ open(filePath, "wb") { |file|
59
+ file.write(response)
60
+ }
61
+
62
+ puts "Downloaded Success!"
63
+ end
64
+
65
+ private
27
66
  def request(url, method = "GET", data = nil, retryCount = 0)
28
67
  uri = URI(url)
29
68
  https = Net::HTTP.new(uri.host, uri.port)
@@ -46,7 +85,7 @@ class GoogleAPI
46
85
  if !result["error"].nil?
47
86
  # Quota exceeded for quota metric 'Write requests' and limit 'Write requests per minute per user
48
87
  if result["error"]["code"] == 429
49
- puts "[GoogleAPI] Reached Rate Limited, sleep 30 secs..."
88
+ puts "[ZAPKDownloader] Reached Rate Limited, sleep 30 secs..."
50
89
  sleep(30)
51
90
  return request(url, method, data, 0)
52
91
  else
@@ -55,7 +94,7 @@ class GoogleAPI
55
94
  else
56
95
  @token = generateJWT()
57
96
  message = "JWT Invalid, retry. (#{retryCount + 1})"
58
- puts "[GoogleAPI] #{message}"
97
+ puts "[ZAPKDownloader] #{message}"
59
98
  return request(url, method, data, retryCount + 1)
60
99
  end
61
100
  end
@@ -93,7 +132,7 @@ class GoogleAPI
93
132
  raise "Could not generate google api JWT, key id: #{keyID}, error message: #{response}"
94
133
  else
95
134
  message = "Could not generate google api JWT, retry. (#{retryCount + 1})"
96
- puts "[GoogleAPI] #{message}"
135
+ puts "[ZAPKDownloader] #{message}"
97
136
  return generateJWT(retryCount + 1)
98
137
  end
99
138
  else
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ZAPKDownloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ZhgChgLi
@@ -46,7 +46,7 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - bin/ZAPKDownloader
49
- - lib/GoogleAPI.rb
49
+ - lib/ZAPKDownloader.rb
50
50
  homepage: https://github.com/ZhgChgLi/ZAPKDownloader
51
51
  licenses:
52
52
  - MIT