itunes_api 1.0.0 → 1.1.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 +12 -8
- data/itunes_api.gemspec +2 -0
- data/lib/itunes_api/music/album.rb +15 -3
- data/lib/itunes_api/music/album_lookup.rb +21 -0
- data/lib/itunes_api/music/all.rb +2 -0
- data/lib/itunes_api/music/artist.rb +2 -2
- data/lib/itunes_api/music/artist_lookup.rb +1 -1
- data/lib/itunes_api/music/artist_search.rb +1 -1
- data/lib/itunes_api/music/track.rb +46 -0
- data/lib/itunes_api/requests/album_tracklist.rb +36 -0
- data/lib/itunes_api/requests/all.rb +1 -0
- data/lib/itunes_api/requests/base.rb +4 -0
- data/lib/itunes_api/requests/lookup.rb +1 -5
- data/lib/itunes_api/version.rb +1 -1
- data/lib/itunes_api.rb +4 -0
- metadata +32 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1810ef10c9524ed9723f646906484b6a30e9e0b8
|
4
|
+
data.tar.gz: 6506854bfadcf78976c134e745b87412645c052d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2cb36e5ada9e4a679d8e0da83bf0dc25c185785c64ad620b6c3c2997d8787e0627fcadeafab29774928bd1d35bcab0ff3a082363030183c7fa7523bab24880a
|
7
|
+
data.tar.gz: 695d0dc2e55ee694e6eddd94b5d1da1308131cde7603cd16a1f70a3b82af70ad8ea0924532d8c87f0788e3d4acf079088cc50708270d5dbd41dfb6f6a18b4e50
|
data/README.md
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
[![Gem Version](https://badge.fury.io/rb/itunes_api.svg)](https://badge.fury.io/rb/itunes_api) [![Dependency Status](https://gemnasium.com/badges/github.com/mariodarco/itunes-api.svg)](https://gemnasium.com/github.com/mariodarco/itunes-api) [![CircleCI](https://circleci.com/gh/mariodarco/itunes-api/tree/master.svg?style=shield)](https://circleci.com/gh/mariodarco/itunes-api/tree/master)
|
2
|
-
|
3
|
-
|
4
1
|
# ItunesApi
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/itunes_api.svg)](https://badge.fury.io/rb/itunes_api) [![Dependency Status](https://gemnasium.com/badges/github.com/mariodarco/itunes-api.svg)](https://gemnasium.com/github.com/mariodarco/itunes-api) [![CircleCI](https://circleci.com/gh/mariodarco/itunes-api/tree/master.svg?style=shield)](https://circleci.com/gh/mariodarco/itunes-api/tree/master) [![Coverage Status](https://coveralls.io/repos/github/mariodarco/itunes-api/badge.svg?branch=master)](https://coveralls.io/github/mariodarco/itunes-api?branch=master)
|
5
3
|
|
6
4
|
A simple interface for the Itunes Api.
|
7
5
|
|
@@ -42,22 +40,28 @@ To return all the Apple ids associated with a search term.
|
|
42
40
|
ItunesApi.artist_ids('Pink Floyd')
|
43
41
|
```
|
44
42
|
|
43
|
+
To get all artists returning from a search term, and their albums.
|
44
|
+
```ruby
|
45
|
+
ItunesApi.artist_search('Led Zeppelin')
|
46
|
+
```
|
47
|
+
|
45
48
|
To return a specific artist with albums, based on the Apple id.
|
46
49
|
```ruby
|
47
|
-
ItunesApi.artist_lookup(
|
50
|
+
ItunesApi.artist_lookup(265766061)
|
48
51
|
```
|
49
52
|
|
50
|
-
To
|
53
|
+
To return the tracklist for a specific albums, based on the Apple collection id.
|
51
54
|
```ruby
|
52
|
-
ItunesApi.
|
55
|
+
ItunesApi.album_lookup(286930912)
|
53
56
|
```
|
54
57
|
|
55
58
|
An argument holding the country code can be used to look into different stores than the default one.
|
56
59
|
|
57
60
|
```ruby
|
58
61
|
ItunesApi.artist_ids('Pink Floyd', :it)
|
59
|
-
ItunesApi.
|
60
|
-
ItunesApi.
|
62
|
+
ItunesApi.artist_search('Led Zeppelin', :fr)
|
63
|
+
ItunesApi.artist_lookup(265766061, :us)
|
64
|
+
ItunesApi.album_lookup(286930912, :gb)
|
61
65
|
```
|
62
66
|
|
63
67
|
## Development
|
data/itunes_api.gemspec
CHANGED
@@ -27,8 +27,10 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_dependency 'selfies'
|
28
28
|
|
29
29
|
spec.add_development_dependency 'bundler'
|
30
|
+
spec.add_development_dependency 'coveralls'
|
30
31
|
spec.add_development_dependency 'rake'
|
31
32
|
spec.add_development_dependency 'rspec'
|
33
|
+
spec.add_development_dependency 'simplecov'
|
32
34
|
spec.add_development_dependency 'rubocop'
|
33
35
|
spec.add_development_dependency 'vcr'
|
34
36
|
end
|
@@ -1,12 +1,13 @@
|
|
1
|
+
require 'date'
|
1
2
|
module ItunesApi
|
2
3
|
module Music
|
3
4
|
# Wrapper for album results.
|
4
5
|
class Album
|
5
|
-
attr_reader_init :data
|
6
|
+
attr_reader_init :data, :store
|
6
7
|
private :data
|
7
8
|
|
8
|
-
def self.build(albums_data)
|
9
|
-
albums_data.map { |data| new(data) }
|
9
|
+
def self.build(albums_data, store)
|
10
|
+
albums_data.map { |data| new(data, store) }
|
10
11
|
.sort_by(&:released)
|
11
12
|
.reverse
|
12
13
|
end
|
@@ -15,6 +16,10 @@ module ItunesApi
|
|
15
16
|
@artwork ||= data[:artworkUrl100]
|
16
17
|
end
|
17
18
|
|
19
|
+
def apple_music?
|
20
|
+
tracklist.any?(&:streamable?)
|
21
|
+
end
|
22
|
+
|
18
23
|
def collection_id
|
19
24
|
@collection_id ||= data[:collectionId]
|
20
25
|
end
|
@@ -33,8 +38,15 @@ module ItunesApi
|
|
33
38
|
collection_id: collection_id,
|
34
39
|
name: name,
|
35
40
|
released: released,
|
41
|
+
apple_music: apple_music?
|
36
42
|
}
|
37
43
|
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def tracklist
|
48
|
+
@tracklist ||= AlbumLookup.tracklist(collection_id, store)
|
49
|
+
end
|
38
50
|
end
|
39
51
|
end
|
40
52
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ItunesApi
|
2
|
+
module Music
|
3
|
+
# Album Tracklist resulting from a specific lookup
|
4
|
+
class AlbumLookup
|
5
|
+
attr_reader_init :album_id, :store
|
6
|
+
selfie :tracklist
|
7
|
+
|
8
|
+
def tracklist
|
9
|
+
return [] unless songs_data
|
10
|
+
|
11
|
+
Track.build(songs_data)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def songs_data
|
17
|
+
@songs_data ||= Requests::AlbumTracklist.songs(album_id, store)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/itunes_api/music/all.rb
CHANGED
@@ -2,11 +2,11 @@ module ItunesApi
|
|
2
2
|
module Music
|
3
3
|
# Artist or Band from the Apple catalog
|
4
4
|
class Artist
|
5
|
-
attr_reader_init :data
|
5
|
+
attr_reader_init :data, :store
|
6
6
|
private :data
|
7
7
|
|
8
8
|
def albums
|
9
|
-
@albums ||= Album.build(data[:albums])
|
9
|
+
@albums ||= Album.build(data[:albums], store)
|
10
10
|
end
|
11
11
|
|
12
12
|
def apple_id
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module ItunesApi
|
2
|
+
module Music
|
3
|
+
# Wrapper for song results.
|
4
|
+
class Track
|
5
|
+
attr_reader_init :data
|
6
|
+
private :data
|
7
|
+
|
8
|
+
def self.build(songs_data)
|
9
|
+
songs_data.map { |data| new(data) }
|
10
|
+
end
|
11
|
+
|
12
|
+
def duration
|
13
|
+
@duration ||= track_lenght(data[:trackTimeMillis])
|
14
|
+
end
|
15
|
+
|
16
|
+
def name
|
17
|
+
@name ||= data[:trackName]
|
18
|
+
end
|
19
|
+
|
20
|
+
def number
|
21
|
+
data[:trackNumber]
|
22
|
+
end
|
23
|
+
|
24
|
+
def streamable?
|
25
|
+
data[:isStreamable]
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_hash
|
29
|
+
{
|
30
|
+
duration: duration,
|
31
|
+
name: name,
|
32
|
+
number: number,
|
33
|
+
stremable: stremable?,
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def track_lenght(milliseconds)
|
40
|
+
minutes, milliseconds = milliseconds.divmod(1000 * 60)
|
41
|
+
seconds = milliseconds / 1000
|
42
|
+
"#{minutes}:#{seconds}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module ItunesApi
|
2
|
+
module Requests
|
3
|
+
# Allows querying the API via lookup for album songs.
|
4
|
+
class AlbumTracklist
|
5
|
+
include Base
|
6
|
+
attr_reader_init :album_id, :store
|
7
|
+
selfie :songs
|
8
|
+
|
9
|
+
def songs
|
10
|
+
songs_data.map do |song|
|
11
|
+
symbolize_keys(unwrapped(song))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def action
|
18
|
+
'lookup'
|
19
|
+
end
|
20
|
+
|
21
|
+
def songs_data
|
22
|
+
results.find_all { |wrappers| wrappers['wrapperType'] == 'track' }
|
23
|
+
end
|
24
|
+
|
25
|
+
def query
|
26
|
+
{
|
27
|
+
entity: 'song',
|
28
|
+
id: album_id,
|
29
|
+
country: store.to_s.upcase,
|
30
|
+
limit: LIMIT,
|
31
|
+
sort: 'trackNumber'
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -43,16 +43,12 @@ module ItunesApi
|
|
43
43
|
def query
|
44
44
|
{
|
45
45
|
entity: 'album',
|
46
|
-
id:
|
46
|
+
id: artist_id,
|
47
47
|
country: store.to_s.upcase,
|
48
48
|
limit: LIMIT,
|
49
49
|
sort: 'recent'
|
50
50
|
}
|
51
51
|
end
|
52
|
-
|
53
|
-
def unwrapped(data_hash)
|
54
|
-
data_hash.tap { |hash| hash.delete('wrapperType') }
|
55
|
-
end
|
56
52
|
end
|
57
53
|
end
|
58
54
|
end
|
data/lib/itunes_api/version.rb
CHANGED
data/lib/itunes_api.rb
CHANGED
@@ -12,6 +12,10 @@ module ItunesApi
|
|
12
12
|
Requests::Search.artist_ids(name, store)
|
13
13
|
end
|
14
14
|
|
15
|
+
def self.album_lookup(album_id, store = default_store)
|
16
|
+
Music::AlbumLookup.tracklist(album_id, store)
|
17
|
+
end
|
18
|
+
|
15
19
|
def self.artist_lookup(artist_id, store = default_store)
|
16
20
|
Music::ArtistLookup.artist(artist_id, store)
|
17
21
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: itunes_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario D’Arco
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rake
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +94,20 @@ dependencies:
|
|
80
94
|
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: rubocop
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,10 +156,13 @@ files:
|
|
128
156
|
- lib/itunes_api.rb
|
129
157
|
- lib/itunes_api/configuration.rb
|
130
158
|
- lib/itunes_api/music/album.rb
|
159
|
+
- lib/itunes_api/music/album_lookup.rb
|
131
160
|
- lib/itunes_api/music/all.rb
|
132
161
|
- lib/itunes_api/music/artist.rb
|
133
162
|
- lib/itunes_api/music/artist_lookup.rb
|
134
163
|
- lib/itunes_api/music/artist_search.rb
|
164
|
+
- lib/itunes_api/music/track.rb
|
165
|
+
- lib/itunes_api/requests/album_tracklist.rb
|
135
166
|
- lib/itunes_api/requests/all.rb
|
136
167
|
- lib/itunes_api/requests/base.rb
|
137
168
|
- lib/itunes_api/requests/lookup.rb
|