itunes-client 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/itunes/track.rb +20 -0
- data/lib/itunes/version.rb +1 -1
- data/scripts/track/updater.tmpl.scpt +4 -0
- data/spec/itunes/track_spec.rb +42 -2
- data/spec/itunes/util/executor_spec.rb +23 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17d1042e67a74536457080f89d209446fae44ac2
|
4
|
+
data.tar.gz: 751e7a6dd53f7caeca542d1d3fd09f8b283a3669
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01743c0db4c302fd96ace4fa2d844414e30884392262b6f9db525f05bf2344f905944ea39f6e18b9718ad44c332e73d046f3e784e1a267832f496a34aa3bf8ee
|
7
|
+
data.tar.gz: 8e6795ebb879c1cae8e7c8678bde1c26f9255cda3677d0bb4ccf7f0d1d5fc9ab9904f0c697ccb713f9fa19602b9f268585e1cc32f87db49c2a65a129f7f8de19
|
data/lib/itunes/track.rb
CHANGED
@@ -58,6 +58,17 @@ module Itunes
|
|
58
58
|
self
|
59
59
|
end
|
60
60
|
|
61
|
+
def update_attributes(attributes)
|
62
|
+
raise ArgumentError.new('Invalid argument is given') unless attributes.is_a?(Hash)
|
63
|
+
|
64
|
+
records = update_attribute_records(attributes)
|
65
|
+
update_targets = { persistent_id: self.persistent_id, update_records: records }
|
66
|
+
script_name = generate_script_from_template('track/updater.tmpl.scpt', update_targets)
|
67
|
+
execute_template_based_script(script_name)
|
68
|
+
attributes.each { |key, val| send("#{key}=", val) }
|
69
|
+
self
|
70
|
+
end
|
71
|
+
|
61
72
|
def assign_attributes_by(track_attributes)
|
62
73
|
ATTRIBUTES.each { |attr| send("#{attr}=", track_attributes[attr.to_s]) }
|
63
74
|
end
|
@@ -94,5 +105,14 @@ module Itunes
|
|
94
105
|
Application.instance
|
95
106
|
end
|
96
107
|
|
108
|
+
def update_attribute_records(args)
|
109
|
+
records = []
|
110
|
+
args.each do |key, val|
|
111
|
+
if ATTRIBUTES.include?(key)
|
112
|
+
records << "set #{key.to_s.gsub('_', ' ')} of specified_track to \"#{val}\""
|
113
|
+
end
|
114
|
+
end
|
115
|
+
records.join("\n")
|
116
|
+
end
|
97
117
|
end
|
98
118
|
end
|
data/lib/itunes/version.rb
CHANGED
data/spec/itunes/track_spec.rb
CHANGED
@@ -5,9 +5,13 @@ require 'itunes-client'
|
|
5
5
|
include Itunes
|
6
6
|
|
7
7
|
describe Track do
|
8
|
-
let(:track)
|
8
|
+
let(:track) do
|
9
|
+
Track.new(persistent_id: base_persistent_id, name: base_name, album: base_album)
|
10
|
+
end
|
9
11
|
let(:app) { Application.instance }
|
10
12
|
let(:base_persistent_id) { 'foo' }
|
13
|
+
let(:base_name) { 'base name' }
|
14
|
+
let(:base_album) { 'base album' }
|
11
15
|
|
12
16
|
describe '#initialize' do
|
13
17
|
subject(:init) { Track.new(args) }
|
@@ -84,6 +88,42 @@ describe Track do
|
|
84
88
|
end
|
85
89
|
end
|
86
90
|
|
91
|
+
describe '#update_attributes' do
|
92
|
+
subject(:update) { track.update_attributes(attributes) }
|
93
|
+
|
94
|
+
context 'when nil argument is given' do
|
95
|
+
let(:attributes) { nil }
|
96
|
+
it 'raises an ArgumentError' do
|
97
|
+
expect { update }.to raise_error(ArgumentError)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'when hash argument is given' do
|
102
|
+
let(:new_scpt) { 'new.scpt' }
|
103
|
+
let(:new_name) { 'new name' }
|
104
|
+
let(:new_album) { 'new album' }
|
105
|
+
let(:attributes) { { name: new_name, album: new_album } }
|
106
|
+
|
107
|
+
before do
|
108
|
+
track.stub(:generate_script_from_template).
|
109
|
+
with('track/updater.tmpl.scpt', persistent_id: track.persistent_id, update_records: "set name of specified_track to \"#{new_name}\"\nset album of specified_track to \"#{new_album}\"").
|
110
|
+
and_return(new_scpt)
|
111
|
+
track.stub(:execute_template_based_script).
|
112
|
+
with(new_scpt)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'updates given attributes' do
|
116
|
+
update
|
117
|
+
expect(track.name).to be_eql(new_name)
|
118
|
+
expect(track.album).to be_eql(new_album)
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'does not update persistent_id' do
|
122
|
+
expect { update }.not_to change { track.persistent_id }.from(base_persistent_id)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
87
127
|
describe '.find_by' do
|
88
128
|
subject(:find) { Track.find_by(arg) }
|
89
129
|
let(:finder_scpt) { 'track/finder.tmpl.scpt' }
|
@@ -102,7 +142,7 @@ describe Track do
|
|
102
142
|
let(:name) { 'Hey Jude' }
|
103
143
|
|
104
144
|
before do
|
105
|
-
Track.stub(:
|
145
|
+
Track.stub(:generate_script_from_template).
|
106
146
|
and_return(new_scpt)
|
107
147
|
|
108
148
|
Track.stub(:execute_template_based_script).
|
@@ -42,7 +42,29 @@ describe Itunes::Util::Executor do
|
|
42
42
|
File.exist?(script_full_path)
|
43
43
|
}.from(true).to(false)
|
44
44
|
end
|
45
|
-
|
46
45
|
end
|
47
46
|
|
47
|
+
describe '#generate_script_from_template' do
|
48
|
+
subject(:generate_script_from_template) { klass.generate_script_from_template(path, args) }
|
49
|
+
|
50
|
+
let(:path) { 'spec.scpt' }
|
51
|
+
let(:args) { { target: 'bar' } }
|
52
|
+
|
53
|
+
before do
|
54
|
+
script_path = "#{klass.script_base_dir}/#{path}"
|
55
|
+
open(script_path, 'w') { |f| f.write('#{target}') }
|
56
|
+
end
|
57
|
+
|
58
|
+
after do
|
59
|
+
FileUtils.rm("#{klass.script_base_dir}/#{path}")
|
60
|
+
end
|
61
|
+
it 'returns script path which replaces template key' do
|
62
|
+
script_path = generate_script_from_template
|
63
|
+
body = ''
|
64
|
+
open("#{klass.script_tmp_dir}/#{script_path}", 'r') do |f|
|
65
|
+
f.each { |line| body << line }
|
66
|
+
end
|
67
|
+
expect(body).to eq('bar')
|
68
|
+
end
|
69
|
+
end
|
48
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: itunes-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ryo katsuma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -181,6 +181,7 @@ files:
|
|
181
181
|
- scripts/track/delete.scpt
|
182
182
|
- scripts/track/finder.tmpl.scpt
|
183
183
|
- scripts/track/play.scpt
|
184
|
+
- scripts/track/updater.tmpl.scpt
|
184
185
|
- spec/itunes/application_spec.rb
|
185
186
|
- spec/itunes/track_spec.rb
|
186
187
|
- spec/itunes/util/executor_spec.rb
|