itunes_api 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -12
- data/lib/itunes_api/music/album.rb +5 -13
- data/lib/itunes_api/music/artist.rb +7 -10
- data/lib/itunes_api/music/requests/albums.rb +4 -16
- data/lib/itunes_api/music/requests/artist.rb +7 -7
- data/lib/itunes_api/music/requests/songs.rb +7 -15
- data/lib/itunes_api/music/results/song.rb +44 -3
- data/lib/itunes_api/music/song.rb +44 -2
- data/lib/itunes_api/music.rb +13 -9
- data/lib/itunes_api/request.rb +12 -4
- data/lib/itunes_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0119772a5f3282816339b02adb15ed086292f73
|
4
|
+
data.tar.gz: dfcbbf5230c641efba8adf69ecbb6f6405329ca9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78a8a929d19ce114f8821f9dac825ee5bdb05164ca1b435886768d3d976e2912595ffd4421f090b2656568c3d1704ebb7f12c8f8251166732d2e30604e47df74
|
7
|
+
data.tar.gz: e08ab36a8e01cc425fc05cdfaaf195b31f1566ccbcfd280a505c5d8ea2ceb85f3d2cff3ef686d086dc3405cc7ce6503b6efa33f61bc5096ed2e03d663cc8df8b
|
data/README.md
CHANGED
@@ -37,16 +37,10 @@ end
|
|
37
37
|
|
38
38
|
## Usage
|
39
39
|
|
40
|
-
To return all the Apple ids associated with the search for a Artist name
|
41
|
-
|
42
|
-
```ruby
|
43
|
-
ItunesApi::Music.all_apple_ids('Pink Floyd')
|
44
|
-
```
|
45
|
-
|
46
40
|
To get all artists returning from a search term
|
47
41
|
|
48
42
|
```ruby
|
49
|
-
ItunesApi::Music.
|
43
|
+
ItunesApi::Music.find_by_name('Led Zeppelin')
|
50
44
|
```
|
51
45
|
|
52
46
|
To return a specific artist, based on the artist's Apple id
|
@@ -61,27 +55,38 @@ They are lazily fetched when calling artist.albums.
|
|
61
55
|
To return only the albums for a specific artist, based on the artist's Apple id
|
62
56
|
|
63
57
|
```ruby
|
64
|
-
ItunesApi::Music.
|
58
|
+
ItunesApi::Music.find_albums_by_apple_id(265766061)
|
65
59
|
```
|
66
60
|
|
67
61
|
To return a specific album, based on the album's collection id
|
68
62
|
|
69
63
|
```ruby
|
70
|
-
ItunesApi::Music.find_by_collection_id(
|
64
|
+
ItunesApi::Music.find_by_collection_id(286930912)
|
71
65
|
```
|
72
66
|
|
73
67
|
Note that each request that returns albums does not automatically return songs.
|
74
68
|
They are lazily fetched when calling album.tracklist.
|
75
69
|
|
70
|
+
To return only the songs for a specific album, based on the album's collection id
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
ItunesApi::Music.find_songs_by_collection_id(286930912)
|
74
|
+
```
|
75
|
+
|
76
|
+
To return a specific track, based on its track id
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
ItunesApi::Music.find_by_track_id(286931522)
|
80
|
+
```
|
81
|
+
|
76
82
|
---
|
77
83
|
|
78
84
|
An argument holding the country code can be used to look into different stores than the default one
|
79
85
|
|
80
86
|
```ruby
|
81
|
-
ItunesApi::Music.
|
82
|
-
ItunesApi::Music.all_artists_by_name('Led Zeppelin', :fr)
|
87
|
+
ItunesApi::Music.find_by_name('Led Zeppelin', :fr)
|
83
88
|
ItunesApi::Music.find_by_apple_id(265766061, :us)
|
84
|
-
ItunesApi::Music.
|
89
|
+
ItunesApi::Music.find_albums_by_apple_id(265766061, :es)
|
85
90
|
```
|
86
91
|
|
87
92
|
## Development
|
@@ -16,23 +16,19 @@ module ItunesApi
|
|
16
16
|
|
17
17
|
class << self
|
18
18
|
def find_by_collection_id(collection_id, store)
|
19
|
-
result =
|
19
|
+
result = albums(collection_id, store).first
|
20
20
|
|
21
21
|
new(*result.attributes) if result
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
24
|
+
def find_by_apple_id(apple_id, store)
|
25
25
|
albums(apple_id, store).map { |album| new(*album.attributes) }
|
26
26
|
end
|
27
27
|
|
28
28
|
private
|
29
29
|
|
30
|
-
def
|
31
|
-
Requests::Albums.
|
32
|
-
end
|
33
|
-
|
34
|
-
def albums(apple_id, store)
|
35
|
-
Requests::Albums.find_by_apple_id(apple_id, store)
|
30
|
+
def albums(id, store)
|
31
|
+
Requests::Albums.find_by_id(id, store)
|
36
32
|
end
|
37
33
|
end
|
38
34
|
|
@@ -61,7 +57,7 @@ module ItunesApi
|
|
61
57
|
end
|
62
58
|
|
63
59
|
def tracklist
|
64
|
-
@tracklist ||=
|
60
|
+
@tracklist ||= Song.find_by_collection_id(collection_id, store)
|
65
61
|
end
|
66
62
|
|
67
63
|
private
|
@@ -79,10 +75,6 @@ module ItunesApi
|
|
79
75
|
def pre_release?
|
80
76
|
release_on > Date.today
|
81
77
|
end
|
82
|
-
|
83
|
-
def songs
|
84
|
-
@songs ||= Requests::Songs.find_by_collection_id(collection_id, store)
|
85
|
-
end
|
86
78
|
end
|
87
79
|
end
|
88
80
|
end
|
@@ -5,30 +5,27 @@ module ItunesApi
|
|
5
5
|
attr_reader_init :amg_id, :apple_id, :genre, :link, :name, :store
|
6
6
|
|
7
7
|
class << self
|
8
|
-
def
|
9
|
-
find_all_by_name(name, store).map(&:apple_id)
|
10
|
-
end
|
11
|
-
|
12
|
-
def find_all_by_name(name, store)
|
8
|
+
def find_by_name(name, store)
|
13
9
|
Requests::Search.artists(name, store).map do |result|
|
14
10
|
new(*result.attributes)
|
15
11
|
end
|
16
12
|
end
|
17
13
|
|
18
14
|
def find_by_apple_id(apple_id, store)
|
19
|
-
|
20
|
-
|
15
|
+
result = artists(apple_id, store).first
|
16
|
+
|
17
|
+
new(*result.attributes) if result
|
21
18
|
end
|
22
19
|
|
23
20
|
private
|
24
21
|
|
25
|
-
def
|
26
|
-
Requests::Artist.
|
22
|
+
def artists(id, store)
|
23
|
+
Requests::Artist.find_by_id(id, store)
|
27
24
|
end
|
28
25
|
end
|
29
26
|
|
30
27
|
def albums
|
31
|
-
@albums ||= Album.
|
28
|
+
@albums ||= Album.find_by_apple_id(apple_id, store)
|
32
29
|
end
|
33
30
|
|
34
31
|
def to_hash
|
@@ -5,18 +5,14 @@ module ItunesApi
|
|
5
5
|
class Albums
|
6
6
|
include Request
|
7
7
|
attr_reader_init :search_id, :store
|
8
|
-
selfie :
|
8
|
+
selfie :find_by_id
|
9
9
|
|
10
|
-
def
|
11
|
-
unwrapped_results.map do |result|
|
10
|
+
def find_by_id
|
11
|
+
unwrapped_results(:collection).map do |result|
|
12
12
|
Results::Album.new(result, store)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
def find_by_collection_id
|
17
|
-
find_by_apple_id.first
|
18
|
-
end
|
19
|
-
|
20
16
|
private
|
21
17
|
|
22
18
|
def action
|
@@ -25,20 +21,12 @@ module ItunesApi
|
|
25
21
|
|
26
22
|
def query
|
27
23
|
{
|
28
|
-
id: search_id,
|
29
24
|
country: store.to_s.upcase,
|
30
25
|
entity: :album,
|
26
|
+
id: search_id,
|
31
27
|
limit: LIMIT
|
32
28
|
}
|
33
29
|
end
|
34
|
-
|
35
|
-
def unwrapped_results
|
36
|
-
return [] unless results.any?
|
37
|
-
|
38
|
-
results.find_all do |wrappers|
|
39
|
-
wrappers['wrapperType'] == 'collection'
|
40
|
-
end
|
41
|
-
end
|
42
30
|
end
|
43
31
|
end
|
44
32
|
end
|
@@ -4,13 +4,13 @@ module ItunesApi
|
|
4
4
|
# Allows querying the API via lookup for artists.
|
5
5
|
class Artist
|
6
6
|
include Request
|
7
|
-
attr_reader_init :
|
8
|
-
selfie :
|
7
|
+
attr_reader_init :search_id, :store
|
8
|
+
selfie :find_by_id
|
9
9
|
|
10
|
-
def
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def find_by_id
|
11
|
+
unwrapped_results(:artist).map do |result|
|
12
|
+
Results::Artist.new(result, store)
|
13
|
+
end
|
14
14
|
end
|
15
15
|
|
16
16
|
private
|
@@ -21,7 +21,7 @@ module ItunesApi
|
|
21
21
|
|
22
22
|
def query
|
23
23
|
{
|
24
|
-
id:
|
24
|
+
id: search_id,
|
25
25
|
country: store.to_s.upcase,
|
26
26
|
limit: LIMIT
|
27
27
|
}
|
@@ -4,12 +4,12 @@ module ItunesApi
|
|
4
4
|
# Allows querying the API via lookup for album songs.
|
5
5
|
class Songs
|
6
6
|
include Request
|
7
|
-
attr_reader_init :
|
8
|
-
selfie :
|
7
|
+
attr_reader_init :search_id, :store
|
8
|
+
selfie :find_by_id
|
9
9
|
|
10
|
-
def
|
11
|
-
unwrapped_results.map do |result|
|
12
|
-
Results::Song.new(result)
|
10
|
+
def find_by_id
|
11
|
+
unwrapped_results(:track).map do |result|
|
12
|
+
Results::Song.new(result, store)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -21,21 +21,13 @@ module ItunesApi
|
|
21
21
|
|
22
22
|
def query
|
23
23
|
{
|
24
|
-
entity: 'song',
|
25
|
-
id: collection_id,
|
26
24
|
country: store.to_s.upcase,
|
25
|
+
entity: 'song',
|
26
|
+
id: search_id,
|
27
27
|
limit: LIMIT,
|
28
28
|
sort: 'trackNumber'
|
29
29
|
}
|
30
30
|
end
|
31
|
-
|
32
|
-
def unwrapped_results
|
33
|
-
return [] unless results.any?
|
34
|
-
|
35
|
-
results.find_all do |wrappers|
|
36
|
-
wrappers['wrapperType'] == 'track'
|
37
|
-
end
|
38
|
-
end
|
39
31
|
end
|
40
32
|
end
|
41
33
|
end
|
@@ -3,15 +3,48 @@ module ItunesApi
|
|
3
3
|
module Results
|
4
4
|
# Wrapper for song search results.
|
5
5
|
class Song
|
6
|
-
attr_reader_init :data
|
6
|
+
attr_reader_init :data, :store
|
7
7
|
private :data
|
8
8
|
|
9
|
+
def album
|
10
|
+
@album ||= data['collectionName']
|
11
|
+
end
|
12
|
+
|
13
|
+
def artist
|
14
|
+
@artist ||= data['artistName']
|
15
|
+
end
|
16
|
+
|
17
|
+
def attributes
|
18
|
+
[
|
19
|
+
album,
|
20
|
+
artist,
|
21
|
+
duration,
|
22
|
+
explicitness,
|
23
|
+
genre,
|
24
|
+
link,
|
25
|
+
name,
|
26
|
+
number,
|
27
|
+
preview,
|
28
|
+
store,
|
29
|
+
streamable,
|
30
|
+
track_id
|
31
|
+
]
|
32
|
+
end
|
33
|
+
|
9
34
|
def duration
|
10
35
|
@duration ||= track_lenght(data['trackTimeMillis'])
|
11
36
|
end
|
12
37
|
|
13
|
-
def
|
14
|
-
|
38
|
+
def explicitness
|
39
|
+
@explicitness ||= data['trackExplicitness']
|
40
|
+
end
|
41
|
+
|
42
|
+
def genre
|
43
|
+
@genre ||= data['primaryGenreName']
|
44
|
+
end
|
45
|
+
|
46
|
+
def link
|
47
|
+
@link ||= data['trackViewUrl']
|
15
48
|
end
|
16
49
|
|
17
50
|
def name
|
@@ -22,10 +55,18 @@ module ItunesApi
|
|
22
55
|
@number ||= data['trackNumber']
|
23
56
|
end
|
24
57
|
|
58
|
+
def preview
|
59
|
+
@preview ||= data['previewUrl']
|
60
|
+
end
|
61
|
+
|
25
62
|
def streamable
|
26
63
|
@streamable ||= data['isStreamable']
|
27
64
|
end
|
28
65
|
|
66
|
+
def track_id
|
67
|
+
@track_id ||= data['trackId']
|
68
|
+
end
|
69
|
+
|
29
70
|
private
|
30
71
|
|
31
72
|
def track_lenght(milliseconds)
|
@@ -2,15 +2,57 @@ module ItunesApi
|
|
2
2
|
module Music
|
3
3
|
# Wrapper for song results.
|
4
4
|
class Song
|
5
|
-
attr_reader_init :
|
5
|
+
attr_reader_init :album,
|
6
|
+
:artist,
|
7
|
+
:duration,
|
8
|
+
:explicitness,
|
9
|
+
:genre,
|
10
|
+
:link,
|
11
|
+
:name,
|
12
|
+
:number,
|
13
|
+
:preview,
|
14
|
+
:store,
|
15
|
+
:streamable,
|
16
|
+
:track_id
|
17
|
+
|
6
18
|
alias streamable? streamable
|
7
19
|
|
20
|
+
class << self
|
21
|
+
def find_by_collection_id(collection_id, store)
|
22
|
+
songs(collection_id, store).map { |song| new(*song.attributes) }
|
23
|
+
end
|
24
|
+
|
25
|
+
def find_by_track_id(track_id, store)
|
26
|
+
result = songs(track_id, store).first
|
27
|
+
|
28
|
+
new(*result.attributes) if result
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def songs(id, store)
|
34
|
+
Requests::Songs.find_by_id(id, store)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def explicit?
|
39
|
+
explicitness == 'explicit'
|
40
|
+
end
|
41
|
+
|
8
42
|
def to_hash
|
9
43
|
{
|
44
|
+
album: album,
|
45
|
+
artist: artist,
|
10
46
|
duration: duration,
|
47
|
+
explicit: explicit?,
|
48
|
+
genre: genre,
|
49
|
+
link: link,
|
11
50
|
name: name,
|
12
51
|
number: number,
|
13
|
-
|
52
|
+
preview: preview,
|
53
|
+
store: store,
|
54
|
+
streamable: streamable,
|
55
|
+
track_id: track_id
|
14
56
|
}
|
15
57
|
end
|
16
58
|
end
|
data/lib/itunes_api/music.rb
CHANGED
@@ -9,26 +9,30 @@ module ItunesApi
|
|
9
9
|
# Public interface for the Music Api
|
10
10
|
module Music
|
11
11
|
class << self
|
12
|
-
def
|
13
|
-
Artist.
|
14
|
-
end
|
15
|
-
|
16
|
-
def all_artists_by_name(name, store = default_store)
|
17
|
-
Artist.find_all_by_name(name, store)
|
12
|
+
def find_by_name(name, store = default_store)
|
13
|
+
Artist.find_by_name(name, store)
|
18
14
|
end
|
19
15
|
|
20
16
|
def find_by_apple_id(apple_id, store = default_store)
|
21
17
|
Music::Artist.find_by_apple_id(apple_id, store)
|
22
18
|
end
|
23
19
|
|
24
|
-
def
|
25
|
-
Music::Album.
|
20
|
+
def find_albums_by_apple_id(apple_id, store = default_store)
|
21
|
+
Music::Album.find_by_apple_id(apple_id, store)
|
26
22
|
end
|
27
23
|
|
28
|
-
def find_by_collection_id(collection_id, store)
|
24
|
+
def find_by_collection_id(collection_id, store = default_store)
|
29
25
|
Music::Album.find_by_collection_id(collection_id, store)
|
30
26
|
end
|
31
27
|
|
28
|
+
def find_songs_by_collection_id(collection_id, store = default_store)
|
29
|
+
Music::Song.find_by_collection_id(collection_id, store)
|
30
|
+
end
|
31
|
+
|
32
|
+
def find_by_track_id(track_id, store = default_store)
|
33
|
+
Music::Song.find_by_track_id(track_id, store)
|
34
|
+
end
|
35
|
+
|
32
36
|
private
|
33
37
|
|
34
38
|
def default_store
|
data/lib/itunes_api/request.rb
CHANGED
@@ -9,16 +9,24 @@ module ItunesApi
|
|
9
9
|
|
10
10
|
private
|
11
11
|
|
12
|
-
def parsed_response
|
13
|
-
JSON.parse(response.body)
|
14
|
-
end
|
15
|
-
|
16
12
|
def connection
|
17
13
|
Faraday.new(url: BASE_URL)
|
18
14
|
end
|
19
15
|
|
16
|
+
def parsed_response
|
17
|
+
JSON.parse(response.body)
|
18
|
+
end
|
19
|
+
|
20
20
|
def response
|
21
21
|
connection.get(action, query)
|
22
22
|
end
|
23
|
+
|
24
|
+
def unwrapped_results(type)
|
25
|
+
return [] unless results.any?
|
26
|
+
|
27
|
+
results.find_all do |wrappers|
|
28
|
+
wrappers['wrapperType'] == type.to_s
|
29
|
+
end
|
30
|
+
end
|
23
31
|
end
|
24
32
|
end
|
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: 2.
|
4
|
+
version: 2.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: 2017-08-
|
11
|
+
date: 2017-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|