itunes_api 0.0.0 → 0.0.1

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: 741f5352a0fe5d1f9d3225f2347c25986c0ee77e
4
- data.tar.gz: 3e172f4d944181611d2e585243894f05cfdb2709
3
+ metadata.gz: 60692f8078fec897509d930b312f27f0864d6618
4
+ data.tar.gz: 1c7e4d06b470b8e3bcd7e68da4dc869e59e65842
5
5
  SHA512:
6
- metadata.gz: 92841595b57c3d85d5f442a7404bbf55e380f9c1793cfbe5a419417f02ab41e32ae4c0d0fdd89f3bb02e73cc4bc75a6b001f2d33ed51d938bb6f2a2ce0227953
7
- data.tar.gz: fb9e02023ce88e7a8cc84271a6ebe2b11f47cd1bd6b8610213c2965d4915238dad28551cc594dcc7083e701806a8d8c7d98a63f91ed75fd76a074df9eb5f3adb
6
+ metadata.gz: ace4631bd06fb8f7cd4ae8f18ab01eb35229d6fe9f86593a8401543fb4f913c2cd60a458835c195c156cb5d39b92b456e3bbd61bc188f8a4645a29c00c243ca3
7
+ data.tar.gz: f7394825a891aa37e78dff0b6b7a9eed179b3c81ab080e3296abbcd87e0c8bbd1a3a5d72dae72291d411dad31174967307d11781d4042a6dcfda45a388e403ad
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # ItunesApi
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/itunes_api`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ A simple interface for the Itunes Api.
6
4
 
7
5
  ## Installation
8
6
 
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "itunes_api"
3
+ require 'bundler/setup'
4
+ require 'itunes_api'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "itunes_api"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
data/itunes_api.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.email = ['mariodarco78@icloud.com']
19
19
  spec.summary = 'iTunes Api'
20
20
  spec.description = 'An interface to the iTunes Api'
21
- spec.homepage = 'https://rubygems.org/gems/itunes_api'
21
+ spec.homepage = 'https://github.com/mariodarco/itunes-api'
22
22
  spec.license = 'MIT'
23
23
  spec.bindir = 'exe'
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
@@ -0,0 +1,2 @@
1
+ require_relative 'request'
2
+ require_relative 'music/all'
@@ -0,0 +1,40 @@
1
+ module ItunesApi
2
+ module Music
3
+ # Use to retrieve available albums from artist's ids.
4
+ class Album
5
+ include Request
6
+
7
+ TYPE = 'Album'.freeze
8
+
9
+ def initialize(artists_id)
10
+ @artists_id = artists_id
11
+ end
12
+
13
+ def self.info(artists_id)
14
+ new(artists_id).info
15
+ end
16
+
17
+ def info
18
+ @info ||= results
19
+ .find_all { |r| r['collectionType'] == TYPE }
20
+ .sort_by { |a| a['releaseDate'] }
21
+ .reverse
22
+ end
23
+
24
+ private
25
+
26
+ def url
27
+ "#{BASE_URL}/lookup?id=#{all_artists_id}&" \
28
+ "entity=#{entity}&country=#{COUNTRY_CODE}"
29
+ end
30
+
31
+ def all_artists_id
32
+ @artists_id.join(',')
33
+ end
34
+
35
+ def entity
36
+ TYPE.downcase
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1 @@
1
+ require_relative 'album'
@@ -0,0 +1,19 @@
1
+ require 'open-uri'
2
+ require 'json'
3
+
4
+ module ItunesApi
5
+ # Allow requests to the iTunes API.
6
+ module Request
7
+ def request
8
+ @request ||= open(url).read
9
+ end
10
+
11
+ def response
12
+ JSON.parse(request)
13
+ end
14
+
15
+ def results
16
+ response.fetch('results', [])
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module ItunesApi
2
- VERSION = '0.0.0'
2
+ VERSION = '0.0.1'.freeze
3
3
  end
data/lib/itunes_api.rb CHANGED
@@ -1,9 +1,7 @@
1
- require 'itunes_api/version'
1
+ require 'itunes_api/all'
2
2
 
3
+ # Interface to the Itunes Api
3
4
  module ItunesApi
4
-
5
- # Your code goes here...
6
- def self.version
7
- VERSION
8
- end
5
+ COUNTRY_CODE = 'GB'.freeze
6
+ BASE_URL = 'https://itunes.apple.com'.freeze
9
7
  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.0.0
4
+ version: 0.0.1
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: 2016-11-11 00:00:00.000000000 Z
11
+ date: 2016-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,8 +85,12 @@ files:
85
85
  - bin/setup
86
86
  - itunes_api.gemspec
87
87
  - lib/itunes_api.rb
88
+ - lib/itunes_api/all.rb
89
+ - lib/itunes_api/music/album.rb
90
+ - lib/itunes_api/music/all.rb
91
+ - lib/itunes_api/request.rb
88
92
  - lib/itunes_api/version.rb
89
- homepage: https://rubygems.org/gems/itunes_api
93
+ homepage: https://github.com/mariodarco/itunes-api
90
94
  licenses:
91
95
  - MIT
92
96
  metadata: