itunes_api 0.6.0 → 0.7.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: 1d99e396f4049e8c7bd11bc060e06c3ff70aad41
4
- data.tar.gz: e4447f6837f2feb4025f414d5de2d23958944830
3
+ metadata.gz: '086360de32ce5889a48b42076307dad1053d3246'
4
+ data.tar.gz: 23a2bd2b8077266ba0e7f80b4675f3e21648341a
5
5
  SHA512:
6
- metadata.gz: 9a713e9774c704803155dcddbc1da773bd5c9c8180144cb5995e9d2d131a4a8916ab97c50b1f9e0fa6946e7d7a1710935ed057edb8c7f8c4ce59a5e06c43f733
7
- data.tar.gz: 99dd861be1948e382b33696a7027aceb3e00d8847a3b1016c6906c34368df668b4e4eb97f94c97df675b97ffb9c0a05b8fe7fc64891f025e668c249afa23702b
6
+ metadata.gz: 5254e87655037e9627c841f531977aae91d3cff571dfe717784f1c75e451e77890960b25207cfae7ce392f754604024b53daa7a72570d69522a9585a3a32cf14
7
+ data.tar.gz: aa4d762126de0bdf0087d2dd56ceba1690eed644ceca577247a269258ddd0afeb19c3ba32774ce08cc154b3699c7e08c9b72583d17e8a3d9905bd5e34fed3864
@@ -10,8 +10,8 @@ module ItunesApi
10
10
  @albums ||= Album.build(data[:albums])
11
11
  end
12
12
 
13
- def amg_id
14
- @amg_id ||= data[:amgArtistId]
13
+ def apple_id
14
+ @apple_id ||= data[:artistId]
15
15
  end
16
16
 
17
17
  def name
@@ -11,17 +11,21 @@ module ItunesApi
11
11
  end
12
12
 
13
13
  def artist
14
- @artist ||= build_artist(artist_id)
14
+ build_artist
15
15
  end
16
16
 
17
17
  private
18
18
 
19
19
  attr_reader :artist_id
20
20
 
21
- def build_artist(id)
22
- Artist.new(
23
- Requests::Lookup.artist_with_albums(id)
24
- )
21
+ def build_artist
22
+ return lookup unless lookup
23
+
24
+ Artist.new(lookup)
25
+ end
26
+
27
+ def lookup
28
+ @lookup ||= Requests::Lookup.artist_with_albums(artist_id)
25
29
  end
26
30
  end
27
31
  end
@@ -11,7 +11,7 @@ module ItunesApi
11
11
  end
12
12
 
13
13
  def artists
14
- @artists ||= artist_ids.map { |id| build_artist(id) }
14
+ @artists ||= artist_ids.map { |id| build_artist(id) }.compact
15
15
  end
16
16
 
17
17
  private
@@ -23,9 +23,15 @@ module ItunesApi
23
23
  end
24
24
 
25
25
  def build_artist(id)
26
- Artist.new(
27
- Requests::Lookup.artist_with_albums(id)
28
- )
26
+ if (lookup = lookup(id))
27
+ Artist.new(lookup)
28
+ end
29
+ end
30
+
31
+ def lookup(id)
32
+ Requests::Lookup.artist_with_albums(id)
33
+ rescue
34
+ nil
29
35
  end
30
36
  end
31
37
  end
@@ -13,6 +13,8 @@ module ItunesApi
13
13
  end
14
14
 
15
15
  def artist_with_albums
16
+ return artist unless artist
17
+
16
18
  artist.merge(albums: albums)
17
19
  end
18
20
 
@@ -33,11 +35,13 @@ module ItunesApi
33
35
  end
34
36
 
35
37
  def artist
38
+ return artist_data unless artist_data
39
+
36
40
  symbolize_keys(unwrapped(artist_data))
37
41
  end
38
42
 
39
43
  def artist_data
40
- results.find do |wrappers|
44
+ @artist_data ||= results.find do |wrappers|
41
45
  wrappers['wrapperType'] == 'artist'
42
46
  end
43
47
  end
@@ -45,16 +49,15 @@ module ItunesApi
45
49
  def query
46
50
  {
47
51
  entity: 'album',
48
- amgArtistId: @artist_id,
52
+ id: @artist_id,
49
53
  country: country_code,
50
54
  limit: LIMIT,
51
55
  sort: 'recent'
52
56
  }
53
57
  end
54
58
 
55
- def unwrapped(hash)
56
- hash.delete('wrapperType')
57
- hash
59
+ def unwrapped(data_hash)
60
+ data_hash.tap { |hash| hash.delete('wrapperType') }
58
61
  end
59
62
  end
60
63
  end
@@ -14,7 +14,7 @@ module ItunesApi
14
14
 
15
15
  def artist_ids
16
16
  results.collect do |result|
17
- result['amgArtistId']
17
+ result['artistId']
18
18
  end.compact.uniq.sort
19
19
  end
20
20
 
@@ -1,3 +1,3 @@
1
1
  module ItunesApi
2
- VERSION = '0.6.0'.freeze
2
+ VERSION = '0.7.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.6.0
4
+ version: 0.7.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-05-24 00:00:00.000000000 Z
11
+ date: 2017-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday