itunes_api 0.8.2 → 1.0.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: 5e034da09b20707fbc47ec4c10d71eec8ff51ae7
4
- data.tar.gz: 03b55ba82587b3d17f649813416471eee5d5cdb3
3
+ metadata.gz: 3b7a79e554749a6e18d54f28f00105456d35fa9b
4
+ data.tar.gz: f4c3493a4838318d654a8fe6fb5cd13c5ff51ad5
5
5
  SHA512:
6
- metadata.gz: a311e497aefb2cf29ca16b0cd05b2b340fe15fd0b1b19a991967c438cce23b0831f7c8076a1d02115dee11e3815033e4576cf02984149d7027abf8a92841795d
7
- data.tar.gz: 0b2df8c24652bbfb8028c0343a015ee43cdb1995e25cb7d2df8b1220d607833a3e1b88532802893b3a9976165f4e86895fda279b7804cff3c723933b2ca090db
6
+ metadata.gz: 442270dae2b4da5febc278f62cf3a69ef9b9c2fab310faeecba5efd71080be2925059d3a82c495060fed926e490f45038212497183874153c62679394b0d0ee2
7
+ data.tar.gz: 7feeadb252a1849aa7f760f2c9920aa12e11a0482269b321b032dc7968e42fff57415c420a7667632401ba719b275075d70d0a6a5a1886b4f9fd5f8084c38a09
data/README.md CHANGED
@@ -31,18 +31,18 @@ Add an initializer to your app to set the country for the Store:
31
31
  ```ruby
32
32
  # config/initializers/itunes_api.rb
33
33
  ItunesApi.configure do |config|
34
- config.country_code = ENV['COUNTRY_CODE']
34
+ config.country_code = ENV['COUNTRY_CODE'] || :gb
35
35
  end
36
36
  ```
37
37
 
38
38
  ## Usage
39
39
 
40
- To return all the AMG ids associated with a search term.
40
+ To return all the Apple ids associated with a search term.
41
41
  ```ruby
42
42
  ItunesApi.artist_ids('Pink Floyd')
43
43
  ```
44
44
 
45
- To return a specific artist with albums, based on the AMG id.
45
+ To return a specific artist with albums, based on the Apple id.
46
46
  ```ruby
47
47
  ItunesApi.artist_lookup(12345)
48
48
  ```
@@ -52,6 +52,14 @@ To get all artists returning from a search term, and their albums.
52
52
  ItunesApi.artist_search('Pink Floyd')
53
53
  ```
54
54
 
55
+ An argument holding the country code can be used to look into different stores than the default one.
56
+
57
+ ```ruby
58
+ ItunesApi.artist_ids('Pink Floyd', :it)
59
+ ItunesApi.artist_lookup(12345, :us)
60
+ ItunesApi.artist_search('Pink Floyd', :fr)
61
+ ```
62
+
55
63
  ## Development
56
64
 
57
65
  Ruby version:
@@ -2,8 +2,8 @@ module ItunesApi
2
2
  module Music
3
3
  # Artist or Band resulting from a specific lookup
4
4
  class ArtistLookup
5
- attr_reader_init :artist_id
6
- selfie :artist
5
+ attr_reader_init :artist_id, :store
6
+ selfie :artist, :store
7
7
 
8
8
  def artist
9
9
  build_artist
@@ -18,7 +18,7 @@ module ItunesApi
18
18
  end
19
19
 
20
20
  def lookup
21
- @lookup ||= Requests::Lookup.artist_with_albums(artist_id)
21
+ @lookup ||= Requests::Lookup.artist_with_albums(artist_id, store)
22
22
  end
23
23
  end
24
24
  end
@@ -2,7 +2,7 @@ module ItunesApi
2
2
  module Music
3
3
  # Artists or Bands resulting from a search
4
4
  class ArtistSearch
5
- attr_reader_init :name
5
+ attr_reader_init :name, :store
6
6
  selfie :artists
7
7
 
8
8
  def artists
@@ -12,7 +12,7 @@ module ItunesApi
12
12
  private
13
13
 
14
14
  def artist_ids
15
- @search ||= ItunesApi.artist_ids(name)
15
+ @search ||= ItunesApi.artist_ids(name, store)
16
16
  end
17
17
 
18
18
  def build_artist(id)
@@ -22,7 +22,7 @@ module ItunesApi
22
22
  end
23
23
 
24
24
  def lookup(id)
25
- Requests::Lookup.artist_with_albums(id)
25
+ Requests::Lookup.artist_with_albums(id, store)
26
26
  rescue
27
27
  nil
28
28
  end
@@ -18,10 +18,6 @@ module ItunesApi
18
18
  Faraday.new(url: BASE_URL)
19
19
  end
20
20
 
21
- def country_code
22
- Configuration.instance.country_code || 'GB'
23
- end
24
-
25
21
  def response
26
22
  connection.get(action, query)
27
23
  end
@@ -3,7 +3,7 @@ module ItunesApi
3
3
  # Allows querying the API via lookup.
4
4
  class Lookup
5
5
  include Base
6
- attr_reader_init :artist_id
6
+ attr_reader_init :artist_id, :store
7
7
  selfie :artist_with_albums
8
8
 
9
9
  def artist_with_albums
@@ -44,7 +44,7 @@ module ItunesApi
44
44
  {
45
45
  entity: 'album',
46
46
  id: @artist_id,
47
- country: country_code,
47
+ country: store.to_s.upcase,
48
48
  limit: LIMIT,
49
49
  sort: 'recent'
50
50
  }
@@ -3,7 +3,7 @@ module ItunesApi
3
3
  # Fetch all the artist ids corresponding to a search term
4
4
  class Search
5
5
  include Base
6
- attr_reader_init :artist_name
6
+ attr_reader_init :artist_name, :store
7
7
  selfie :artist_ids
8
8
 
9
9
  def artist_ids
@@ -23,7 +23,7 @@ module ItunesApi
23
23
  attribute: 'artistTerm',
24
24
  entity: 'album',
25
25
  term: @artist_name,
26
- country: country_code,
26
+ country: store.to_s.upcase,
27
27
  limit: LIMIT,
28
28
  media: 'music',
29
29
  sort: 'recent'
@@ -1,3 +1,3 @@
1
1
  module ItunesApi
2
- VERSION = '0.8.2'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
data/lib/itunes_api.rb CHANGED
@@ -8,19 +8,25 @@ module ItunesApi
8
8
  BASE_URL = 'https://itunes.apple.com'.freeze
9
9
  LIMIT = 200
10
10
 
11
- def self.artist_ids(name)
12
- Requests::Search.artist_ids(name)
11
+ def self.artist_ids(name, store = default_store)
12
+ Requests::Search.artist_ids(name, store)
13
13
  end
14
14
 
15
- def self.artist_lookup(artist_id)
16
- Music::ArtistLookup.artist(artist_id)
15
+ def self.artist_lookup(artist_id, store = default_store)
16
+ Music::ArtistLookup.artist(artist_id, store)
17
17
  end
18
18
 
19
- def self.artist_search(name)
20
- Music::ArtistSearch.artists(name)
19
+ def self.artist_search(name, store = default_store)
20
+ Music::ArtistSearch.artists(name, store)
21
21
  end
22
22
 
23
23
  def self.configure
24
24
  yield(Configuration.instance)
25
25
  end
26
+
27
+ private
28
+
29
+ def self.default_store
30
+ Configuration.instance.country_code rescue :gb
31
+ end
26
32
  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.8.2
4
+ version: 1.0.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-07-04 00:00:00.000000000 Z
11
+ date: 2017-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday