itunes_api 2.0.0 → 2.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b59950a6d1529d61e387ac0ef1306324959bc43d
4
- data.tar.gz: d5bb63b84da411992c53a7178224e34023d2f02a
3
+ metadata.gz: c771828d631c80dd7ef7b555ca9172c79b58baf8
4
+ data.tar.gz: 60fdc7036173756e07a4f0d64561b8b20b58552f
5
5
  SHA512:
6
- metadata.gz: 4cabff1c9f4a1d757231f46d1623ed2d5506efee42e289ae92e63aa979bff1a3a6944e8170c885d468d2a0f314715192b5108385609d8a91e50317b0b802ee33
7
- data.tar.gz: 63d044a01c39946370f2133a0190a0fad390db937fca70d43ac4b1885134154bff678ddccb489906602144e3dea5b66815b87a39115af2f795c904a9236d9ec6
6
+ metadata.gz: 3b5989a5a4b21a7073321545974ae04f55df3d3d504598017ec6e0aba56df4f7c5233a2f7cd6886b5d8e610c2cf29b9f374cac5eb74eaf729669ac20c66e4556
7
+ data.tar.gz: 11b1ae2aa25b1671dc00f9fb200ab0020876e6a926f2ac8a8cae8774178726a0bc12f1b97478d551db0d51717a125d94ea4758d765b6650174ca056a90607a39
data/README.md CHANGED
@@ -64,6 +64,17 @@ To return only the albums for a specific artist, based on the artist's Apple id
64
64
  ItunesApi::Music.albums_for_artist(265766061)
65
65
  ```
66
66
 
67
+ To return a specific album, based on the album's collection id
68
+
69
+ ```ruby
70
+ ItunesApi::Music.find_by_collection_id(collection_id, store)
71
+ ```
72
+
73
+ Note that each request that returns albums does not automatically return songs.
74
+ They are lazily fetched when calling album.tracklist.
75
+
76
+ ---
77
+
67
78
  An argument holding the country code can be used to look into different stores than the default one
68
79
 
69
80
  ```ruby
@@ -76,12 +87,14 @@ ItunesApi::Music.albums_for_artist(265766061, :es)
76
87
  ## Development
77
88
 
78
89
  Ruby version:
79
- ```
90
+
91
+ ```text
80
92
  2.4.1
81
93
  ```
82
94
 
83
95
  Fork the project, clone the repository and bundle:
84
- ```
96
+
97
+ ```bash
85
98
  >> git clone https://github.com/{your_account}/itunes-api.git
86
99
  >> cd itunes-api
87
100
  ```
@@ -92,7 +105,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
92
105
 
93
106
  ## Contributing
94
107
 
95
- 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.
108
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/mariodarco/itunes-api](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.
96
109
 
97
110
  ## License
98
111
 
@@ -3,15 +3,34 @@ module ItunesApi
3
3
  module Music
4
4
  # Wrapper for album results.
5
5
  class Album
6
- attr_reader_init :artwork, :collection_id, :genre, :name, :release_on, :store
6
+ attr_reader_init :artist,
7
+ :artwork,
8
+ :collection_id,
9
+ :explicitness,
10
+ :genre,
11
+ :link,
12
+ :name,
13
+ :release_on,
14
+ :store,
15
+ :track_count
7
16
 
8
17
  class << self
18
+ def find_by_collection_id(collection_id, store)
19
+ result = album(collection_id, store)
20
+
21
+ new(*result.attributes) if result
22
+ end
23
+
9
24
  def for_artist(apple_id, store)
10
25
  albums(apple_id, store).map { |album| new(*album.attributes) }
11
26
  end
12
27
 
13
28
  private
14
29
 
30
+ def album(collection_id, store)
31
+ Requests::Albums.find_by_collection_id(collection_id, store)
32
+ end
33
+
15
34
  def albums(apple_id, store)
16
35
  Requests::Albums.find_by_apple_id(apple_id, store)
17
36
  end
@@ -21,14 +40,23 @@ module ItunesApi
21
40
  @availability ||= build_availability
22
41
  end
23
42
 
43
+ def explicit?
44
+ explicitness == 'explicit'
45
+ end
46
+
24
47
  def to_hash
25
48
  {
49
+ artist: artist,
26
50
  artwork: artwork,
27
51
  availability: availability,
28
52
  collection_id: collection_id,
53
+ explicit: explicit?,
54
+ genre: genre,
55
+ link: link,
29
56
  name: name,
30
57
  release_on: release_on,
31
- store: store
58
+ store: store,
59
+ track_count: track_count
32
60
  }
33
61
  end
34
62
 
@@ -2,7 +2,7 @@ module ItunesApi
2
2
  module Music
3
3
  # Artist or Band from the Apple catalog
4
4
  class Artist
5
- attr_reader_init :apple_id, :genre, :name, :store
5
+ attr_reader_init :amg_id, :apple_id, :genre, :link, :name, :store
6
6
 
7
7
  class << self
8
8
  def all_apple_ids(name, store)
@@ -33,7 +33,10 @@ module ItunesApi
33
33
 
34
34
  def to_hash
35
35
  {
36
+ amg_id: amg_id,
36
37
  apple_id: apple_id,
38
+ genre: genre,
39
+ link: link,
37
40
  name: name,
38
41
  store: store
39
42
  }
@@ -4,8 +4,8 @@ module ItunesApi
4
4
  # Allows querying the API via lookup for albums.
5
5
  class Albums
6
6
  include Request
7
- attr_reader_init :apple_id, :store
8
- selfie :find_by_apple_id
7
+ attr_reader_init :search_id, :store
8
+ selfie :find_by_apple_id, :find_by_collection_id
9
9
 
10
10
  def find_by_apple_id
11
11
  unwrapped_results.map do |result|
@@ -13,6 +13,10 @@ module ItunesApi
13
13
  end
14
14
  end
15
15
 
16
+ def find_by_collection_id
17
+ find_by_apple_id.first
18
+ end
19
+
16
20
  private
17
21
 
18
22
  def action
@@ -21,7 +25,7 @@ module ItunesApi
21
25
 
22
26
  def query
23
27
  {
24
- id: apple_id,
28
+ id: search_id,
25
29
  country: store.to_s.upcase,
26
30
  entity: :album,
27
31
  limit: LIMIT
@@ -6,22 +6,45 @@ module ItunesApi
6
6
  attr_reader_init :data, :store
7
7
  private :data
8
8
 
9
+ def artist
10
+ @artist ||= data['artistName']
11
+ end
12
+
9
13
  def artwork
10
14
  @artwork ||= data['artworkUrl100']
11
15
  end
12
16
 
13
17
  def attributes
14
- [artwork, collection_id, genre, name, release_on, store]
18
+ [
19
+ artist,
20
+ artwork,
21
+ collection_id,
22
+ explicitness,
23
+ genre,
24
+ link,
25
+ name,
26
+ release_on,
27
+ store,
28
+ track_count
29
+ ]
15
30
  end
16
31
 
17
32
  def collection_id
18
33
  @collection_id ||= data['collectionId']
19
34
  end
20
35
 
36
+ def explicitness
37
+ @explicitness ||= data['collectionExplicitness']
38
+ end
39
+
21
40
  def genre
22
41
  @genre ||= data['primaryGenreName']
23
42
  end
24
43
 
44
+ def link
45
+ @link ||= data['collectionViewUrl']
46
+ end
47
+
25
48
  def name
26
49
  @name ||= data['collectionName']
27
50
  end
@@ -29,6 +52,10 @@ module ItunesApi
29
52
  def release_on
30
53
  @release_on ||= Date.parse(data['releaseDate'])
31
54
  end
55
+
56
+ def track_count
57
+ @track_count ||= data['trackCount']
58
+ end
32
59
  end
33
60
  end
34
61
  end
@@ -6,18 +6,26 @@ module ItunesApi
6
6
  attr_reader_init :data, :store, search_term: nil
7
7
  private :data, :search_term
8
8
 
9
+ def amg_id
10
+ @amg_id ||= data['amgArtistId']
11
+ end
12
+
9
13
  def apple_id
10
14
  @apple_id ||= data['artistId']
11
15
  end
12
16
 
13
17
  def attributes
14
- [apple_id, genre, name, store]
18
+ [amg_id, apple_id, genre, link, name, store]
15
19
  end
16
20
 
17
21
  def genre
18
22
  @genre ||= data['primaryGenreName']
19
23
  end
20
24
 
25
+ def link
26
+ @link ||= data['artistLinkUrl']
27
+ end
28
+
21
29
  def name
22
30
  @name ||= data['artistName']
23
31
  end
@@ -10,7 +10,7 @@ module ItunesApi
10
10
  duration: duration,
11
11
  name: name,
12
12
  number: number,
13
- stremable: streamable?,
13
+ stremable: streamable?
14
14
  }
15
15
  end
16
16
  end
@@ -25,6 +25,10 @@ module ItunesApi
25
25
  Music::Album.for_artist(apple_id, store)
26
26
  end
27
27
 
28
+ def find_by_collection_id(collection_id, store)
29
+ Music::Album.find_by_collection_id(collection_id, store)
30
+ end
31
+
28
32
  private
29
33
 
30
34
  def default_store
@@ -1,3 +1,3 @@
1
1
  module ItunesApi
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '2.1.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: 2.0.0
4
+ version: 2.1.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: 2017-08-04 00:00:00.000000000 Z
11
+ date: 2017-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday