itunes_api 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 977e293cb1119a93c8307fa6777c4fc56a2c2070
4
- data.tar.gz: 7dbe4950ee63e43462c06d2549ef5a01cc94cc0a
3
+ metadata.gz: 0cefe7c03674f77de95c0ad26c37f7bcf1846228
4
+ data.tar.gz: d0ae1fa1c14205710238e2c49ec8d61f6c4fb332
5
5
  SHA512:
6
- metadata.gz: b526669ffe54690bc851552129c8a3c7507298b66e883617981732221ed07740c04d7f0fd9715bf69104f8bb03be05ce9d472273b051d8986efb059c78f47229
7
- data.tar.gz: c8db2f679fb319d0aa1f503f4cf8f7aaa5a3f192eda61295f8e9aa5410fd4a8fa1010e6a63362f40c3f4f6dbdf498ab6fb96f5cd4a64cc2a70447a794058b663
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/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.
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', '~> 0.45'
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(name, filtering_options = {})
9
- @name = name
10
- @filtering_options = filtering_options
11
- end
12
-
13
- def tracks
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
- tracks.any? { |track| track['isStreamable'] }
17
+ streamable_tracks.any?
19
18
  end
20
19
 
21
- private
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 artist_id
28
- @artist_id ||= @filtering_options[:artist_id]
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
- (!album_id || result['collectionId'] == album_id) &&
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 { |result| album(result) }
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
- @apple_ids ||= filtered_results.collect do |album|
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 filtered_results
31
- results.find_all do |result|
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 album(result)
38
- Album.new(
39
- result['collectionName'],
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
@@ -1,3 +1,3 @@
1
1
  module ItunesApi
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
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.1.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: 2016-11-26 00:00:00.000000000 Z
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.45'
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.45'
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.5.1
130
+ rubygems_version: 2.6.8
130
131
  signing_key:
131
132
  specification_version: 4
132
133
  summary: iTunes Api