play_time 0.0.2 → 0.0.3
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 +4 -4
- data/lib/play_time/client.rb +10 -6
- data/lib/play_time/configuration.rb +5 -3
- data/lib/play_time/runner.rb +2 -25
- data/lib/play_time/version.rb +1 -1
- data/spec/client_spec.rb +6 -5
- data/spec/configuration_spec.rb +10 -0
- data/spec/runner_spec.rb +4 -16
- data/spec/support/config/default.yml +4 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52263d955063ada0381b1f92eb4f3eb888e9b09a
|
4
|
+
data.tar.gz: a4a5c66750eeba46e127b1a16813fb3935873559
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 416e3bbdbde16698f213f275b444181ca7e5ccbb448bb6f51de1fe026d87acc436da08573ce16df454d001ea2a6bc3ca405e5f4af51f6110f704363cfe28aa73
|
7
|
+
data.tar.gz: c8a5867c0c328306ee31d97a5d2f555e82bc85946d4ba10c3d72e79ebe6046ef13c7e2a125748a49a982af22242a33affd816da19bad15854cd51678b677f736
|
data/lib/play_time/client.rb
CHANGED
@@ -24,29 +24,33 @@ module PlayTime
|
|
24
24
|
|
25
25
|
private
|
26
26
|
|
27
|
-
attr_reader :edit_id
|
27
|
+
attr_reader :edit_id, :version_code
|
28
28
|
|
29
29
|
def create_insert
|
30
|
-
@edit_id =
|
30
|
+
@edit_id = run!(api_method: service.edits.insert, parameters: parameters).data.id
|
31
31
|
end
|
32
32
|
|
33
33
|
def upload_apk
|
34
34
|
upload_params = parameters.merge(editId: edit_id, uploadType: 'media')
|
35
|
-
|
35
|
+
@version_code = run!(api_method: service.edits.apks.upload, parameters: upload_params, media: Apk.load).data.versionCode
|
36
36
|
end
|
37
37
|
|
38
38
|
def update_track(track)
|
39
39
|
update_params = parameters.merge(editId: edit_id, track: track)
|
40
|
-
|
40
|
+
run! api_method: service.edits.tracks.update, parameters: update_params, body_object: { versionCodes: [version_code] }
|
41
41
|
end
|
42
42
|
|
43
43
|
def save
|
44
44
|
commit_params = parameters.merge(editId: edit_id)
|
45
|
-
|
45
|
+
run! api_method: service.edits.commit, parameters: commit_params
|
46
|
+
end
|
47
|
+
|
48
|
+
def run!(options = {})
|
49
|
+
Runner.run! client, options
|
46
50
|
end
|
47
51
|
|
48
52
|
def parameters
|
49
|
-
{
|
53
|
+
{packageName: PlayTime.configuration.package_name}
|
50
54
|
end
|
51
55
|
|
52
56
|
def client
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module PlayTime
|
2
2
|
class Configuration
|
3
|
+
class MissingOption < StandardError; end
|
4
|
+
|
3
5
|
DEFAULT_CONFIG = 'config/play_time.yml'.freeze
|
4
6
|
OPTIONS = %w(
|
5
7
|
apk_path
|
@@ -17,9 +19,9 @@ module PlayTime
|
|
17
19
|
|
18
20
|
OPTIONS.each do |config_name|
|
19
21
|
eval <<-RUBY
|
20
|
-
def #{config_name}
|
21
|
-
config["#{config_name}"] #
|
22
|
-
end
|
22
|
+
def #{config_name}
|
23
|
+
config["#{config_name}"] || raise(MissingOption, "Missing #{config_name} in \#{PlayTime.config_path}")
|
24
|
+
end
|
23
25
|
RUBY
|
24
26
|
end
|
25
27
|
|
data/lib/play_time/runner.rb
CHANGED
@@ -1,40 +1,17 @@
|
|
1
1
|
module PlayTime
|
2
2
|
class Runner
|
3
|
-
class IOError < StandardError; end
|
4
3
|
class ResponseError < StandardError; end
|
5
4
|
|
6
5
|
class << self
|
7
6
|
def run!(client, options = {})
|
8
7
|
response = client.execute(options)
|
9
8
|
|
10
|
-
if error
|
11
|
-
raise
|
9
|
+
if response.data && (error = response.data['error'])
|
10
|
+
raise ResponseError, error
|
12
11
|
else
|
13
12
|
response
|
14
13
|
end
|
15
14
|
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def has_data?(response)
|
20
|
-
response && response.data
|
21
|
-
end
|
22
|
-
|
23
|
-
def error?(response)
|
24
|
-
!has_data?(response) || response.data['error']
|
25
|
-
end
|
26
|
-
|
27
|
-
def error_message(response)
|
28
|
-
response.data['error'] if has_data?(response)
|
29
|
-
end
|
30
|
-
|
31
|
-
def error_for(response)
|
32
|
-
if error_message = error_message(response)
|
33
|
-
ResponseError.new(error_message)
|
34
|
-
else
|
35
|
-
IOError
|
36
|
-
end
|
37
|
-
end
|
38
15
|
end
|
39
16
|
end
|
40
17
|
end
|
data/lib/play_time/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -67,7 +67,7 @@ describe PlayTime::Client do
|
|
67
67
|
describe '#commit' do
|
68
68
|
let(:track) { 'alpha' }
|
69
69
|
let(:service) { double(Google::APIClient::API) }
|
70
|
-
let(:response) { double(:response, data: double(:data, id: 'id')) }
|
70
|
+
let(:response) { double(:response, data: double(:data, id: 'id', versionCode: 'version code')) }
|
71
71
|
let(:apk_file) { instance_double(Google::APIClient::UploadIO) }
|
72
72
|
|
73
73
|
subject { PlayTime::Client.new.commit(track) }
|
@@ -94,7 +94,7 @@ describe PlayTime::Client do
|
|
94
94
|
subject
|
95
95
|
|
96
96
|
expect(PlayTime::Runner).to have_received(:run!).with(
|
97
|
-
api_client, api_method: 'insert', parameters: {
|
97
|
+
api_client, api_method: 'insert', parameters: { packageName: 'com.package.name' })
|
98
98
|
end
|
99
99
|
|
100
100
|
it 'uploads an apk file' do
|
@@ -103,7 +103,7 @@ describe PlayTime::Client do
|
|
103
103
|
expect(PlayTime::Runner).to have_received(:run!).with(
|
104
104
|
api_client,
|
105
105
|
api_method: 'upload',
|
106
|
-
parameters: {
|
106
|
+
parameters: { packageName: 'com.package.name', editId: 'id', uploadType: 'media' },
|
107
107
|
media: apk_file
|
108
108
|
)
|
109
109
|
end
|
@@ -114,7 +114,8 @@ describe PlayTime::Client do
|
|
114
114
|
expect(PlayTime::Runner).to have_received(:run!).with(
|
115
115
|
api_client,
|
116
116
|
api_method: 'track update',
|
117
|
-
parameters: {
|
117
|
+
parameters: { packageName: 'com.package.name', editId: 'id', track: track },
|
118
|
+
body_object: { versionCodes: ['version code'] }
|
118
119
|
)
|
119
120
|
end
|
120
121
|
|
@@ -124,7 +125,7 @@ describe PlayTime::Client do
|
|
124
125
|
expect(PlayTime::Runner).to have_received(:run!).with(
|
125
126
|
api_client,
|
126
127
|
api_method: 'commit',
|
127
|
-
parameters: {
|
128
|
+
parameters: { packageName: 'com.package.name', editId: 'id' }
|
128
129
|
)
|
129
130
|
end
|
130
131
|
end
|
data/spec/configuration_spec.rb
CHANGED
@@ -7,6 +7,16 @@ describe PlayTime::Configuration do
|
|
7
7
|
it "fetchings the option from the config" do
|
8
8
|
expect(subject).to eq option
|
9
9
|
end
|
10
|
+
|
11
|
+
context 'missing options' do
|
12
|
+
let(:configuration) { PlayTime::Configuration.new({'foo' => 'bar'}) }
|
13
|
+
|
14
|
+
it "raises an exception for each missing param" do
|
15
|
+
expect {
|
16
|
+
subject
|
17
|
+
}.to raise_error PlayTime::Configuration::MissingOption, "Missing #{option} in #{PlayTime.config_path}"
|
18
|
+
end
|
19
|
+
end
|
10
20
|
end
|
11
21
|
|
12
22
|
PlayTime::Configuration::OPTIONS.each do |option|
|
data/spec/runner_spec.rb
CHANGED
@@ -16,29 +16,17 @@ describe PlayTime::Runner do
|
|
16
16
|
it 'returns a response' do
|
17
17
|
expect(subject).to eq response
|
18
18
|
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'when failure' do
|
22
|
-
context 'when no response' do
|
23
|
-
let(:response) { nil }
|
24
|
-
|
25
|
-
it 'raises an error' do
|
26
|
-
expect {
|
27
|
-
subject
|
28
|
-
}.to raise_error PlayTime::Runner::IOError
|
29
|
-
end
|
30
|
-
end
|
31
19
|
|
32
20
|
context 'when data is nil' do
|
33
21
|
let(:response) { double(:response, data: nil) }
|
34
22
|
|
35
|
-
it '
|
36
|
-
expect
|
37
|
-
subject
|
38
|
-
}.to raise_error PlayTime::Runner::IOError
|
23
|
+
it 'returns the response' do
|
24
|
+
expect(subject).to eq response
|
39
25
|
end
|
40
26
|
end
|
27
|
+
end
|
41
28
|
|
29
|
+
context 'when failure' do
|
42
30
|
context 'when data has an error' do
|
43
31
|
let(:response) { double(:response, data: {'error' => 'Something went wrong'}) }
|
44
32
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
package_name: com.example.app
|
2
2
|
secret_path: /path/to/secret/secret.p12
|
3
|
+
secret_passphrase: notasecret
|
3
4
|
apk_path: /path/to/alpha/app.apk
|
4
|
-
client_name:
|
5
|
-
client_version:
|
5
|
+
client_name: Google API Client Name
|
6
|
+
client_version: 1.0.0
|
7
|
+
issuer: issuer@developer.gserviceaccount.com
|