itunes_api 0.1.0 → 0.2.0
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/.ruby-version +1 -0
- data/README.md +1 -1
- data/itunes_api.gemspec +1 -1
- data/lib/itunes_api/music/album.rb +15 -17
- data/lib/itunes_api/music/artist.rb +15 -16
- data/lib/itunes_api/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0cefe7c03674f77de95c0ad26c37f7bcf1846228
|
4
|
+
data.tar.gz: d0ae1fa1c14205710238e2c49ec8d61f6c4fb332
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 602db34f182e67fae632a47a5e3a955c964ed5c27c36e36ea6a910ffbaef40d04f2969250f613e0f4f9f184ab42813be6aa96d076e186b84375d93cb14a5d556
|
7
|
+
data.tar.gz: ae5429fdef3d026b6c881d275d296781323d769db55b9f49d1474f736c2422b6835fbf2f5582b084423a1fef1b4cbec71fb481fdd1422d024207c91c4913d1e3
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.4
|
data/README.md
CHANGED
@@ -30,7 +30,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
30
30
|
|
31
31
|
## Contributing
|
32
32
|
|
33
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/mariodarco/
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mariodarco/itunes-api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
34
34
|
|
35
35
|
|
36
36
|
## License
|
data/itunes_api.gemspec
CHANGED
@@ -35,5 +35,5 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.add_development_dependency 'bundler', '~> 1.13'
|
36
36
|
spec.add_development_dependency 'rake', '~> 10.0'
|
37
37
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
38
|
-
spec.add_development_dependency 'rubocop'
|
38
|
+
spec.add_development_dependency 'rubocop'
|
39
39
|
end
|
@@ -2,36 +2,34 @@ module ItunesApi
|
|
2
2
|
module Music
|
3
3
|
# Retrieves album tracks info.
|
4
4
|
class Album
|
5
|
-
attr_accessor :name
|
5
|
+
attr_accessor :name, :artwork, :track_count, :release_date
|
6
6
|
include Request
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@name =
|
10
|
-
@
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
@tracks ||= filtered_results.sort_by { |track| track['trackNumber'] }
|
8
|
+
def initialize(info)
|
9
|
+
@name = info['collectionName']
|
10
|
+
@album_id = info['collectionId']
|
11
|
+
@artwork = info['artworkUrl100']
|
12
|
+
@track_count = info['trackCount']
|
13
|
+
@release_date = Date.parse(info['releaseDate'])
|
15
14
|
end
|
16
15
|
|
17
16
|
def apple_music?
|
18
|
-
|
17
|
+
streamable_tracks.any?
|
19
18
|
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
def album_id
|
24
|
-
@album_id ||= @filtering_options[:album_id]
|
20
|
+
def streamable_tracks
|
21
|
+
tracks.select { |track| track['isStreamable'] }
|
25
22
|
end
|
26
23
|
|
27
|
-
def
|
28
|
-
@
|
24
|
+
def tracks
|
25
|
+
@tracks ||= filtered_results.sort_by { |track| track['trackNumber'] }
|
29
26
|
end
|
30
27
|
|
28
|
+
private
|
29
|
+
|
31
30
|
def filtered_results
|
32
31
|
@filtered_results ||= results.find_all do |result|
|
33
|
-
|
34
|
-
(!artist_id || result['artistId'] == artist_id)
|
32
|
+
result['collectionId'] == @album_id
|
35
33
|
end
|
36
34
|
end
|
37
35
|
|
@@ -8,7 +8,7 @@ module ItunesApi
|
|
8
8
|
|
9
9
|
def initialize(artist_name, apple_id = nil)
|
10
10
|
@artist_name = artist_name
|
11
|
-
@apple_id = apple_id
|
11
|
+
@apple_id = normalize(apple_id.to_i)
|
12
12
|
end
|
13
13
|
|
14
14
|
def albums(limit = 3)
|
@@ -16,32 +16,31 @@ module ItunesApi
|
|
16
16
|
.sort_by { |result| result['releaseDate'] }
|
17
17
|
.reverse
|
18
18
|
.first(limit)
|
19
|
-
.map { |
|
19
|
+
.map { |info| Album.new(info) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def normalize(apple_id)
|
23
|
+
apple_id.zero? ? nil : apple_id
|
20
24
|
end
|
21
25
|
|
22
26
|
def apple_ids
|
23
|
-
@
|
27
|
+
return [@apple_id] if @apple_id
|
28
|
+
|
29
|
+
@apple_ids ||= filtered_albums.collect do |album|
|
24
30
|
album['artistId']
|
25
31
|
end.compact.uniq.sort
|
26
32
|
end
|
27
33
|
|
28
34
|
private
|
29
35
|
|
30
|
-
def
|
31
|
-
results.find_all
|
32
|
-
result['collectionType'] == 'Album' &&
|
33
|
-
(!@apple_id || result['artistId'] == @apple_id)
|
34
|
-
end
|
36
|
+
def filtered_albums
|
37
|
+
results.find_all { |result| result['collectionType'] == 'Album' }
|
35
38
|
end
|
36
39
|
|
37
|
-
def
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
artist_id: @apple_id,
|
42
|
-
album_id: result['collectionId']
|
43
|
-
}
|
44
|
-
)
|
40
|
+
def filtered_results
|
41
|
+
filtered_albums.find_all do |album|
|
42
|
+
(!@apple_id || album['artistId'] == @apple_id)
|
43
|
+
end
|
45
44
|
end
|
46
45
|
|
47
46
|
def query_values
|
data/lib/itunes_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: itunes_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario D’Arco
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: rubocop
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0
|
82
|
+
version: '0'
|
83
83
|
description: An interface to the iTunes Api
|
84
84
|
email:
|
85
85
|
- mariodarco78@icloud.com
|
@@ -89,6 +89,7 @@ extra_rdoc_files: []
|
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
91
|
- ".rspec"
|
92
|
+
- ".ruby-version"
|
92
93
|
- ".travis.yml"
|
93
94
|
- CODE_OF_CONDUCT.md
|
94
95
|
- Gemfile
|
@@ -126,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
127
|
version: '0'
|
127
128
|
requirements: []
|
128
129
|
rubyforge_project:
|
129
|
-
rubygems_version: 2.
|
130
|
+
rubygems_version: 2.6.8
|
130
131
|
signing_key:
|
131
132
|
specification_version: 4
|
132
133
|
summary: iTunes Api
|