ruby_deezer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +11 -0
- data/Gemfile.lock +26 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +18 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/lib/ruby_deezer/album.rb +51 -0
- data/lib/ruby_deezer/artist.rb +53 -0
- data/lib/ruby_deezer/track.rb +51 -0
- data/lib/ruby_deezer.rb +7 -0
- data/pkg/ruby_deezer-0.1.0.gem +0 -0
- data/ruby_deezer.gemspec +82 -0
- data/test/fixtures/album.json +20 -0
- data/test/fixtures/albums.json +41 -0
- data/test/fixtures/artist.json +1774 -0
- data/test/fixtures/artists.json +23 -0
- data/test/fixtures/track.json +21 -0
- data/test/fixtures/tracks.json +68 -0
- data/test/helper.rb +18 -0
- data/test/unit/test_album.rb +29 -0
- data/test/unit/test_artist.rb +29 -0
- data/test/unit/test_track.rb +36 -0
- metadata +185 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (2.3.5)
|
5
|
+
crack (0.1.8)
|
6
|
+
fakeweb (1.3.0)
|
7
|
+
git (1.2.5)
|
8
|
+
httparty (0.7.4)
|
9
|
+
crack (= 0.1.8)
|
10
|
+
jeweler (1.5.2)
|
11
|
+
bundler (~> 1.0.0)
|
12
|
+
git (>= 1.2.5)
|
13
|
+
rake
|
14
|
+
rake (0.8.7)
|
15
|
+
will_paginate (2.3.15)
|
16
|
+
|
17
|
+
PLATFORMS
|
18
|
+
ruby
|
19
|
+
|
20
|
+
DEPENDENCIES
|
21
|
+
activesupport (= 2.3.5)
|
22
|
+
bundler (~> 1.0.0)
|
23
|
+
fakeweb
|
24
|
+
httparty (~> 0.7.4)
|
25
|
+
jeweler (~> 1.5.2)
|
26
|
+
will_paginate (= 2.3.15)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Aleksandr Lossenko
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= RubyDeezer
|
2
|
+
|
3
|
+
RubyDeezer is a ruby wrapper for the Deezer APIs ( http://www.deezer.com/en/#developers/simpleapi/ ).
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
gem install ruby_deezer
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
|
11
|
+
RubyDeezer::Artist.find(13)
|
12
|
+
RubyDeezer::Artist.search("eminem", {:per_page => 10, :page => 1}) # options can be skipped, default is 10 per page
|
13
|
+
|
14
|
+
RubyDeezer::Album.find(13)
|
15
|
+
RubyDeezer::Album.search("eminem", {:per_page => 10, :page => 1}) # options can be skipped, default is 10 per page
|
16
|
+
|
17
|
+
RubyDeezer::Track.find(13)
|
18
|
+
RubyDeezer::Track.search("eminem", {:per_page => 10, :page => 1}) # options can be skipped, default is 10 per page
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "ruby_deezer"
|
16
|
+
gem.homepage = "http://github.com/egze/ruby_deezer"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = "RubyDeezer is a ruby wrapper for the Deezer APIs"
|
19
|
+
gem.description = "Search for artists, albums and tracks with Deezer API"
|
20
|
+
gem.email = "alossenko@gmail.com"
|
21
|
+
gem.authors = ["Aleksandr Lossenko"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
end
|
25
|
+
Jeweler::RubygemsDotOrgTasks.new
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
Rake::TestTask.new(:test) do |test|
|
29
|
+
test.libs << 'lib' << 'test'
|
30
|
+
test.pattern = 'test/**/test_*.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :default => :test
|
35
|
+
|
36
|
+
require 'rake/rdoctask'
|
37
|
+
Rake::RDocTask.new do |rdoc|
|
38
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
39
|
+
|
40
|
+
rdoc.rdoc_dir = 'rdoc'
|
41
|
+
rdoc.title = "ruby_deezer #{version}"
|
42
|
+
rdoc.rdoc_files.include('README*')
|
43
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
44
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module RubyDeezer
|
2
|
+
|
3
|
+
class Album
|
4
|
+
|
5
|
+
include HTTParty
|
6
|
+
base_uri 'api-v3.deezer.com/1.0'
|
7
|
+
format :json
|
8
|
+
|
9
|
+
attr_accessor :id, :name, :url, :image, :nb_tracks, :nb_disks, :year, :tracks, :artist
|
10
|
+
|
11
|
+
def self.find(id, options = [])
|
12
|
+
response = get("/lookup/album/", {:query => {:id => id, :output => 'json', :options => options.join(",")}})
|
13
|
+
artist = response ? Album.init_from_hash(response['album']) : nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.search(query, options = {})
|
17
|
+
per_page = options.delete(:per_page) || 10
|
18
|
+
page = options.delete(:page) || 1
|
19
|
+
index = (page - 1) * per_page
|
20
|
+
|
21
|
+
response = get("/search/album/", {:query => {:q => query, :output => 'json', :index => index, :nb_items => per_page}})
|
22
|
+
albums = response && response["search"] && response["search"]["albums"] ?
|
23
|
+
response["search"]["albums"]["album"].inject([]){|arr, hash| arr << Album.init_from_hash(hash); arr } : []
|
24
|
+
|
25
|
+
|
26
|
+
WillPaginate::Collection.create(page, per_page) do |pager|
|
27
|
+
pager.replace albums
|
28
|
+
pager.total_entries = response['search']['total_results'].to_i rescue 0
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.init_from_hash(hash)
|
33
|
+
return nil unless hash.is_a?(Hash)
|
34
|
+
tracks = hash["tracks"] || []
|
35
|
+
artist = hash["artist"] || {}
|
36
|
+
Album.new.tap do |album|
|
37
|
+
album.id = hash["id"].to_i
|
38
|
+
album.name = hash["name"]
|
39
|
+
album.url = hash["url"]
|
40
|
+
album.image = hash["image"]
|
41
|
+
album.nb_tracks = hash["nb_tracks"].to_i
|
42
|
+
album.nb_disks = hash["nb_disks"].to_i
|
43
|
+
album.year = hash["year"].to_i
|
44
|
+
album.tracks = tracks.inject([]) {|arr, track| arr << Track.init_from_hash(track); arr}
|
45
|
+
album.artist = Artist.init_from_hash(artist)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module RubyDeezer
|
2
|
+
|
3
|
+
class Artist
|
4
|
+
|
5
|
+
include HTTParty
|
6
|
+
base_uri 'api-v3.deezer.com/1.0'
|
7
|
+
format :json
|
8
|
+
|
9
|
+
attr_accessor :id, :name, :url, :image, :similar_artists, :discography
|
10
|
+
|
11
|
+
alias :albums :discography
|
12
|
+
|
13
|
+
def self.find(id, options = [])
|
14
|
+
response = get("/lookup/artist/", {:query => {:id => id, :output => 'json', :options => options.join(",")}})
|
15
|
+
artist = response ? Artist.init_from_hash(response['artist']) : nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.search(query, options = {})
|
19
|
+
per_page = options.delete(:per_page) || 10
|
20
|
+
page = options.delete(:page) || 1
|
21
|
+
index = (page - 1) * per_page
|
22
|
+
|
23
|
+
response = get("/search/artist/", {:query => {:q => query, :output => 'json', :index => index, :nb_items => per_page}})
|
24
|
+
artists = response && response["search"] && response["search"]["artists"] ?
|
25
|
+
response["search"]["artists"]["artist"].inject([]){|arr, hash| arr << Artist.init_from_hash(hash); arr } : []
|
26
|
+
|
27
|
+
|
28
|
+
WillPaginate::Collection.create(page, per_page) do |pager|
|
29
|
+
pager.replace artists
|
30
|
+
pager.total_entries = response['search']['total_results'].to_i rescue 0
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.init_from_hash(hash)
|
35
|
+
return nil unless hash.is_a?(Hash)
|
36
|
+
similar_artists = hash["similar_artists"] || {}
|
37
|
+
similar_artists_array = similar_artists["artist"] || []
|
38
|
+
discography = hash["discography"] || {}
|
39
|
+
discography_array = discography["album"] || []
|
40
|
+
Artist.new.tap do |artist|
|
41
|
+
artist.id = hash["id"].to_i
|
42
|
+
artist.name = hash["name"]
|
43
|
+
artist.url = hash["url"]
|
44
|
+
artist.image = hash["image"]
|
45
|
+
artist.similar_artists = similar_artists_array.inject([]) {|arr, hash| arr << init_from_hash(hash); arr}
|
46
|
+
artist.discography = discography_array.inject([]) {|arr, hash| arr << Album.init_from_hash(hash); arr}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module RubyDeezer
|
2
|
+
|
3
|
+
class Track
|
4
|
+
|
5
|
+
include HTTParty
|
6
|
+
base_uri 'api-v3.deezer.com/1.0'
|
7
|
+
format :json
|
8
|
+
|
9
|
+
attr_accessor :id, :name, :url, :duration, :rank, :artist, :album
|
10
|
+
|
11
|
+
def self.find(id)
|
12
|
+
response = get("/lookup/track/", {:query => {:id => id, :output => 'json'}})
|
13
|
+
artist = response ? Track.init_from_hash(response['track']) : nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.search(query, options = {})
|
17
|
+
per_page = options.delete(:per_page) || 10
|
18
|
+
page = options.delete(:page) || 1
|
19
|
+
index = (page - 1) * per_page
|
20
|
+
|
21
|
+
response = get("/search/track/", {:query => {:q => query, :output => 'json', :index => index, :nb_items => per_page}})
|
22
|
+
tracks = response && response["search"] && response["search"]["tracks"] ?
|
23
|
+
response["search"]["tracks"]["track"].inject([]){|arr, hash| arr << Track.init_from_hash(hash); arr } : []
|
24
|
+
|
25
|
+
|
26
|
+
WillPaginate::Collection.create(page, per_page) do |pager|
|
27
|
+
pager.replace tracks
|
28
|
+
pager.total_entries = response['search']['total_results'].to_i rescue 0
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.init_from_hash(hash)
|
33
|
+
return nil unless hash.is_a?(Hash)
|
34
|
+
Track.new.tap do |track|
|
35
|
+
track.id = hash["id"].to_i
|
36
|
+
track.name = hash["name"]
|
37
|
+
track.url = hash["url"]
|
38
|
+
track.duration = hash["duration"].to_i
|
39
|
+
track.rank = hash["rank"].to_i
|
40
|
+
if hash["artist"]
|
41
|
+
track.artist = Artist.init_from_hash(hash["artist"])
|
42
|
+
end
|
43
|
+
if hash["album"]
|
44
|
+
track.album = Album.init_from_hash(hash["album"])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
data/lib/ruby_deezer.rb
ADDED
Binary file
|
data/ruby_deezer.gemspec
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{ruby_deezer}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Aleksandr Lossenko"]
|
12
|
+
s.date = %q{2011-03-04}
|
13
|
+
s.description = %q{Search for artists, albums and tracks with Deezer API}
|
14
|
+
s.email = %q{alossenko@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
"Gemfile",
|
21
|
+
"Gemfile.lock",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/ruby_deezer.rb",
|
27
|
+
"lib/ruby_deezer/album.rb",
|
28
|
+
"lib/ruby_deezer/artist.rb",
|
29
|
+
"lib/ruby_deezer/track.rb",
|
30
|
+
"pkg/ruby_deezer-0.1.0.gem",
|
31
|
+
"ruby_deezer.gemspec",
|
32
|
+
"test/fixtures/album.json",
|
33
|
+
"test/fixtures/albums.json",
|
34
|
+
"test/fixtures/artist.json",
|
35
|
+
"test/fixtures/artists.json",
|
36
|
+
"test/fixtures/track.json",
|
37
|
+
"test/fixtures/tracks.json",
|
38
|
+
"test/helper.rb",
|
39
|
+
"test/unit/test_album.rb",
|
40
|
+
"test/unit/test_artist.rb",
|
41
|
+
"test/unit/test_track.rb"
|
42
|
+
]
|
43
|
+
s.homepage = %q{http://github.com/egze/ruby_deezer}
|
44
|
+
s.licenses = ["MIT"]
|
45
|
+
s.require_paths = ["lib"]
|
46
|
+
s.rubygems_version = %q{1.4.2}
|
47
|
+
s.summary = %q{RubyDeezer is a ruby wrapper for the Deezer APIs}
|
48
|
+
s.test_files = [
|
49
|
+
"test/helper.rb",
|
50
|
+
"test/unit/test_album.rb",
|
51
|
+
"test/unit/test_artist.rb",
|
52
|
+
"test/unit/test_track.rb"
|
53
|
+
]
|
54
|
+
|
55
|
+
if s.respond_to? :specification_version then
|
56
|
+
s.specification_version = 3
|
57
|
+
|
58
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
59
|
+
s.add_runtime_dependency(%q<activesupport>, ["= 2.3.5"])
|
60
|
+
s.add_runtime_dependency(%q<httparty>, ["~> 0.7.4"])
|
61
|
+
s.add_runtime_dependency(%q<will_paginate>, ["= 2.3.15"])
|
62
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
63
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
64
|
+
s.add_development_dependency(%q<fakeweb>, [">= 0"])
|
65
|
+
else
|
66
|
+
s.add_dependency(%q<activesupport>, ["= 2.3.5"])
|
67
|
+
s.add_dependency(%q<httparty>, ["~> 0.7.4"])
|
68
|
+
s.add_dependency(%q<will_paginate>, ["= 2.3.15"])
|
69
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
70
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
71
|
+
s.add_dependency(%q<fakeweb>, [">= 0"])
|
72
|
+
end
|
73
|
+
else
|
74
|
+
s.add_dependency(%q<activesupport>, ["= 2.3.5"])
|
75
|
+
s.add_dependency(%q<httparty>, ["~> 0.7.4"])
|
76
|
+
s.add_dependency(%q<will_paginate>, ["= 2.3.15"])
|
77
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
78
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
79
|
+
s.add_dependency(%q<fakeweb>, [">= 0"])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
{
|
2
|
+
"album":{
|
3
|
+
"artist":{
|
4
|
+
"id":"60",
|
5
|
+
"name":"Don Choa",
|
6
|
+
"url":"http:\/\/www.deezer.com\/en\/music\/don-choa",
|
7
|
+
"image":"http:\/\/cdn-images.deezer.com\/images\/artist\/0906ddc614e0988ab91f37666b3391b7\/90x90-000000-80-0-0.jpg"
|
8
|
+
},
|
9
|
+
"id":"64",
|
10
|
+
"name":"Vapeurs Toxiques",
|
11
|
+
"url":"http:\/\/www.deezer.com\/en\/music\/don-choa\/vapeurs-toxiques-64",
|
12
|
+
"image":"http:\/\/cdn-images.deezer.com\/images\/cover\/162922e3732a312053f14bb47480ce84\/150x150-000000-80-0-0.jpg",
|
13
|
+
"nb_tracks":"0",
|
14
|
+
"nb_disks":"1",
|
15
|
+
"year":"2010",
|
16
|
+
"tracks":{
|
17
|
+
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
{
|
2
|
+
"search":{
|
3
|
+
"total_results":91,
|
4
|
+
"start_index":2,
|
5
|
+
"items_per_page":2,
|
6
|
+
"albums":{
|
7
|
+
"album":[
|
8
|
+
{
|
9
|
+
"artist":{
|
10
|
+
"id":"13",
|
11
|
+
"name":"Eminem",
|
12
|
+
"url":"http:\/\/www.deezer.com\/en\/music\/eminem",
|
13
|
+
"image":"http:\/\/cdn-images.deezer.com\/images\/artist\/cb286a88a55a10847d1ac0f47798380c\/90x90-000000-80-0-0.jpg"
|
14
|
+
},
|
15
|
+
"id":"595243",
|
16
|
+
"name":"Recovery",
|
17
|
+
"url":"http:\/\/www.deezer.com\/en\/music\/eminem\/recovery-595243",
|
18
|
+
"image":"http:\/\/cdn-images.deezer.com\/images\/cover\/be682506145061814eddee648edb7c59\/150x150-000000-80-0-0.jpg",
|
19
|
+
"nb_tracks":"17",
|
20
|
+
"nb_disks":"1",
|
21
|
+
"year":"2010"
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"artist":{
|
25
|
+
"id":"13",
|
26
|
+
"name":"Eminem",
|
27
|
+
"url":"http:\/\/www.deezer.com\/en\/music\/eminem",
|
28
|
+
"image":"http:\/\/cdn-images.deezer.com\/images\/artist\/cb286a88a55a10847d1ac0f47798380c\/90x90-000000-80-0-0.jpg"
|
29
|
+
},
|
30
|
+
"id":"350198",
|
31
|
+
"name":"Relapse",
|
32
|
+
"url":"http:\/\/www.deezer.com\/en\/music\/eminem\/relapse-350198",
|
33
|
+
"image":"http:\/\/cdn-images.deezer.com\/images\/cover\/ca352d5a5537329b60df882a71b5204f\/150x150-000000-80-0-0.jpg",
|
34
|
+
"nb_tracks":"20",
|
35
|
+
"nb_disks":"1",
|
36
|
+
"year":"2009"
|
37
|
+
}
|
38
|
+
]
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|