itunes-client 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: acf0f6362da0cee6e1acd568af19372073f9ff1b
4
- data.tar.gz: 819befcd3e4f4df0c3937d77d053e30350a88d4e
3
+ metadata.gz: 5645b5129783ab41989f48719cc052f25a5f835b
4
+ data.tar.gz: 7253a509ac6e66791d49dc71dca6acad9a7f4dd3
5
5
  SHA512:
6
- metadata.gz: 71055a9bf65eef0718b2656e29ea2661f0505909750bb12494d993407f0cccfb4eaf22d0e5a96c4d2306d8c96cc09d2adf3224c75ef5011fb199b25d14636434
7
- data.tar.gz: 55ca841cd771536984bb3750b9d1c1a57906540be6ff0842ebe49b89823f9d9dfa5dae479886a7c6de68a06042816040540413b8b0913a4052fce0c7bc70666a
6
+ metadata.gz: 9a57212b58a551bbc99ca4d70027ad5ffa308cbae0f121932c3e8e0e2b04a672fab0ed95f0a54762192b6d06df31301a2c4144cfee2fbcdfa067ed89695d463c
7
+ data.tar.gz: a89c43842d98e6f0a22d06348907c1ea9ae78be9c7579b6a3272489863c870d1d0f57da57ea60c8f211d9fde9b8e104c10a13b183b49cdd09cd58e6a6fa51054
data/README.md CHANGED
@@ -44,9 +44,11 @@ track = application.add(path_to_your_sound_file)
44
44
  # Convert by default encoder
45
45
  encoded_track = track.convert
46
46
 
47
- # Find a track
48
- track = Track.find_by(name: "Hello, Goodbye")
49
- # => #<Itunes::Track:0x007fdd38a1d430 @persistent_id="571B6412CDADBC93", @name="Hello, Goodbye", @album="1", @artist="The Beatles", @track_count="27", @track_number="19">
47
+ # Find all tracks
48
+ tracks = Track.find_by(name: "Hello, Goodbye")
49
+ # => [#<Itunes::Track:0x007fdd38a1d430 @persistent_id="571B6412CDADBC93", @name="Hello, Goodbye", @album="1", @artist="The Beatles", @track_count="27", @track_number="19">]
50
+
51
+ track = tracks.first
50
52
 
51
53
  # Play track
52
54
  track.play
data/lib/itunes/track.rb CHANGED
@@ -58,9 +58,8 @@ module Itunes
58
58
  self
59
59
  end
60
60
 
61
- def assign_attributes_by(itunes_response)
62
- track_data = ::JSON.parse(itunes_response)
63
- ATTRIBUTES.each { |attr| send("#{attr}=", track_data[attr.to_s]) }
61
+ def assign_attributes_by(track_attributes)
62
+ ATTRIBUTES.each { |attr| send("#{attr}=", track_attributes[attr.to_s]) }
64
63
  end
65
64
 
66
65
  def self.find_by(arg)
@@ -70,8 +69,11 @@ module Itunes
70
69
  script_name = generate_script_from_template('track/finder.tmpl.scpt', conditions: conditions)
71
70
  track_response = execute_template_based_script(script_name)
72
71
 
73
- Track.new.tap do |track|
74
- track.assign_attributes_by(track_response)
72
+ tracks_attributes = ::JSON.parse(track_response)
73
+ tracks_attributes.compact.map do |track_attributes|
74
+ Track.new.tap do |track|
75
+ track.assign_attributes_by(track_attributes)
76
+ end
75
77
  end
76
78
  end
77
79
 
@@ -1,3 +1,3 @@
1
1
  module Itunes
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,15 +1,23 @@
1
1
  tell application "iTunes"
2
- set specified_track to (some track whose #{conditions})
3
-
4
- set props to {}
5
- set end of props to "{"
6
- set end of props to ("\"persistent_id\":\"" & persistent ID of specified_track & "\",")
7
- set end of props to ("\"name\":\"" & name of specified_track & "\",")
8
- set end of props to ("\"album\":\"" & album of specified_track & "\",")
9
- set end of props to ("\"artist\":\"" & artist of specified_track & "\",")
10
- set end of props to ("\"track_count\":\"" & track count of specified_track & "\",")
11
- set end of props to ("\"track_number\":\"" & track number of specified_track & "\"")
12
- set end of props to "}"
13
-
14
- return props as string
2
+ set specified_tracks to (every track whose #{conditions})
3
+
4
+ set json to "["
5
+
6
+ repeat with specified_track in specified_tracks
7
+ set props to {}
8
+ set end of props to "{"
9
+ set end of props to ("\"persistent_id\":\"" & persistent ID of specified_track & "\",")
10
+ set end of props to ("\"name\":\"" & name of specified_track & "\",")
11
+ set end of props to ("\"album\":\"" & album of specified_track & "\",")
12
+ set end of props to ("\"artist\":\"" & artist of specified_track & "\",")
13
+ set end of props to ("\"track_count\":\"" & track count of specified_track & "\",")
14
+ set end of props to ("\"track_number\":\"" & track number of specified_track & "\"")
15
+ set end of props to "}"
16
+
17
+ set json to json & props as string & ","
18
+ end repeat
19
+
20
+ set json to json & "null]"
21
+ return json
22
+
15
23
  end tell
@@ -24,14 +24,15 @@ describe Application do
24
24
  with('application/add.scpt', file_name).and_return(new_persistent_id)
25
25
  Track.should_receive(:find_by).
26
26
  with(persistent_id: new_persistent_id).
27
- and_return(Track.new(persistent_id: new_persistent_id))
27
+ and_return([Track.new(persistent_id: new_persistent_id)])
28
28
  end
29
29
 
30
- it 'returns a track instance' do
31
- track = add
30
+ it 'returns an array of track instance' do
31
+ tracks = add
32
32
 
33
- expect(track).to be_a(Track)
34
- expect(track.persistent_id).to eq(new_persistent_id)
33
+ expect(tracks).to be_an(Array)
34
+ expect(tracks.size).to eq(1)
35
+ expect(tracks.first.persistent_id).to eq(new_persistent_id)
35
36
  end
36
37
  end
37
38
 
@@ -33,13 +33,14 @@ describe Track do
33
33
  and_return(new_persistent_id)
34
34
  Track.should_receive(:find_by).
35
35
  with(persistent_id: new_persistent_id).
36
- and_return(Track.new(persistent_id: new_persistent_id))
36
+ and_return([Track.new(persistent_id: new_persistent_id)])
37
37
  end
38
38
 
39
- it 'returns a new Track' do
40
- converted_track = convert
41
- expect(converted_track).to be_a(Track)
42
- expect(converted_track.persistent_id).to eq(new_persistent_id)
39
+ it 'returns an array of new Track' do
40
+ converted_tracks = convert
41
+ expect(converted_tracks).to be_an(Array)
42
+ expect(converted_tracks.size).to eq(1)
43
+ expect(converted_tracks.first.persistent_id).to eq(new_persistent_id)
43
44
  end
44
45
  end
45
46
 
@@ -94,7 +95,7 @@ describe Track do
94
95
  end
95
96
  end
96
97
 
97
- context 'when hash argument which has 1 key is given' do
98
+ context 'when hash argument is given' do
98
99
  let(:arg) { { name: name } }
99
100
  let(:new_scpt) { 'new.scpt' }
100
101
  let(:new_persistent_id) { 'bar' }
@@ -105,15 +106,14 @@ describe Track do
105
106
  and_return(new_scpt)
106
107
 
107
108
  Track.stub(:execute_template_based_script).
108
- and_return({ persistent_id: new_persistent_id, name: name }.to_json)
109
+ and_return([{ persistent_id: new_persistent_id, name: name }].to_json)
109
110
  end
110
111
 
111
- it 'returns a track with specified name' do
112
- track = find
113
- expect(track).to be_a(Track)
114
- expect(track.name).to eq(name)
112
+ it 'returns an array of track with specified name' do
113
+ tracks = find
114
+ expect(tracks.size).to eq(1)
115
+ expect(tracks.first.name).to eq(name)
115
116
  end
116
117
  end
117
-
118
118
  end
119
119
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itunes-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ryo katsuma